dialysis_api_controller.go 430KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  891. redis := service.RedisClient()
  892. //清空key 值
  893. redis.Set(key, "", time.Second)
  894. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  895. redis.Set(keyOne, "", time.Second)
  896. defer redis.Close()
  897. if err == nil {
  898. c.ServeSuccessJSON(map[string]interface{}{
  899. "doubleCheck": &doubleCheck,
  900. })
  901. }
  902. } else { //修改
  903. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  904. if infor.ID > 0 {
  905. var cha_time int64
  906. timeNowStr := time.Now().Format("2006-01-02")
  907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  908. //今日的日期减去设置的日期
  909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  910. if cha_time >= recordDate.Unix() {
  911. //查询审核是否允许
  912. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  913. //申请状态不允许的情况 拒绝修改
  914. if infor.ApplicationStatus != 1 {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  916. return
  917. }
  918. }
  919. }
  920. doubleCheck.FirstCheckTime = firstCheckDate
  921. doubleCheck.CheckTime = checkDate
  922. doubleCheck.Creater = creater
  923. doubleCheck.Modifier = modifier
  924. doubleCheck.CreatedTime = check.CreatedTime
  925. doubleCheck.ID = check.ID
  926. doubleCheck.EmployeeNumber = employee_number
  927. doubleCheck.NeedleBatchNumber = needle_batch_number
  928. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  929. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  930. //查询未核对的医嘱
  931. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  932. for _, advice := range doctorList {
  933. if advice.ExecutionStaff == modifier {
  934. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  935. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  936. return
  937. }
  938. }
  939. }
  940. err := service.UpdateDoubleCheck(&doubleCheck)
  941. //针对长沙南雅
  942. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  943. //查询未核对的医嘱
  944. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  945. if len(doctorList) > 0 && modifier > 0 {
  946. for _, advice := range doctorList {
  947. service.UpdateDoctorAdviceList(advice.ID, modifier)
  948. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  949. redis := service.RedisClient()
  950. //清空key 值
  951. redis.Set(key, "", time.Second)
  952. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  953. redis.Set(keyTwo, "", time.Second)
  954. theTime := time.Now()
  955. recordDate := theTime.Format("2006-01-02")
  956. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  957. redis.Set(keyFour, "", time.Second)
  958. defer redis.Close()
  959. }
  960. }
  961. }
  962. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  963. redis := service.RedisClient()
  964. //清空key 值
  965. redis.Set(key, "", time.Second)
  966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  967. redis.Set(keyOne, "", time.Second)
  968. defer redis.Close()
  969. if err == nil {
  970. c.ServeSuccessJSON(map[string]interface{}{
  971. "doubleCheck": &doubleCheck,
  972. "msg": "1",
  973. })
  974. }
  975. }
  976. }
  977. func (c *DialysisAPIController) PostAcceptsAssessment() {
  978. id, _ := c.GetInt64("patient", 0)
  979. recordDateStr := c.GetString("record_date")
  980. way, _ := c.GetInt64("way", 0)
  981. consciousness, _ := c.GetInt64("consciousness", 0)
  982. appetite, _ := c.GetInt64("appetite", 0)
  983. condition, _ := c.GetInt64("condition", 0)
  984. posture, _ := c.GetInt64("posture")
  985. sick_condition, _ := c.GetInt64("sick_condition", 0)
  986. danger_level, _ := c.GetInt64("danger_level", 0)
  987. intake, _ := c.GetInt64("intake", 0)
  988. nutrition, _ := c.GetInt64("nutrition", 0)
  989. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  990. psychological_assessment_other := c.GetString("psychological_assessment_other")
  991. score := c.GetString("score")
  992. sick_condition_other := c.GetString("sick_condition_other")
  993. //precaution, _ := c.GetInt64("precaution", 0)
  994. precaution := c.GetString("precaution")
  995. precaution_other := c.GetString("precaution_other")
  996. psychological_other := c.GetString("psychological_other")
  997. admission_number := c.GetString("admission_number")
  998. tumble, _ := c.GetInt64("tumble")
  999. diacrisis := c.GetString("diacrisis")
  1000. his_department := c.GetString("his_department")
  1001. his_bed := c.GetString("his_bed")
  1002. if id <= 0 {
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. adminUserInfo := c.GetMobileAdminUserInfo()
  1007. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1008. if patient.ID == 0 {
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1010. return
  1011. }
  1012. //now := time.Now()
  1013. //year, month, day := now.Date()
  1014. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1015. //todayTimeStamp := today_time.Unix()
  1016. if len(recordDateStr) == 0 {
  1017. recordDateStr = time.Now().Format("2006-01-02")
  1018. }
  1019. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1020. if parseDateErr != nil {
  1021. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. // 查询信息规挡的设置天数
  1026. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1027. if infor.ID > 0 && infor.WeekDay > 0 {
  1028. var cha_time int64
  1029. timeNowStr := time.Now().Format("2006-01-02")
  1030. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1031. //今日的日期减去设置的日期
  1032. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1033. if cha_time >= recordDate.Unix() {
  1034. //查询审核是否允许
  1035. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1036. //申请状态不允许的情况 拒绝修改
  1037. if infor.ApplicationStatus != 1 {
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1039. return
  1040. }
  1041. }
  1042. }
  1043. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1044. if adminUserInfo.Org.Id == 10340 {
  1045. if condition == 1 {
  1046. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1047. if admission_number == "" {
  1048. admission_number = lastAcceptTreatment.AdmissionNumber
  1049. }
  1050. }
  1051. }
  1052. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1053. UserOrgId: adminUserInfo.Org.Id,
  1054. PatientId: id,
  1055. RecordDate: recordDate.Unix(),
  1056. Way: way,
  1057. Consciousness: consciousness,
  1058. Appetite: appetite,
  1059. Condition: condition,
  1060. SickCondition: sick_condition,
  1061. DangerLevel: danger_level,
  1062. Intake: intake,
  1063. Nutrition: nutrition,
  1064. PsychologicalAssessment: psychological_assessment,
  1065. PsychologicalAssessmentOther: psychological_assessment_other,
  1066. SickConditionOther: sick_condition_other,
  1067. Posture: posture,
  1068. CreatedTime: time.Now().Unix(),
  1069. UpdateTime: time.Now().Unix(),
  1070. Status: 1,
  1071. Score: score,
  1072. Precaution: precaution,
  1073. PrecautionOther: precaution_other,
  1074. PsychologicalOther: psychological_other,
  1075. AdmissionNumber: admission_number,
  1076. Tumble: tumble,
  1077. Diacrisis: diacrisis,
  1078. HisBed: his_bed,
  1079. HisDepartment: his_department,
  1080. }
  1081. if receiveTreatment.ID == 0 { //新增
  1082. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1083. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1084. finish := models.XtDialysisFinish{
  1085. IsFinish: 1,
  1086. UserOrgId: adminUserInfo.Org.Id,
  1087. Status: 1,
  1088. Ctime: time.Now().Unix(),
  1089. Mtime: 0,
  1090. Module: 2,
  1091. RecordDate: recordDate.Unix(),
  1092. Sourse: 1,
  1093. PatientId: id,
  1094. }
  1095. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1096. if dialysisFinish.ID == 0 {
  1097. service.CreateDialysisFinish(finish)
  1098. }
  1099. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1100. redis := service.RedisClient()
  1101. defer redis.Close()
  1102. //清空key 值
  1103. redis.Set(key, "", time.Second)
  1104. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1105. redis.Set(keyOne, "", time.Second)
  1106. if err == nil {
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "receiveTreatmentAsses": receiveTreatmentAsses,
  1109. })
  1110. }
  1111. } else { //修改
  1112. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1113. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1114. // if getPermissionErr != nil {
  1115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1116. // return
  1117. // } else if headNursePermission == nil {
  1118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1119. // return
  1120. // }
  1121. //}
  1122. // 查询信息规挡的设置天数
  1123. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1124. if infor.ID > 0 && infor.WeekDay > 0 {
  1125. var cha_time int64
  1126. timeNowStr := time.Now().Format("2006-01-02")
  1127. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1128. //今日的日期减去设置的日期
  1129. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1130. if cha_time >= recordDate.Unix() {
  1131. //查询审核是否允许
  1132. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1133. //申请状态不允许的情况 拒绝修改
  1134. if infor.ApplicationStatus != 1 {
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1136. return
  1137. }
  1138. }
  1139. }
  1140. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1141. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1142. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1143. receiveTreatmentAsses.ID = receiveTreatment.ID
  1144. if adminUserInfo.Org.Id == 10340 {
  1145. if condition == 1 {
  1146. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1147. if receiveTreatmentAsses.AdmissionNumber == "" {
  1148. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1149. }
  1150. }
  1151. }
  1152. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1153. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1154. redis := service.RedisClient()
  1155. defer redis.Close()
  1156. //清空key 值
  1157. redis.Set(key, "", time.Second)
  1158. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1159. redis.Set(keyOne, "", time.Second)
  1160. if err == nil {
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "receiveTreatmentAsses": receiveTreatmentAsses,
  1163. })
  1164. }
  1165. }
  1166. }
  1167. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1168. id, _ := c.GetInt64("patient", 0)
  1169. recordDateStr := c.GetString("record_date")
  1170. weightAfter, _ := c.GetFloat("weight_after", 0)
  1171. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1172. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1173. fmt.Println("weight_loss", weightReduce)
  1174. temperature, _ := c.GetFloat("temperature", 0)
  1175. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1176. breathing_rate := c.GetString("breathing_rate")
  1177. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1178. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1179. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1180. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1181. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1182. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1183. cruor := c.GetString("cruor")
  1184. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1185. internalFistula := c.GetString("internal_fistula")
  1186. catheter := c.GetString("catheter")
  1187. complications := c.GetString("complication")
  1188. remark := c.GetString("remark")
  1189. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1190. dialysis_intakes := c.GetString("dialysis_intakes")
  1191. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1192. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1193. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1194. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1195. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1196. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1197. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1198. patientGose, _ := c.GetInt64("patient_gose", 0)
  1199. inpatientDepartment := c.GetString("inpatient_department")
  1200. observationContent := c.GetString("observation_content")
  1201. observationContentOther := c.GetString("observation_content_other")
  1202. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1203. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1204. in_advance_reason := c.GetString("in_advance_reason")
  1205. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1206. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1207. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1208. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1209. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1210. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1211. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1212. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1213. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1214. is_eat, _ := c.GetInt64("is_eat", 0)
  1215. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1216. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1217. channels, _ := c.GetInt64("channel", 0)
  1218. return_blood, _ := c.GetInt64("return_blood", 0)
  1219. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1220. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1221. dialysis_during, _ := c.GetFloat("dialysis_during")
  1222. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1223. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1224. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1225. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1226. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1227. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1228. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1229. setting_pressure := c.GetString("setting_pressure")
  1230. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1231. diastolic_pressure := c.GetString("diastolic_pressure")
  1232. other_complication := c.GetString("other_complication")
  1233. ktv := c.GetString("ktv")
  1234. urr := c.GetString("urr")
  1235. hypertenison, _ := c.GetInt64("hypertenison")
  1236. hypopiesia, _ := c.GetInt64("hypopiesia")
  1237. leave_office_method, _ := c.GetInt64("leave_office_method")
  1238. lapse, _ := c.GetInt64("lapse")
  1239. consciousness, _ := c.GetInt64("consciousness")
  1240. fallrisk, _ := c.GetInt64("fallrisk")
  1241. machine_run := c.GetString("machine_run")
  1242. after_urea := c.GetString("after_urea")
  1243. pip_coagulation := c.GetString("pip_coagulation")
  1244. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1245. transfusion_volume := c.GetString("transfusion_volume")
  1246. last_after_weight := c.GetString("last_after_weight")
  1247. displace_liqui_value := c.GetString("displace_liqui_value")
  1248. if id <= 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. adminUserInfo := c.GetMobileAdminUserInfo()
  1253. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1254. if patient.ID == 0 {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1256. return
  1257. }
  1258. if len(recordDateStr) == 0 {
  1259. recordDateStr = time.Now().Format("2006-01-02")
  1260. }
  1261. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1262. fmt.Println("parseDateErr", parseDateErr)
  1263. if parseDateErr != nil {
  1264. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. //now := time.Now()
  1269. //year, month, day := now.Date()
  1270. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1271. //todayTimeStamp := today_time.Unix()
  1272. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1273. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1274. UserOrgId: adminUserInfo.Org.Id,
  1275. PatientId: id,
  1276. AssessmentDate: recordDate.Unix(),
  1277. Temperature: temperature,
  1278. PulseFrequency: pulse_frequency,
  1279. BreathingRate: breathing_rate,
  1280. SystolicBloodPressure: systolic_blood_pressure,
  1281. DiastolicBloodPressure: diastolic_blood_pressure,
  1282. ActualUltrafiltration: actual_ultrafiltration,
  1283. ActualDisplacement: actual_displacement,
  1284. ActualTreatmentHour: actualtreatHour,
  1285. ActualTreatmentMinute: actualtreatmin,
  1286. WeightAfter: weightAfter,
  1287. AdditionalWeight: additionalWeight,
  1288. WeightLoss: weightReduce,
  1289. Cruor: cruor,
  1290. SymptomAfterDialysis: symptomsAfterDialysi,
  1291. InternalFistula: internalFistula,
  1292. Catheter: catheter,
  1293. Complication: complications,
  1294. DialysisIntakes: dialysateVolume,
  1295. CreatedTime: time.Now().Unix(),
  1296. UpdatedTime: time.Now().Unix(),
  1297. Status: 1,
  1298. Remark: remark,
  1299. BloodAccessPartId: blood_access_part_id,
  1300. BloodAccessPartOperaId: blood_access_part_opera_id,
  1301. DialysisIntakesUnit: dialysis_intakes_unit,
  1302. PuncturePointOozingBlood: puncturePointOozingBlood,
  1303. PuncturePointHaematoma: puncturePointHaematoma,
  1304. InternalFistulaTremorAc: internalFistulaTremorAc,
  1305. PatientGose: patientGose,
  1306. InpatientDepartment: inpatientDepartment,
  1307. ObservationContent: observationContent,
  1308. ObservationContentOther: observationContentOther,
  1309. DialysisProcess: dialysis_process,
  1310. InAdvanceMinute: in_advance_minute,
  1311. InAdvanceReason: in_advance_reason,
  1312. HemostasisMinute: hemostasis_minute,
  1313. HemostasisOpera: hemostasis_opera,
  1314. TremorNoise: tremor_noise,
  1315. DisequilibriumSyndrome: disequilibrium_syndrome,
  1316. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1317. ArterialTube: arterial_tube,
  1318. IntravenousTube: intravenous_tube,
  1319. Dialyzer: dialyzer,
  1320. InAdvanceReasonOther: in_advance_reason_other,
  1321. IsEat: is_eat,
  1322. CvcA: cvc_a,
  1323. CvcV: cvc_v,
  1324. Channel: channels,
  1325. ReturnBlood: return_blood,
  1326. RehydrationVolume: rehydration_volume,
  1327. DialysisDuring: dialysis_during,
  1328. StrokeVolume: stroke_volume,
  1329. BloodFlow: blood_flow,
  1330. SealingFluidDispose: sealing_fluid_dispose,
  1331. SealingFluidSpecial: sealing_fluid_special,
  1332. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1333. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1334. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1335. SettingPressure: setting_pressure,
  1336. DiastolicPressure: diastolic_pressure,
  1337. OtherComplication: other_complication,
  1338. Ktv: ktv,
  1339. Urr: urr,
  1340. Hypopiesia: hypopiesia,
  1341. Hypertenison: hypertenison,
  1342. Lapse: lapse,
  1343. LeaveOfficeMethod: leave_office_method,
  1344. Consciousness: consciousness,
  1345. Fallrisk: fallrisk,
  1346. MachineRun: machine_run,
  1347. AfterUrea: after_urea,
  1348. PipCoagulation: pip_coagulation,
  1349. AccumulatedBloodVolume: accumulated_blood_volume,
  1350. TransfusionVolume: transfusion_volume,
  1351. LastAfterWeight: last_after_weight,
  1352. DisplaceLiquiValue: displace_liqui_value,
  1353. }
  1354. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1355. // 查询信息规挡的设置天数
  1356. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1357. if infor.ID > 0 && infor.WeekDay > 0 {
  1358. var cha_time int64
  1359. timeNowStr := time.Now().Format("2006-01-02")
  1360. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1361. //今日的日期减去设置的日期
  1362. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1363. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1364. if cha_time >= recordDate.Unix() {
  1365. //查询审核是否允许
  1366. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1367. //申请状态不允许的情况 拒绝修改
  1368. if infor.ApplicationStatus != 1 {
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1370. return
  1371. }
  1372. }
  1373. }
  1374. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1375. if assessmentAfter.ID == 0 { //新增
  1376. if appRole.UserType == 2 || appRole.UserType == 1 {
  1377. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1378. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1379. } else {
  1380. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1381. }
  1382. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1383. if assessmentAfterDislysis.UserOrgId != 10340 {
  1384. if assessmentAfterDislysis.WeightAfter == 0 {
  1385. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1386. }
  1387. }
  1388. if adminUserInfo.Org.Id == 10693 {
  1389. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1390. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1391. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1392. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1393. }
  1394. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1395. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1396. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1397. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1398. }
  1399. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1400. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1401. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1402. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1403. }
  1404. if assessmentAfterDislysis.PulseFrequency == 0 {
  1405. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1406. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1407. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1408. }
  1409. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1410. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1411. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1412. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1413. }
  1414. }
  1415. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1416. //记录日志
  1417. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1418. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1419. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1420. PatientId: assessmentAfterDislysis.PatientId,
  1421. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1422. Status: 1,
  1423. ErrLog: string(byterequest),
  1424. AdminUserId: adminUserInfo.AdminUser.Id,
  1425. Ctime: 0,
  1426. Mtime: 0,
  1427. Source: "手机端保存透后评估",
  1428. }
  1429. service.CreateAfterDialysisLog(afterDialysisLog)
  1430. finish := models.XtDialysisFinish{
  1431. IsFinish: 1,
  1432. UserOrgId: adminUserInfo.Org.Id,
  1433. Status: 1,
  1434. Ctime: time.Now().Unix(),
  1435. Mtime: 0,
  1436. Module: 9,
  1437. RecordDate: recordDate.Unix(),
  1438. Sourse: 1,
  1439. PatientId: id,
  1440. }
  1441. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1442. if dialysisFinish.ID == 0 {
  1443. service.CreateDialysisFinish(finish)
  1444. }
  1445. redis := service.RedisClient()
  1446. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1447. redis.Set(keyTwo, "", time.Second)
  1448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1449. //清空key 值
  1450. redis.Set(key, "", time.Second)
  1451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1452. redis.Set(keyOne, "", time.Second)
  1453. defer redis.Close()
  1454. if err == nil {
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "assessmentAfterDislysis": assessmentAfterDislysis,
  1457. })
  1458. }
  1459. return
  1460. } else { //修改
  1461. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1462. if infor.ID > 0 && infor.WeekDay > 0 {
  1463. var cha_time int64
  1464. timeNowStr := time.Now().Format("2006-01-02")
  1465. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1466. //今日的日期减去设置的日期
  1467. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1468. if cha_time >= recordDate.Unix() {
  1469. //查询审核是否允许
  1470. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1471. //申请状态不允许的情况 拒绝修改
  1472. if infor.ApplicationStatus != 1 {
  1473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1474. return
  1475. }
  1476. }
  1477. }
  1478. if appRole.UserType == 2 || appRole.UserType == 1 {
  1479. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1480. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1481. } else {
  1482. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1483. if assessmentAfterDislysis.Creater == 0 {
  1484. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1485. }
  1486. }
  1487. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1488. assessmentAfterDislysis.ID = assessmentAfter.ID
  1489. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1490. if assessmentAfterDislysis.UserOrgId != 10340 {
  1491. if assessmentAfterDislysis.WeightAfter == 0 {
  1492. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1493. }
  1494. }
  1495. if adminUserInfo.Org.Id == 10693 {
  1496. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1497. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1498. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1499. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1500. }
  1501. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1502. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1503. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1504. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1505. }
  1506. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1507. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1508. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1509. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1510. }
  1511. if assessmentAfterDislysis.PulseFrequency == 0 {
  1512. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1513. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1514. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1515. }
  1516. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1517. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1518. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1519. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1520. }
  1521. }
  1522. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1523. //记录日志
  1524. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1525. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1526. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1527. PatientId: assessmentAfterDislysis.PatientId,
  1528. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1529. Status: 1,
  1530. ErrLog: string(byterequest),
  1531. AdminUserId: adminUserInfo.AdminUser.Id,
  1532. Ctime: time.Now().Unix(),
  1533. Mtime: 0,
  1534. Source: "手机端修改保存透后评估",
  1535. }
  1536. service.CreateAfterDialysisLog(afterDialysisLog)
  1537. redis := service.RedisClient()
  1538. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1539. redis.Set(keyTwo, "", time.Second)
  1540. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1541. //清空key 值
  1542. redis.Set(key, "", time.Second)
  1543. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1544. redis.Set(keyOne, "", time.Second)
  1545. if err == nil {
  1546. c.ServeSuccessJSON(map[string]interface{}{
  1547. "assessmentAfterDislysis": assessmentAfterDislysis,
  1548. })
  1549. return
  1550. }
  1551. }
  1552. return
  1553. }
  1554. func (c *DialysisAPIController) PostDialysisPrescription() {
  1555. id, _ := c.GetInt64("patient", 0)
  1556. recordDateStr := c.GetString("record_date")
  1557. if id <= 0 {
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1559. return
  1560. }
  1561. adminUserInfo := c.GetMobileAdminUserInfo()
  1562. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1563. if patient.ID == 0 {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1565. return
  1566. }
  1567. if len(recordDateStr) == 0 {
  1568. recordDateStr = time.Now().Format("2006-01-02")
  1569. }
  1570. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1571. if parseDateErr != nil {
  1572. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. mode_id, _ := c.GetInt64("mode_id", 0)
  1577. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1578. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1579. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1580. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1581. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1582. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1583. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1584. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1585. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1586. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1587. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1588. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1589. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1590. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1591. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1592. kalium, _ := c.GetFloat("kalium", 0)
  1593. sodium, _ := c.GetFloat("sodium", 0)
  1594. calcium, _ := c.GetFloat("calcium", 0)
  1595. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1596. glucose, _ := c.GetFloat("glucose", 0)
  1597. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1598. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1599. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1600. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1601. conductivity, _ := c.GetFloat("conductivity", 0)
  1602. remark := c.GetString("remark")
  1603. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1604. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1605. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1606. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1607. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1608. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1609. special_medicine_other := c.GetString("special_medicine_other")
  1610. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1611. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1612. blood_access, _ := c.GetInt64("blood_access", 0)
  1613. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1614. body_fluid_other := c.GetString("body_fluid_other")
  1615. niprocart, _ := c.GetInt64("niprocart", 0)
  1616. jms, _ := c.GetInt64("jms", 0)
  1617. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1618. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1619. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1620. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1621. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1622. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1623. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1624. injector, _ := c.GetInt64("injector", 0)
  1625. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1626. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1627. safe_package, _ := c.GetInt64("package", 0)
  1628. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1629. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1630. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1631. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1632. blood := c.GetString("blood")
  1633. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1634. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1635. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1636. displace_speed := c.GetString("displace_speed")
  1637. illness, _ := c.GetInt64("illness")
  1638. amylaceum := c.GetString("amylaceum")
  1639. single_time := c.GetString("single_time")
  1640. single_water := c.GetString("single_water")
  1641. replacement_flow := c.GetString("replacement_flow")
  1642. plasma_separator := c.GetString("plasma_separator")
  1643. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1644. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1645. oxygen_flow := c.GetString("oxygen_flow")
  1646. oxygen_time := c.GetString("oxygen_time")
  1647. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1648. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1649. puncture_needle := c.GetString("puncture_needle")
  1650. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1651. epo := c.GetString("epo")
  1652. epo_count, _ := c.GetFloat("epo_count", 0)
  1653. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1654. admin_user_id, _ := c.GetInt64("admin_user_id")
  1655. is_water := c.GetString("is_water")
  1656. var is_war int64
  1657. if is_water == "是" {
  1658. is_war = 1
  1659. }
  1660. if is_water == "否" {
  1661. is_war = 2
  1662. }
  1663. if is_water == "请选择" {
  1664. is_war = 0
  1665. }
  1666. drhy_water := c.GetString("drhy_water")
  1667. dry_water_hour := c.GetString("dry_water_hour")
  1668. water_machine := c.GetString("water_machine")
  1669. add_amount, _ := c.GetFloat("add_amount")
  1670. reduce_amount, _ := c.GetFloat("reduce_amount")
  1671. dialysis_remark := c.GetString("dialysis_remark")
  1672. prescribing_number, _ := c.GetFloat("prescribing_number")
  1673. prescription_sodium := c.GetString("prescription_sodium")
  1674. start_sodium := c.GetString("start_sodium")
  1675. sodium_curve := c.GetString("sodium_curve")
  1676. treatment_remark := c.GetString("treatment_remark")
  1677. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1678. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1679. prescription_water, _ := c.GetFloat("prescription_water")
  1680. dialysis_strainer := c.GetString("dialysis_strainer")
  1681. chaptalization := c.GetString("chaptalization")
  1682. washing_time := c.GetString("washing_time")
  1683. warsh_count := c.GetString("warsh_count")
  1684. blood_access_part_id := c.GetString("blood_access_part_id")
  1685. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1686. dialyzate := c.GetString("dialyzate")
  1687. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1688. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1689. //
  1690. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1691. // if appRole.UserType == 3 {
  1692. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1693. // if getPermissionErr != nil {
  1694. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1695. // return
  1696. // } else if headNursePermission == nil {
  1697. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1698. // return
  1699. // }
  1700. // }
  1701. //}
  1702. // 查询信息规挡的设置天数
  1703. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1704. if infor.ID > 0 && infor.WeekDay > 0 {
  1705. var cha_time int64
  1706. timeNowStr := time.Now().Format("2006-01-02")
  1707. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1708. //今日的日期减去设置的日期
  1709. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1710. if cha_time >= recordDate.Unix() {
  1711. //查询审核是否允许
  1712. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1713. //申请状态不允许的情况 拒绝修改
  1714. if infor.ApplicationStatus != 1 {
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1716. return
  1717. }
  1718. }
  1719. }
  1720. if mode_id > 0 {
  1721. var str string
  1722. //查找该机构用的是什么透析器
  1723. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1724. if filedConfig.ID > 0 {
  1725. str = dialyzerPerfusionApparatus
  1726. } else {
  1727. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1728. }
  1729. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1730. }
  1731. //TODO 需要根据角色去判断
  1732. prescription := models.DialysisPrescription{
  1733. UserOrgId: adminUserInfo.Org.Id,
  1734. PatientId: id,
  1735. RecordDate: recordDate.Unix(),
  1736. ModeId: mode_id,
  1737. DialysisDuration: dialysis_duration,
  1738. Dialyzer: dialyzer,
  1739. PerfusionApparatus: perfusion_apparatus,
  1740. BloodFlowVolume: blood_flow_volume,
  1741. DewaterAmount: dewater_amount,
  1742. DisplaceLiqui: displace_liqui,
  1743. ReplacementWay: replacement_way,
  1744. Anticoagulant: anticoagulant,
  1745. AnticoagulantShouji: anticoagulant_shouji,
  1746. AnticoagulantWeichi: anticoagulant_weichi,
  1747. AnticoagulantZongliang: anticoagulant_zongliang,
  1748. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1749. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1750. Kalium: kalium,
  1751. Sodium: sodium,
  1752. Calcium: calcium,
  1753. Bicarbonate: bicarbonate,
  1754. Glucose: glucose,
  1755. // DryWeight: dry_weight,
  1756. DialysateFlow: dialysate_flow,
  1757. DialysateTemperature: dialysate_temperature,
  1758. // PrescriptionDoctor: prescription_doctor,
  1759. ReplacementTotal: replacement_total,
  1760. Conductivity: conductivity,
  1761. Remark: remark,
  1762. Status: 1,
  1763. CreatedTime: time.Now().Unix(),
  1764. UpdatedTime: time.Now().Unix(),
  1765. DialysisDurationMinute: dialysisDurationMinute,
  1766. DialysisDurationHour: dialysisDurationHour,
  1767. TargetUltrafiltration: targetUltrafiltration,
  1768. DialysateFormulation: dialysateFormulation,
  1769. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1770. BodyFluid: body_fluid,
  1771. SpecialMedicine: special_medicine,
  1772. SpecialMedicineOther: special_medicine_other,
  1773. DisplaceLiquiPart: displace_liqui_part,
  1774. DisplaceLiquiValue: displace_liqui_value,
  1775. BloodAccess: blood_access,
  1776. Ultrafiltration: ultrafiltration,
  1777. BodyFluidOther: body_fluid_other,
  1778. Niprocart: niprocart,
  1779. Jms: jms,
  1780. FistulaNeedleSet: fistula_needle_set,
  1781. FistulaNeedleSet16: fistula_needle_set_16,
  1782. Hemoperfusion: hemoperfusion,
  1783. DialyserSterilised: dialyser_sterilised,
  1784. Filtryzer: filtryzer,
  1785. Dialyzers: dialyzers,
  1786. Injector: injector,
  1787. Bloodlines: bloodlines,
  1788. TubingHemodialysis: tubing_hemodialysis,
  1789. Package: safe_package,
  1790. ALiquid: a_liquid,
  1791. TargetKtv: target_ktv,
  1792. PreImpulse: pre_impulse,
  1793. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1794. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1795. Blood: blood,
  1796. DialysisDialyszers: dialysis_dialyszers,
  1797. DialysisIrrigation: dialysis_irrigation,
  1798. AntioxidantCommodityName: antioxidant_commodity_name,
  1799. DisplaceSpeed: displace_speed,
  1800. Illness: illness,
  1801. Amylaceum: amylaceum,
  1802. SingleTime: single_time,
  1803. SingleWater: single_water,
  1804. ReplacementFlow: replacement_flow,
  1805. PlasmaSeparator: plasma_separator,
  1806. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1807. OxygenUptake: oxygen_uptake,
  1808. OxygenFlow: oxygen_flow,
  1809. OxygenTime: oxygen_time,
  1810. HemodialysisPipelines: hemodialysis_pipelines,
  1811. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1812. PunctureNeedle: puncture_needle,
  1813. PunctureNeedleCount: puncture_needle_count,
  1814. Epo: epo,
  1815. EpoCount: epo_count,
  1816. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1817. AdminUserId: admin_user_id,
  1818. IsWater: is_war,
  1819. DrhyWater: drhy_water,
  1820. DryWaterHour: dry_water_hour,
  1821. WaterMachine: water_machine,
  1822. AddAmount: add_amount,
  1823. ReduceAmount: reduce_amount,
  1824. DialysisRemark: dialysis_remark,
  1825. PrescribingNumber: prescribing_number,
  1826. StartSodium: start_sodium,
  1827. SodiumCurve: sodium_curve,
  1828. TreatmentRemark: treatment_remark,
  1829. PrescriptionSodium: prescription_sodium,
  1830. DialysisFluidFlow: dialysis_fluid_flow,
  1831. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1832. PrescriptionWater: prescription_water,
  1833. DialysisStrainer: dialysis_strainer,
  1834. Chaptalization: chaptalization,
  1835. WashingTime: washing_time,
  1836. WarshCount: warsh_count,
  1837. BloodAccessPartId: blood_access_part_id,
  1838. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1839. Dialyzate: dialyzate,
  1840. }
  1841. //查询最近透析准备表里是否存在 透析器 灌流器
  1842. //
  1843. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1844. //
  1845. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1846. //
  1847. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1848. //if len(mation)>0{
  1849. // for _, item := range splitStr {
  1850. // for _,it := range mation{
  1851. // if(item == it.SpecificationName){
  1852. //
  1853. // //查询最近一次的透析器
  1854. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1855. //
  1856. // if errcode == gorm.ErrRecordNotFound{
  1857. // //插入数据
  1858. // prepare := models.DialysisBeforePrepare{
  1859. // UserOrgId: adminUserInfo.Org.Id,
  1860. // PatientId: id,
  1861. // RecordDate: recordDate.Unix(),
  1862. // GoodTypeId: it.GoodTypeId,
  1863. // GoodId: it.ID,
  1864. // Count: 1,
  1865. // Ctime: time.Now().Unix(),
  1866. // Creater: adminUserInfo.AdminUser.Id,
  1867. // Status:1,
  1868. //
  1869. // }
  1870. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1871. // fmt.Println("",errcode)
  1872. // }
  1873. // }
  1874. // }
  1875. //
  1876. // }
  1877. //
  1878. // for _, item := range splitIrrigation {
  1879. // for _,it := range mation{
  1880. // if(item == it.SpecificationName){
  1881. // //查询最近一次的透析器
  1882. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1883. // if errcode == gorm.ErrRecordNotFound{
  1884. // //插入数据
  1885. // prepare := models.DialysisBeforePrepare{
  1886. // UserOrgId: adminUserInfo.Org.Id,
  1887. // PatientId: id,
  1888. // RecordDate: recordDate.Unix(),
  1889. // GoodTypeId: it.GoodTypeId,
  1890. // GoodId: it.ID,
  1891. // Count: 1,
  1892. // Ctime: time.Now().Unix(),
  1893. // Creater: adminUserInfo.AdminUser.Id,
  1894. // Status:1,
  1895. //
  1896. // }
  1897. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1898. // fmt.Println(errcode)
  1899. // }
  1900. // }
  1901. // }
  1902. // }
  1903. //}
  1904. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1905. if dialysisPrescription.ID == 0 { //新增
  1906. if appRole.UserType == 2 || appRole.UserType == 1 {
  1907. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1908. }
  1909. prescription.Creater = adminUserInfo.AdminUser.Id
  1910. //针对河间咸得
  1911. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1912. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1913. prescription.DisplaceLiquiPart = 0
  1914. prescription.DisplaceLiquiValue = 0
  1915. }
  1916. }
  1917. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1918. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1919. }
  1920. err := service.AddSigleRecord(&prescription)
  1921. //记录日志
  1922. byterequest, _ := json.Marshal(prescription)
  1923. prescriptionLog := models.XtDialysisPrescriptionLog{
  1924. UserOrgId: prescription.UserOrgId,
  1925. Ctime: time.Now().Unix(),
  1926. Mtime: 0,
  1927. ErrLog: string(byterequest),
  1928. AdminUserId: adminUserInfo.AdminUser.Id,
  1929. RecordDate: prescription.RecordDate,
  1930. PatientId: prescription.PatientId,
  1931. Source: "手机端新增保存处方",
  1932. Status: 1,
  1933. }
  1934. service.CreatePrescriptionLog(prescriptionLog)
  1935. finish := models.XtDialysisFinish{
  1936. IsFinish: 1,
  1937. UserOrgId: adminUserInfo.Org.Id,
  1938. Status: 1,
  1939. Ctime: time.Now().Unix(),
  1940. Mtime: 0,
  1941. Module: 1,
  1942. RecordDate: recordDate.Unix(),
  1943. Sourse: 1,
  1944. PatientId: id,
  1945. }
  1946. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1947. if dialysisFinish.ID == 0 {
  1948. service.CreateDialysisFinish(finish)
  1949. }
  1950. //长沙南雅医院,自动生成抗凝剂的临时处方
  1951. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1952. if prescribing_number == 0 {
  1953. prescribing_number = 1
  1954. }
  1955. if prescribing_number == 0 && id == 14682 {
  1956. prescribing_number = 2
  1957. }
  1958. if prescribing_number == 0 && id == 18560 {
  1959. prescribing_number = 2
  1960. }
  1961. advice := models.DoctorAdvice{
  1962. UserOrgId: adminUserInfo.Org.Id,
  1963. PatientId: id,
  1964. GroupNo: 0,
  1965. AdviceType: 2,
  1966. RecordDate: recordDate.Unix(),
  1967. AdviceDate: recordDate.Unix(),
  1968. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1969. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1970. AdviceDesc: "",
  1971. ReminderDate: 0,
  1972. SingleDose: anticoagulant_zongliang,
  1973. SingleDoseUnit: "iu",
  1974. DrugSpec: 0,
  1975. DrugSpecUnit: "",
  1976. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1977. PrescribingNumberUnit: "支",
  1978. DeliveryWay: "静脉注射",
  1979. ExecutionFrequency: "上机前",
  1980. AdviceDoctor: 0,
  1981. Status: 1,
  1982. CreatedTime: time.Now().Unix(),
  1983. UpdatedTime: time.Now().Unix(),
  1984. IsPrescription: 1,
  1985. ExecutionState: 2,
  1986. StopState: 2,
  1987. IsSettle: 2,
  1988. }
  1989. // 查询排班信息
  1990. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1991. if schedulePatient.ID > 0 {
  1992. if schedulePatient.ScheduleType == 1 {
  1993. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1994. }
  1995. if schedulePatient.ScheduleType == 2 {
  1996. advice.StartTime = recordDate.Unix() + 9*60*60
  1997. }
  1998. }
  1999. // 抗凝剂名称
  2000. switch anticoagulant {
  2001. case 1:
  2002. advice.AdviceName = "无肝素"
  2003. break
  2004. case 2:
  2005. advice.AdviceName = "普通肝素"
  2006. break
  2007. case 3:
  2008. advice.AdviceName = "低分子肝素"
  2009. break
  2010. case 4:
  2011. advice.AdviceName = "阿加曲班"
  2012. break
  2013. case 5:
  2014. advice.AdviceName = "枸橼酸钠"
  2015. break
  2016. case 6:
  2017. advice.AdviceName = "低分子肝素钙"
  2018. break
  2019. case 7:
  2020. advice.AdviceName = "低分子肝素钠"
  2021. break
  2022. case 8:
  2023. advice.AdviceName = "依诺肝素"
  2024. break
  2025. case 9:
  2026. advice.AdviceName = "达肝素"
  2027. break
  2028. case 10:
  2029. advice.AdviceName = "体外抗凝"
  2030. break
  2031. case 11:
  2032. advice.AdviceName = "那曲肝素"
  2033. break
  2034. case 12:
  2035. advice.AdviceName = "无抗凝剂"
  2036. break
  2037. }
  2038. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2039. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2040. advice.AdviceDoctor = appRole.AdminUserId
  2041. }
  2042. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2043. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2044. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2045. advice.AdviceName = "低分子肝素钠注射液"
  2046. // 修改患者临时医嘱里的抗凝剂医嘱
  2047. advice.ID = advicePrescription.ID
  2048. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2049. } else {
  2050. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2051. advice.AdviceName = "低分子肝素钠注射液"
  2052. // 新增患者临时医嘱里的抗凝剂医嘱
  2053. service.CreateDoctorAdvice(&advice)
  2054. }
  2055. }
  2056. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2057. redis := service.RedisClient()
  2058. defer redis.Close()
  2059. //清空key 值
  2060. redis.Set(key, "", time.Second)
  2061. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2062. redis.Set(keyOne, "", time.Second)
  2063. }
  2064. //获取key,清空redis
  2065. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2066. redis := service.RedisClient()
  2067. //清空key 值
  2068. redis.Set(key, "", time.Second)
  2069. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2070. //清空key 值
  2071. redis.Set(keyOne, "", time.Second)
  2072. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2073. //清空key 值
  2074. redis.Set(keyTwo, "", time.Second)
  2075. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2076. redis.Set(keySix, "", time.Second)
  2077. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2078. redis.Set(keySeven, "", time.Second)
  2079. if err == nil {
  2080. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2081. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2082. //清空key 值
  2083. redis.Set(keyThree, "", time.Second)
  2084. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2085. //清空key 值
  2086. redis.Set(keyFour, "", time.Second)
  2087. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2088. redis.Set(keyFive, "", time.Second)
  2089. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2090. redis.Set(keySix, "", time.Second)
  2091. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2092. redis.Set(keySeven, "", time.Second)
  2093. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2094. //清空key 值
  2095. redis.Set(keyOne, "", time.Second)
  2096. if updateErr != nil {
  2097. utils.ErrorLog("%v", updateErr)
  2098. }
  2099. defer redis.Close()
  2100. c.ServeSuccessJSON(map[string]interface{}{
  2101. "prescription": prescription,
  2102. })
  2103. }
  2104. } else { //修改
  2105. //if mode_id > 0 {
  2106. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2107. //}
  2108. //if template.TemplateId == 1 {
  2109. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2111. // if getPermissionErr != nil {
  2112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2113. // return
  2114. // } else if headNursePermission == nil {
  2115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2116. // return
  2117. // }
  2118. // }
  2119. //}
  2120. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2121. prescription.Modifier = adminUserInfo.AdminUser.Id
  2122. if appRole.UserType == 2 || appRole.UserType == 1 {
  2123. prescription_doctor := adminUserInfo.AdminUser.Id
  2124. prescription.PrescriptionDoctor = prescription_doctor
  2125. } else {
  2126. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2127. }
  2128. if dialysisPrescription.Creater == 0 { //体重称
  2129. prescription.Creater = adminUserInfo.AdminUser.Id
  2130. } else {
  2131. prescription.Creater = dialysisPrescription.Creater
  2132. if adminUserInfo.Org.Id == 9882 {
  2133. if appRole.UserType == 2 || appRole.UserType == 1 {
  2134. prescription_doctor := adminUserInfo.AdminUser.Id
  2135. prescription.PrescriptionDoctor = prescription_doctor
  2136. prescription.Creater = prescription_doctor
  2137. }
  2138. }
  2139. }
  2140. prescription.ID = dialysisPrescription.ID
  2141. service.UpDateDialysisPrescription(&prescription)
  2142. //记录日志
  2143. byterequest, _ := json.Marshal(prescription)
  2144. prescriptionLog := models.XtDialysisPrescriptionLog{
  2145. UserOrgId: prescription.UserOrgId,
  2146. Ctime: time.Now().Unix(),
  2147. Mtime: 0,
  2148. ErrLog: string(byterequest),
  2149. AdminUserId: adminUserInfo.AdminUser.Id,
  2150. RecordDate: prescription.RecordDate,
  2151. PatientId: prescription.PatientId,
  2152. Source: "手机端修改处方",
  2153. Status: 1,
  2154. }
  2155. service.CreatePrescriptionLog(prescriptionLog)
  2156. finish := models.XtDialysisFinish{
  2157. IsFinish: 1,
  2158. UserOrgId: adminUserInfo.Org.Id,
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Module: 1,
  2163. RecordDate: recordDate.Unix(),
  2164. Sourse: 1,
  2165. PatientId: id,
  2166. }
  2167. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2168. if dialysisFinish.ID == 0 {
  2169. service.CreateDialysisFinish(finish)
  2170. }
  2171. //修改处方
  2172. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2173. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2174. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. if advicePrescription.ID > 0 {
  2176. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2177. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2178. redis := service.RedisClient()
  2179. defer redis.Close()
  2180. //清空key 值
  2181. redis.Set(key, "", time.Second)
  2182. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2183. redis.Set(keyOne, "", time.Second)
  2184. }
  2185. }
  2186. //获取key,清空redis
  2187. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2188. redis := service.RedisClient()
  2189. //清空key 值
  2190. redis.Set(key, "", time.Second)
  2191. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2192. //清空key 值
  2193. redis.Set(keyOne, "", time.Second)
  2194. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2195. redis.Set(keySix, "", time.Second)
  2196. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2197. redis.Set(keySeven, "", time.Second)
  2198. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2199. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2200. //清空key 值
  2201. redis.Set(keyTwoOne, "", time.Second)
  2202. defer redis.Close()
  2203. if updateErr != nil {
  2204. utils.ErrorLog("%v", updateErr)
  2205. }
  2206. c.ServeSuccessJSON(map[string]interface{}{
  2207. "prescription": prescription,
  2208. })
  2209. }
  2210. }
  2211. func (c *DialysisAPIController) Finish() {
  2212. id, _ := c.GetInt64("patient", 0)
  2213. recordDateStr := c.GetString("record_date")
  2214. nurseID, _ := c.GetInt64("nurse")
  2215. end_time := c.GetString("end_time")
  2216. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2217. internal_fistula := c.GetString("blood_access_internal_fistula")
  2218. catheter := c.GetString("catheter")
  2219. cruor := c.GetString("cruor")
  2220. mission := c.GetString("mission")
  2221. condenser := c.GetString("condenser")
  2222. if id <= 0 || nurseID <= 0 {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. adminUserInfo := c.GetMobileAdminUserInfo()
  2227. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2228. if patient.ID == 0 {
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2230. return
  2231. }
  2232. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2233. if getNurseErr != nil {
  2234. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2236. return
  2237. } else if nurse == nil {
  2238. c.ErrorLog("护士不存在")
  2239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2240. return
  2241. }
  2242. if len(recordDateStr) == 0 {
  2243. recordDateStr = time.Now().Format("2006-01-02")
  2244. }
  2245. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2246. if parseDateErr != nil {
  2247. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2249. return
  2250. }
  2251. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2252. if parseEndDateErr != nil {
  2253. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2255. return
  2256. }
  2257. // 查询信息规挡的设置天数
  2258. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2259. if infor.ID > 0 && infor.WeekDay > 0 {
  2260. var cha_time int64
  2261. timeNowStr := time.Now().Format("2006-01-02")
  2262. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2263. //今日的日期减去设置的日期
  2264. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2265. if cha_time >= recordDate.Unix() {
  2266. //查询审核是否允许
  2267. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2268. //申请状态不允许的情况 拒绝修改
  2269. if infor.ApplicationStatus != 1 {
  2270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2271. return
  2272. }
  2273. }
  2274. }
  2275. //now := time.Now()
  2276. //year, month, day := now.Date()
  2277. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2278. //todayTimeStamp := today_time.Unix()
  2279. // 获取当天的第一条透析纪录
  2280. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2281. if getMonitorRecordsErr != nil {
  2282. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. return
  2285. }
  2286. // 获取当前的最后一条透析纪录
  2287. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2288. if getMonitorRecordsErr != nil {
  2289. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2291. return
  2292. }
  2293. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2294. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2295. if getAADErr != nil {
  2296. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2298. return
  2299. }
  2300. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2301. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2304. if assessmentAfterDislysis != nil {
  2305. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2306. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2307. } else {
  2308. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2309. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2310. tempassessmentAfterDislysis.Status = 1
  2311. tempassessmentAfterDislysis.PatientId = id
  2312. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2313. }
  2314. //长沙南雅
  2315. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2316. //获取最后一条透析处方数据
  2317. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2318. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2320. }
  2321. if dialysisOrder.Stage == 1 {
  2322. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2323. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2324. fmt.Println(value)
  2325. a, b := math.Modf(value)
  2326. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2327. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2328. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2329. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2330. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2331. }
  2332. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2333. //var num1 int64
  2334. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2335. //fmt.Println(num1)
  2336. //sub := float64(num1 / 3600)
  2337. //fmt.Println(sub)
  2338. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2339. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2340. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2341. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2342. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2343. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2344. if adminUserInfo.Org.Id != 10375 {
  2345. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2346. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2347. }
  2348. if adminUserInfo.Org.Id != 10445 {
  2349. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2350. }
  2351. //北方营口医院
  2352. if adminUserInfo.Org.Id == 10445 {
  2353. //获取最后一条透析处方数据
  2354. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2355. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2356. } else {
  2357. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2358. }
  2359. //新化博翔
  2360. if adminUserInfo.Org.Id == 10447 {
  2361. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2362. }
  2363. //阳春
  2364. if adminUserInfo.Org.Id == 10485 {
  2365. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2366. }
  2367. if adminUserInfo.Org.Id == 10551 {
  2368. //获取最后一条透析处方数据
  2369. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2370. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2371. }
  2372. if adminUserInfo.Org.Id == 10580 {
  2373. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2374. }
  2375. if adminUserInfo.Org.Id == 10612 {
  2376. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2377. }
  2378. //孝康
  2379. if adminUserInfo.Org.Id == 10693 {
  2380. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2381. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2382. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2383. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2384. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2385. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2386. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2387. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2388. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2389. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2390. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2391. }
  2392. if adminUserInfo.Org.Id == 10721 {
  2393. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2394. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2395. }
  2396. if adminUserInfo.Org.Id == 10697 {
  2397. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2398. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2399. lastWeightAfter.LastAfterWeight = floatAfeter
  2400. }
  2401. }
  2402. 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 {
  2403. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2404. if evaluation.SystolicBloodPressure == 0 {
  2405. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2406. if adminUserInfo.Org.Id == 10693 {
  2407. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2408. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2409. }
  2410. pre := models.PredialysisEvaluation{
  2411. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2412. }
  2413. fmt.Println("prew", pre)
  2414. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2415. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2417. redis := service.RedisClient()
  2418. redis.Set(key, "", time.Second)
  2419. redis.Set(keyOne, "", time.Second)
  2420. defer redis.Close()
  2421. fmt.Println(getNurseErr)
  2422. }
  2423. if evaluation.DiastolicBloodPressure == 0 {
  2424. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2425. if adminUserInfo.Org.Id == 10693 {
  2426. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2427. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2428. }
  2429. pres := models.PredialysisEvaluation{
  2430. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2431. }
  2432. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2433. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2434. redis := service.RedisClient()
  2435. redis.Set(key, "", time.Second)
  2436. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2437. redis.Set(keyOne, "", time.Second)
  2438. defer redis.Close()
  2439. fmt.Println(getNurseErr)
  2440. }
  2441. if evaluation.PulseFrequency == 0 {
  2442. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2443. if adminUserInfo.Org.Id == 10693 {
  2444. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2445. evaluation.PulseFrequency = pulseFrequency
  2446. }
  2447. press := models.PredialysisEvaluation{
  2448. PulseFrequency: evaluation.PulseFrequency,
  2449. }
  2450. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2451. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2452. redis := service.RedisClient()
  2453. redis.Set(key, "", time.Second)
  2454. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2455. redis.Set(keyOne, "", time.Second)
  2456. defer redis.Close()
  2457. fmt.Println(getNurseErr)
  2458. }
  2459. if evaluation.Temperature == 0 {
  2460. evaluation.Temperature = fmonitorRecords.Temperature
  2461. press := models.PredialysisEvaluation{
  2462. Temperature: evaluation.Temperature,
  2463. }
  2464. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2465. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2466. redis := service.RedisClient()
  2467. redis.Set(key, "", time.Second)
  2468. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2469. redis.Set(keyOne, "", time.Second)
  2470. defer redis.Close()
  2471. fmt.Println(getNurseErr)
  2472. }
  2473. }
  2474. if adminUserInfo.Org.Id == 9583 {
  2475. //获取透析处方的最后一条数据
  2476. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if diaerr != nil {
  2478. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2483. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2484. }
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2496. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2497. }
  2498. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2499. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2500. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2501. }
  2502. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2505. }
  2506. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2507. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2508. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2509. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2510. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2511. }
  2512. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2513. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2514. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2515. }
  2516. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2517. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2518. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2519. }
  2520. if lastAssessmentAfterDislysis != nil {
  2521. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2522. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2523. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2524. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2525. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2526. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2527. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2528. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2529. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2530. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2531. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2532. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2533. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2534. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2535. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2536. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2537. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2538. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2539. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2540. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2541. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2542. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2543. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2544. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2545. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2546. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2547. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2548. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2549. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2550. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2551. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2552. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2553. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2554. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2555. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2556. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2557. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2558. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2559. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2560. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2561. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2562. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2563. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2564. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2565. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2566. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2567. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2568. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2569. if tempassessmentAfterDislysis.PatientId == 18695 {
  2570. tempassessmentAfterDislysis.ActualDisplacement = 0
  2571. }
  2572. if adminUserInfo.Org.Id != 10375 {
  2573. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2574. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2575. }
  2576. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2577. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2578. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2579. }
  2580. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2581. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. }
  2584. }
  2585. finish := models.XtDialysisFinish{
  2586. IsFinish: 1,
  2587. UserOrgId: adminUserInfo.Org.Id,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. Module: 9,
  2592. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2593. Sourse: 1,
  2594. PatientId: tempassessmentAfterDislysis.PatientId,
  2595. }
  2596. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2597. if dialysisFinish.ID == 0 {
  2598. service.CreateDialysisFinish(finish)
  2599. }
  2600. //孝康
  2601. if adminUserInfo.Org.Id == 10693 {
  2602. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2603. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2604. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2605. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2606. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2607. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2608. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2609. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2610. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2612. }
  2613. if adminUserInfo.Org.Id == 10697 {
  2614. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2615. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2616. lastWeightAfter.LastAfterWeight = floatAfeter
  2617. }
  2618. if adminUserInfo.Org.Id == 10721 {
  2619. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2620. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2621. }
  2622. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2624. redis := service.RedisClient()
  2625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2626. redis.Set(keyOne, "", time.Second)
  2627. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2628. redis.Set(keyTwo, "", time.Second)
  2629. defer redis.Close()
  2630. //清空key 值
  2631. redis.Set(key, "", time.Second)
  2632. if err != nil {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2634. return
  2635. }
  2636. if dialysisOrder == nil {
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2638. return
  2639. }
  2640. if dialysisOrder.Stage == 2 {
  2641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2642. return
  2643. }
  2644. if dialysisOrder.Stage == 1 {
  2645. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2646. finish := models.XtDialysisFinish{
  2647. IsFinish: 1,
  2648. UserOrgId: adminUserInfo.Org.Id,
  2649. Status: 1,
  2650. Ctime: time.Now().Unix(),
  2651. Mtime: 0,
  2652. Module: 8,
  2653. RecordDate: recordDate.Unix(),
  2654. Sourse: 1,
  2655. PatientId: id,
  2656. }
  2657. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2658. if dialysisFinish.ID == 0 {
  2659. service.CreateDialysisFinish(finish)
  2660. }
  2661. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2662. redis := service.RedisClient()
  2663. defer redis.Close()
  2664. //清空key 值
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2667. redis.Set(keyOne, "", time.Second)
  2668. //结束时候透析次数加1
  2669. service.UpdateSolutionByPatientId(id)
  2670. //下机完自动消毒,针对长沙南雅
  2671. if dialysisOrder.Stage == 1 {
  2672. 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 {
  2673. //根据床位号获取设备型号
  2674. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2675. //查询使用消毒最后一条消毒记录
  2676. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2677. fmt.Println("err", err)
  2678. if err == gorm.ErrRecordNotFound {
  2679. //查找排班
  2680. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2681. //查询改设备是否有消毒计划
  2682. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2683. //根据床位号获取设备id
  2684. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2685. //查询病人信息
  2686. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2687. var con = ""
  2688. if patients.IsInfectious == 0 {
  2689. con = ""
  2690. }
  2691. if patients.IsInfectious == 1 {
  2692. con = "无"
  2693. }
  2694. if patients.IsInfectious == 2 {
  2695. con = "有"
  2696. }
  2697. if errcode == nil {
  2698. var end_time int64
  2699. end_time = endDate.Unix() + plan.DisinfecTime*60
  2700. //新增消毒
  2701. information := models.DeviceInformation{
  2702. Date: dialysisOrder.DialysisDate,
  2703. Zone: dialysisOrder.ZoneId,
  2704. Class: dialysisOrder.SchedualType,
  2705. BedNumber: dialysisOrder.BedID,
  2706. PatientId: dialysisOrder.PatientId,
  2707. DialysisMode: scheduleByPatient.ModeId,
  2708. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2709. Disinfection: 1,
  2710. DialysisConcentration: 1,
  2711. DisinfectionStatus: 1,
  2712. Move: 1,
  2713. UserOrgId: dialysisOrder.UserOrgId,
  2714. DisinfectType: plan.Way,
  2715. DisinfectantType: plan.MachineDisinfectant,
  2716. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2717. Disinfectant: plan.Disinfectant,
  2718. Ctime: time.Now().Unix(),
  2719. Status: 1,
  2720. SignName: nurseID,
  2721. EquimentId: addmacher.ID,
  2722. DisinfectionResidue: 2,
  2723. Bed: addmacher.BedNumber,
  2724. StartTime: dialysisOrder.StartTime,
  2725. EndTime: dialysisOrder.EndTime,
  2726. Contagion: con,
  2727. WeightLoss: 0,
  2728. Hyperfiltratio: 0,
  2729. DialysisHour: "",
  2730. MachineRun: 1,
  2731. DisinfecStartime: endDate.Unix(),
  2732. DisinfecEndtime: end_time,
  2733. }
  2734. err := service.CreateInformationTwo(&information)
  2735. fmt.Println("报错", err)
  2736. }
  2737. }
  2738. }
  2739. }
  2740. dialysisOrder.Stage = 2
  2741. dialysisOrder.FinishNurse = nurseID
  2742. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2743. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2744. dialysisOrder.EndTime = endDate.Unix()
  2745. // 长沙南雅需求
  2746. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2747. //获取最后1条监测的数据
  2748. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2749. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2750. var accumulatedBloodVolume float64
  2751. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2752. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2753. fmt.Println(err)
  2754. // 查询未执行的医嘱
  2755. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2756. for _, item := range doctorAdvice {
  2757. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2758. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2759. redis := service.RedisClient()
  2760. //清空key 值
  2761. redis.Set(key, "", time.Second)
  2762. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2763. redis.Set(keyTwo, "", time.Second)
  2764. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2765. redis.Set(keyThree, "", time.Second)
  2766. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2767. theTime := toTime.Format("2006-01-02")
  2768. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2769. redis.Set(keyFour, "", time.Second)
  2770. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2771. redis.Set(keyFive, "", time.Second)
  2772. defer redis.Close()
  2773. }
  2774. }
  2775. go func() {
  2776. ssoDomain := beego.AppConfig.String("call_domain")
  2777. api := ssoDomain + "/index/downpatient"
  2778. values := make(url.Values)
  2779. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2780. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2781. values.Set("patient_id", strconv.FormatInt(id, 10))
  2782. http.PostForm(api, values)
  2783. }()
  2784. if err == nil {
  2785. c.ServeSuccessJSON(map[string]interface{}{
  2786. "dialysisOrder": dialysisOrder,
  2787. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2788. })
  2789. } else {
  2790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2791. }
  2792. }
  2793. }
  2794. func (c *DialysisAPIController) GetAllZone() {
  2795. adminUserInfo := c.GetMobileAdminUserInfo()
  2796. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2797. if err == nil {
  2798. c.ServeSuccessJSON(map[string]interface{}{
  2799. "zone": zone,
  2800. })
  2801. }
  2802. }
  2803. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2804. adminUserInfo := c.GetMobileAdminUserInfo()
  2805. page, _ := c.GetInt64("page", 1)
  2806. limit, _ := c.GetInt64("limit", 10)
  2807. schedulType, _ := c.GetInt64("schedul_type", 0)
  2808. startTime, _ := c.GetInt64("schedul_time", 0)
  2809. partitionType, _ := c.GetInt64("partition_type", 0)
  2810. keywords := c.GetString("keywords")
  2811. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2812. if err == nil {
  2813. c.ServeSuccessJSON(map[string]interface{}{
  2814. "schedule": dialysisSchedule,
  2815. })
  2816. }
  2817. return
  2818. }
  2819. // /m/api/dialysis/start [post]
  2820. // @param patient_id:int
  2821. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2822. // @param nurse:int 上机护士
  2823. // @param bed:int 床位号
  2824. func (this *DialysisAPIController) StartDialysis() {
  2825. patientID, _ := this.GetInt64("patient_id")
  2826. recordDateStr := this.GetString("record_date")
  2827. nurseID, _ := this.GetInt64("start_nurse")
  2828. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2829. blood_drawing, _ := this.GetInt64("blood_drawing")
  2830. schedual_type, _ := this.GetInt64("schedual_type")
  2831. bedID, _ := this.GetInt64("bed")
  2832. start_time := this.GetString("start_time")
  2833. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2834. change_nurse, _ := this.GetInt64("change_nurse")
  2835. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2836. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2837. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2838. puncture_needle := this.GetString("puncture_needle")
  2839. puncture_way := this.GetString("puncture_way")
  2840. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2841. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2842. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2843. zone_id, _ := this.GetInt64("zone_id")
  2844. elecsign := this.GetString("url")
  2845. nuclein_date_str := this.GetString("nuclein_date_str")
  2846. schedule_remark := this.GetString("schedule_remark")
  2847. order_remark := this.GetString("order_remark")
  2848. catheter_operation := this.GetString("catheter_operation")
  2849. blood_flow_volume := this.GetString("blood_flow_volume")
  2850. dialysis_strainer := this.GetString("dialysis_strainer")
  2851. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2853. return
  2854. }
  2855. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2856. if parseStartDateErr != nil {
  2857. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2859. return
  2860. }
  2861. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2862. if parseErr != nil {
  2863. this.ErrorLog("时间解析失败:%v", parseErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2865. return
  2866. }
  2867. adminUserInfo := this.GetMobileAdminUserInfo()
  2868. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2869. if getPatientErr != nil {
  2870. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2872. return
  2873. } else if patient == nil {
  2874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2875. return
  2876. }
  2877. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2878. if getNurseErr != nil {
  2879. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2881. return
  2882. } else if nurse == nil {
  2883. this.ErrorLog("护士不存在")
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2885. return
  2886. }
  2887. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2888. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2889. if getDeviceNumberErr != nil {
  2890. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2892. return
  2893. } else if deviceNumber == nil {
  2894. this.ErrorLog("床位号不存在")
  2895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2899. if getRecordErr != nil {
  2900. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2902. return
  2903. } else if dialysisRecord != nil {
  2904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2905. return
  2906. }
  2907. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2908. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2909. timeLayout := "2006-01-02 15:04:05"
  2910. loc, _ := time.LoadLocation("Local")
  2911. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2912. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2913. schedulestartTime := theStartTime.Unix()
  2914. scheduleendTime := theEndTime.Unix()
  2915. var theNucleinDate int64
  2916. timeLayoutOne := "2006-01-02"
  2917. if len(nuclein_date_str) > 0 {
  2918. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2919. if err != nil {
  2920. utils.ErrorLog(err.Error())
  2921. }
  2922. theNucleinDate = theTime.Unix()
  2923. }
  2924. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2925. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2926. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2927. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2928. //查询该床位是否有人用了
  2929. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2930. if err == gorm.ErrRecordNotFound { //空床位
  2931. // 修改了床位逻辑
  2932. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2933. if daySchedule.ID > 0 {
  2934. daySchedule.PartitionId = deviceNumber.ZoneID
  2935. daySchedule.BedId = bedID
  2936. daySchedule.ScheduleType = schedual_type
  2937. daySchedule.UpdatedTime = time.Now().Unix()
  2938. xtSchedule := models.Schedule{
  2939. PartitionId: deviceNumber.ZoneID,
  2940. BedId: bedID,
  2941. ScheduleType: schedual_type,
  2942. UpdatedTime: time.Now().Unix(),
  2943. }
  2944. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2945. if err != nil {
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2947. return
  2948. }
  2949. }
  2950. } else if err == nil {
  2951. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2952. if order.ID > 0 { //该机位被其他人占用了
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2954. return
  2955. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2956. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2957. if daySchedule.ID > 0 {
  2958. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2959. if err != nil {
  2960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2961. return
  2962. }
  2963. }
  2964. }
  2965. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2967. return
  2968. }
  2969. //else if order.ID == 0 { //该床位没被占用
  2970. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2971. // if daySchedule.ID > 0 {
  2972. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2973. // //daySchedule.BedId = bedID
  2974. // //daySchedule.ScheduleType = schedual_type
  2975. // //daySchedule.UpdatedTime = time.Now().Unix()
  2976. // //err := service.UpdateSchedule(&daySchedule)
  2977. // xtSchedule := models.Schedule{
  2978. // PartitionId: deviceNumber.ZoneID,
  2979. // BedId: bedID,
  2980. // ScheduleType: schedual_type,
  2981. // UpdatedTime: time.Now().Unix(),
  2982. // }
  2983. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2984. // if err != nil {
  2985. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. // return
  2987. // }
  2988. // }
  2989. //}
  2990. //}
  2991. } else if err != nil {
  2992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2993. return
  2994. }
  2995. // 查询信息规挡的设置天数
  2996. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2997. if infor.ID > 0 && infor.WeekDay > 0 {
  2998. var cha_time int64
  2999. timeNowStr := time.Now().Format("2006-01-02")
  3000. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3001. //今日的日期减去设置的日期
  3002. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3003. if cha_time >= recordDate.Unix() {
  3004. //查询审核是否允许
  3005. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3006. //申请状态不允许的情况 拒绝修改
  3007. if infor.ApplicationStatus != 1 {
  3008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3009. return
  3010. }
  3011. }
  3012. }
  3013. dialysisRecord = &models.DialysisOrder{
  3014. DialysisDate: recordDate.Unix(),
  3015. UserOrgId: adminUserInfo.Org.Id,
  3016. PatientId: patientID,
  3017. Stage: 1,
  3018. BedID: bedID,
  3019. StartNurse: nurseID,
  3020. Status: 1,
  3021. StartTime: startDate.Unix(),
  3022. CreatedTime: time.Now().Unix(),
  3023. UpdatedTime: time.Now().Unix(),
  3024. PunctureNurse: puncture_nurse,
  3025. Creator: adminUserInfo.AdminUser.Id,
  3026. Modifier: adminUserInfo.AdminUser.Id,
  3027. SchedualType: schedual_type,
  3028. WashpipeNurse: washpipe_nurse,
  3029. ChangeNurse: change_nurse,
  3030. DifficultPunctureNurse: difficult_puncture_nurse,
  3031. NewFistulaNurse: new_fistula_nurse,
  3032. ZoneId: zone_id,
  3033. QualityNurseId: quality_nurse_id,
  3034. PunctureNeedle: puncture_needle,
  3035. PunctureWay: puncture_way,
  3036. DialysisIrrigation: dialysis_irrigation,
  3037. DialysisDialyszers: dialysis_dialyszers,
  3038. BloodAccessId: blood_access_id,
  3039. Url: elecsign,
  3040. NucleinDate: theNucleinDate,
  3041. ScheduleRemark: schedule_remark,
  3042. OrderRemark: order_remark,
  3043. CatheterOperation: catheter_operation,
  3044. BloodFlowVolume: blood_flow_volume,
  3045. BloodDrawing: blood_drawing,
  3046. DialysisStrainer: dialysis_strainer,
  3047. }
  3048. //查询该床位是否有人用了
  3049. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3050. if errorscode == gorm.ErrRecordNotFound {
  3051. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3052. finish := models.XtDialysisFinish{
  3053. IsFinish: 1,
  3054. UserOrgId: adminUserInfo.Org.Id,
  3055. Status: 1,
  3056. Ctime: time.Now().Unix(),
  3057. Mtime: 0,
  3058. Module: 6,
  3059. RecordDate: schedulestartTime,
  3060. Sourse: 1,
  3061. PatientId: patientID,
  3062. }
  3063. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3064. if dialysisFinish.ID == 0 {
  3065. service.CreateDialysisFinish(finish)
  3066. }
  3067. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3068. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3069. //统计该患者总次数
  3070. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3071. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3072. }
  3073. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3074. //统计该患者总次数
  3075. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3076. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3077. }
  3078. redis := service.RedisClient()
  3079. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3080. redis.Set(key, "", time.Second)
  3081. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3082. //清空key 值
  3083. redis.Set(keyOne, "", time.Second)
  3084. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3085. //清空key 值
  3086. redis.Set(keyTwo, "", time.Second)
  3087. if createErr != nil {
  3088. this.ErrorLog("上机失败:%v", createErr)
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3090. return
  3091. }
  3092. }
  3093. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3094. var tempdispose string
  3095. // 只针对中能建
  3096. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3097. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3098. }
  3099. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3100. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3101. }
  3102. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3103. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3104. //}
  3105. var ultrafiltration_rate float64
  3106. var ultrafiltration_rate_one string
  3107. var replacement_rate float64
  3108. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3109. //后期预增脱水量
  3110. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3111. if prescription.ID > 0 {
  3112. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3113. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3114. 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
  3115. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3116. }
  3117. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3118. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3119. }
  3120. //针对医师汇
  3121. if adminUserInfo.Org.Id == 10121 {
  3122. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3123. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3124. }
  3125. //针对通道
  3126. if adminUserInfo.Org.Id == 10234 {
  3127. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3128. }
  3129. //针对监利大垸医院
  3130. if template.TemplateId == 41 {
  3131. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3132. }
  3133. //针对肇庆三鹤血液透析中心
  3134. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3135. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3136. }
  3137. if adminUserInfo.Org.Id == 10469 {
  3138. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3139. }
  3140. if adminUserInfo.Org.Id == 10667 {
  3141. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3142. }
  3143. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3144. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3145. }
  3146. // 只针对方济医院
  3147. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3148. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3149. ultrafiltration_rate = value
  3150. }
  3151. //针对
  3152. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10551 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10580 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10629 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10644 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate / 1000
  3175. }
  3176. if adminUserInfo.Org.Id == 10667 {
  3177. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3178. ultrafiltration_rate = ultrafiltration_rate / 1000
  3179. }
  3180. if adminUserInfo.Org.Id == 10693 {
  3181. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3182. ultrafiltration_rate = ultrafiltration_rate
  3183. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3184. }
  3185. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3186. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate
  3188. }
  3189. if adminUserInfo.Org.Id == 10702 {
  3190. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3191. ultrafiltration_rate = ultrafiltration_rate / 1000
  3192. }
  3193. if adminUserInfo.Org.Id == 10723 {
  3194. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3195. ultrafiltration_rate = ultrafiltration_rate / 1000
  3196. }
  3197. if adminUserInfo.Org.Id == 10721 {
  3198. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3199. ultrafiltration_rate = ultrafiltration_rate / 1000
  3200. }
  3201. }
  3202. }
  3203. record := models.MonitoringRecord{
  3204. UserOrgId: adminUserInfo.Org.Id,
  3205. PatientId: patientID,
  3206. DialysisOrderId: dialysisRecord.ID,
  3207. MonitoringDate: schedulestartTime,
  3208. OperateTime: startDate.Unix(),
  3209. // MonitoringTime: recordTime,
  3210. MonitoringNurse: nurseID,
  3211. Dispose: tempdispose,
  3212. UltrafiltrationRate: ultrafiltration_rate,
  3213. UltrafiltrationVolume: 0,
  3214. Status: 1,
  3215. CreatedTime: time.Now().Unix(),
  3216. UpdatedTime: time.Now().Unix(),
  3217. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3218. ReplacementRate: replacement_rate,
  3219. }
  3220. //只针对广慈医院
  3221. 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 {
  3222. // 查询病人是否有透前评估数据
  3223. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3224. //如果有数据就插入
  3225. if errcode == nil {
  3226. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3227. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3228. record.BreathingRate = befor.BreathingRate
  3229. record.PulseFrequency = befor.PulseFrequency
  3230. record.Temperature = befor.Temperature
  3231. }
  3232. }
  3233. //孝昌
  3234. if adminUserInfo.Org.Id == 10693 {
  3235. // 查询病人是否有透前评估数据
  3236. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3237. //如果有数据就插入
  3238. if errcode == nil {
  3239. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3240. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3241. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3242. record.BreathingRate = befor.BreathingRate
  3243. }
  3244. }
  3245. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3246. if newdialysisRecord.ID > 0 {
  3247. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3248. record.Temperature = 36.5
  3249. record.ArterialPressure = -100
  3250. record.DialysateTemperature = 36.5
  3251. record.Conductivity = 14
  3252. record.BreathingRate = "20"
  3253. record.VenousPressure = 80
  3254. record.TransmembranePressure = 60
  3255. record.Dispose = catheter_operation
  3256. }
  3257. //针对新化博翔
  3258. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3259. record.BloodOxygenSaturation = "99"
  3260. record.Conductivity = 14
  3261. record.DialysateTemperature = 36.5
  3262. record.BreathingRate = "20"
  3263. }
  3264. //针对兰溪人民医院的需求
  3265. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3266. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3267. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3268. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3269. record.Temperature = befor.Temperature
  3270. record.PulseFrequency = befor.PulseFrequency
  3271. record.BreathingRate = befor.BreathingRate
  3272. }
  3273. //针对乐山友谊医院的需求
  3274. if adminUserInfo.Org.Id == 10677 {
  3275. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3276. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3277. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3278. record.Temperature = befor.Temperature
  3279. record.PulseFrequency = befor.PulseFrequency
  3280. record.BreathingRate = befor.BreathingRate
  3281. }
  3282. //新化博翔
  3283. if adminUserInfo.Org.Id == 10447 {
  3284. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3285. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3286. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3287. record.BreathingRate = befor.BreathingRate
  3288. }
  3289. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3290. record.PulseFrequency = 80
  3291. record.Temperature = 36.5
  3292. }
  3293. //诊断灵山圣康
  3294. if adminUserInfo.Org.Id == 10375 {
  3295. record.Conductivity = 13.8
  3296. record.DialysateTemperature = 37
  3297. record.DialysateFlow = 500
  3298. record.BloodFlowVolume = 200
  3299. record.BreathingRate = "18"
  3300. record.SodiumConcentration = 140
  3301. }
  3302. //江成肾病医院
  3303. if adminUserInfo.Org.Id == 10517 {
  3304. record.SodiumConcentration = 138
  3305. record.DialysateTemperature = 36.5
  3306. }
  3307. //濉溪杏康血液透析中心
  3308. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3309. record.BloodFlowVolume = prescription.BloodFlowVolume
  3310. }
  3311. if adminUserInfo.Org.Id != 10683 {
  3312. err = service.CreateMonitor(&record)
  3313. }
  3314. //记录日志
  3315. byterequest, _ := json.Marshal(record)
  3316. monitorRecordLog := models.XtMonitorRecordLog{
  3317. RecordDate: record.MonitoringDate,
  3318. PatientId: record.PatientId,
  3319. Module: 1,
  3320. AdminUserId: adminUserInfo.AdminUser.Id,
  3321. Ctime: time.Now().Unix(),
  3322. Mtime: 0,
  3323. Status: 1,
  3324. UserOrgId: record.UserOrgId,
  3325. ErrLog: string(byterequest),
  3326. Source: "执行上机时新增监测",
  3327. }
  3328. service.CreateMonitorRecordLog(monitorRecordLog)
  3329. finish := models.XtDialysisFinish{
  3330. IsFinish: 1,
  3331. UserOrgId: adminUserInfo.Org.Id,
  3332. Status: 1,
  3333. Ctime: time.Now().Unix(),
  3334. Mtime: 0,
  3335. Module: 7,
  3336. RecordDate: schedulestartTime,
  3337. Sourse: 1,
  3338. PatientId: patientID,
  3339. }
  3340. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3341. if dialysisFinish.ID == 0 {
  3342. service.CreateDialysisFinish(finish)
  3343. }
  3344. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3345. redis := service.RedisClient()
  3346. //清空key 值
  3347. redis.Set(key, "", time.Second)
  3348. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3349. redis.Set(keyOne, "", time.Second)
  3350. defer redis.Close()
  3351. if err != nil {
  3352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3353. return
  3354. }
  3355. }
  3356. go func() {
  3357. ssoDomain := beego.AppConfig.String("call_domain")
  3358. api := ssoDomain + "/index/uppatient"
  3359. values := make(url.Values)
  3360. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3361. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3362. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3363. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3364. http.PostForm(api, values)
  3365. }()
  3366. this.ServeSuccessJSON(map[string]interface{}{
  3367. "dialysis_order": newdialysisRecord,
  3368. "monitor": record,
  3369. })
  3370. return
  3371. }
  3372. func (c *DialysisAPIController) PostSolution() {
  3373. id, _ := c.GetInt64("patient", 0)
  3374. recordDateStr := c.GetString("record_date")
  3375. if id <= 0 {
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3377. return
  3378. }
  3379. adminUserInfo := c.GetMobileAdminUserInfo()
  3380. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3381. if patient.ID == 0 {
  3382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3383. return
  3384. }
  3385. if len(recordDateStr) == 0 {
  3386. recordDateStr = time.Now().Format("2006-01-02")
  3387. }
  3388. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3389. if parseDateErr != nil {
  3390. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3392. return
  3393. }
  3394. mode_id, _ := c.GetInt64("mode_id", 0)
  3395. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3396. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3397. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3398. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3399. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3400. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3401. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3402. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3403. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3404. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3405. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3406. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3407. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3408. kalium, _ := c.GetFloat("kalium", 0)
  3409. sodium, _ := c.GetFloat("sodium", 0)
  3410. calcium, _ := c.GetFloat("calcium", 0)
  3411. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3412. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3413. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3414. glucose, _ := c.GetFloat("glucose", 0)
  3415. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3416. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3417. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3418. conductivity, _ := c.GetFloat("conductivity", 0)
  3419. remark := c.GetString("remark")
  3420. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3421. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3422. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3423. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3424. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3425. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3426. special_medicine_other := c.GetString("special_medicine_other")
  3427. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3428. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3429. blood_access, _ := c.GetInt64("blood_access", 0)
  3430. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3431. body_fluid_other := c.GetString("body_fluid_other")
  3432. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3433. niprocart, _ := c.GetInt64("niprocart", 0)
  3434. jms, _ := c.GetInt64("jms", 0)
  3435. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3436. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3437. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3438. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3439. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3440. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3441. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3442. injector, _ := c.GetInt64("injector", 0)
  3443. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3444. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3445. safe_package, _ := c.GetInt64("package", 0)
  3446. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3447. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3448. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3449. blood := c.GetString("blood")
  3450. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3451. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3452. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3453. displace_speed := c.GetString("displace_speed")
  3454. illness, _ := c.GetInt64("illness")
  3455. amylaceum := c.GetString("amylaceum")
  3456. single_time := c.GetString("single_time")
  3457. single_water := c.GetString("single_water")
  3458. replacement_flow := c.GetString("replacement_flow")
  3459. plasma_separator := c.GetString("plasma_separator")
  3460. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3461. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3462. oxygen_flow := c.GetString("oxygen_flow")
  3463. oxygen_time := c.GetString("oxygen_time")
  3464. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3465. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3466. puncture_needle := c.GetString("puncture_needle")
  3467. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3468. epo := c.GetString("epo")
  3469. epo_count, _ := c.GetFloat("epo_count", 0)
  3470. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3471. pre_impulse := c.GetString("pre_impulse")
  3472. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3473. admin_user_id, _ := c.GetInt64("admin_user_id")
  3474. is_water := c.GetString("is_water")
  3475. add_amount, _ := c.GetFloat("add_amount")
  3476. reduce_amount, _ := c.GetFloat("reduce_amount")
  3477. prescribing_number, _ := c.GetFloat("prescribing_number")
  3478. treatment_remark := c.GetString("treatment_remark")
  3479. prescription_sodium := c.GetString("prescription_sodium")
  3480. start_sodium := c.GetString("start_sodium")
  3481. sodium_curve := c.GetString("sodium_curve")
  3482. var is_war int64
  3483. if is_water == "是" {
  3484. is_war = 1
  3485. }
  3486. if is_water == "否" {
  3487. is_war = 2
  3488. }
  3489. if is_water == "请选择" {
  3490. is_war = 0
  3491. }
  3492. drhy_water := c.GetString("drhy_water")
  3493. dry_water_hour := c.GetString("dry_water_hour")
  3494. water_machine := c.GetString("water_machine")
  3495. dialysis_remark := c.GetString("dialysis_remark")
  3496. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3497. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3498. prescription_water, _ := c.GetFloat("prescription_water")
  3499. dialysis_strainer := c.GetString("dialysis_strainer")
  3500. chaptalization := c.GetString("chaptalization")
  3501. washing_time := c.GetString("washing_time")
  3502. warsh_count := c.GetString("warsh_count")
  3503. blood_access_part_id := c.GetString("blood_access_part_id")
  3504. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3505. dialyzate := c.GetString("dialyzate")
  3506. if mode_id > 0 {
  3507. var str string
  3508. //查找该机构用的是什么透析器
  3509. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3510. if filedConfig.ID > 0 {
  3511. str = dialyzerPerfusionApparatus
  3512. } else {
  3513. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3514. }
  3515. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3516. }
  3517. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3518. //
  3519. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3520. // if appRole.UserType == 3 {
  3521. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3522. // if getPermissionErr != nil {
  3523. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3524. // return
  3525. // } else if headNursePermission == nil {
  3526. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3527. // return
  3528. // }
  3529. // }
  3530. //}
  3531. // 查询信息规挡的设置天数
  3532. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3533. if infor.ID > 0 && infor.WeekDay > 0 {
  3534. var cha_time int64
  3535. timeNowStr := time.Now().Format("2006-01-02")
  3536. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3537. //今日的日期减去设置的日期
  3538. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3539. if cha_time >= recordDate.Unix() {
  3540. //查询审核是否允许
  3541. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3542. //申请状态不允许的情况 拒绝修改
  3543. if infor.ApplicationStatus != 1 {
  3544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3545. return
  3546. }
  3547. }
  3548. }
  3549. prescription := models.DialysisPrescription{
  3550. UserOrgId: adminUserInfo.Org.Id,
  3551. PatientId: id,
  3552. RecordDate: recordDate.Unix(),
  3553. ModeId: mode_id,
  3554. DialysisDuration: dialysis_duration,
  3555. Dialyzer: dialyzer,
  3556. PerfusionApparatus: perfusion_apparatus,
  3557. BloodFlowVolume: blood_flow_volume,
  3558. DewaterAmount: dewater_amount,
  3559. DisplaceLiqui: displace_liqui,
  3560. ReplacementWay: replacement_way,
  3561. Anticoagulant: anticoagulant,
  3562. AnticoagulantShouji: anticoagulant_shouji,
  3563. AnticoagulantWeichi: anticoagulant_weichi,
  3564. AnticoagulantZongliang: anticoagulant_zongliang,
  3565. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3566. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3567. Kalium: kalium,
  3568. Sodium: sodium,
  3569. Calcium: calcium,
  3570. Bicarbonate: bicarbonate,
  3571. Glucose: glucose,
  3572. // DryWeight: dry_weight,
  3573. DialysateFlow: dialysate_flow,
  3574. DialysateTemperature: dialysate_temperature,
  3575. Conductivity: conductivity,
  3576. Remark: remark,
  3577. Status: 1,
  3578. CreatedTime: time.Now().Unix(),
  3579. UpdatedTime: time.Now().Unix(),
  3580. DialysisDurationMinute: dialysisDurationMinute,
  3581. DialysisDurationHour: dialysisDurationHour,
  3582. TargetUltrafiltration: targetUltrafiltration,
  3583. DialysateFormulation: dialysateFormulation,
  3584. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3585. BodyFluid: body_fluid,
  3586. SpecialMedicine: special_medicine,
  3587. SpecialMedicineOther: special_medicine_other,
  3588. DisplaceLiquiPart: displace_liqui_part,
  3589. DisplaceLiquiValue: displace_liqui_value,
  3590. BloodAccess: blood_access,
  3591. Ultrafiltration: ultrafiltration,
  3592. BodyFluidOther: body_fluid_other,
  3593. ReplacementTotal: replacement_total,
  3594. Niprocart: niprocart,
  3595. Jms: jms,
  3596. FistulaNeedleSet: fistula_needle_set,
  3597. FistulaNeedleSet16: fistula_needle_set_16,
  3598. Hemoperfusion: hemoperfusion,
  3599. DialyserSterilised: dialyser_sterilised,
  3600. Filtryzer: filtryzer,
  3601. TargetKtv: target_ktv,
  3602. Dialyzers: dialyzers,
  3603. Injector: injector,
  3604. Bloodlines: bloodlines,
  3605. TubingHemodialysis: tubing_hemodialysis,
  3606. Package: safe_package,
  3607. ALiquid: a_liquid,
  3608. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3609. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3610. Blood: blood,
  3611. DialysisDialyszers: dialysis_dialyszers,
  3612. DialysisIrrigation: dialysis_irrigation,
  3613. AntioxidantCommodityName: antioxidant_commodity_name,
  3614. DisplaceSpeed: displace_speed,
  3615. Illness: illness,
  3616. Amylaceum: amylaceum,
  3617. SingleWater: single_water,
  3618. SingleTime: single_time,
  3619. ReplacementFlow: replacement_flow,
  3620. PlasmaSeparator: plasma_separator,
  3621. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3622. OxygenUptake: oxygen_uptake,
  3623. OxygenTime: oxygen_time,
  3624. OxygenFlow: oxygen_flow,
  3625. HemodialysisPipelines: hemodialysis_pipelines,
  3626. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3627. PunctureNeedle: puncture_needle,
  3628. PunctureNeedleCount: puncture_needle_count,
  3629. Epo: epo,
  3630. EpoCount: epo_count,
  3631. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3632. PreImpulse: impulse,
  3633. AdminUserId: admin_user_id,
  3634. IsWater: is_war,
  3635. DrhyWater: drhy_water,
  3636. DryWaterHour: dry_water_hour,
  3637. WaterMachine: water_machine,
  3638. AddAmount: add_amount,
  3639. ReduceAmount: reduce_amount,
  3640. DialysisRemark: dialysis_remark,
  3641. PrescribingNumber: prescribing_number,
  3642. PrescriptionSodium: prescription_sodium,
  3643. StartSodium: start_sodium,
  3644. SodiumCurve: sodium_curve,
  3645. TreatmentRemark: treatment_remark,
  3646. DialysisFluidFlow: dialysis_fluid_flow,
  3647. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3648. PrescriptionWater: prescription_water,
  3649. DialysisStrainer: dialysis_strainer,
  3650. Chaptalization: chaptalization,
  3651. WashingTime: washing_time,
  3652. WarshCount: warsh_count,
  3653. BloodAccessPartId: blood_access_part_id,
  3654. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3655. Dialyzate: dialyzate,
  3656. }
  3657. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3658. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3659. //
  3660. if appRole.UserType == 2 || appRole.UserType == 1 {
  3661. prescription_doctor = adminUserInfo.AdminUser.Id
  3662. prescription.PrescriptionDoctor = prescription_doctor
  3663. }
  3664. if dialysisPrescription.ID == 0 { //新增
  3665. prescription.Creater = adminUserInfo.AdminUser.Id
  3666. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3667. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3668. }
  3669. } else { //修改
  3670. if dialysisPrescription.Creater == 0 {
  3671. prescription.Creater = adminUserInfo.AdminUser.Id
  3672. } else {
  3673. prescription.Creater = dialysisPrescription.Creater
  3674. if adminUserInfo.Org.Id == 9882 {
  3675. if appRole.UserType == 2 || appRole.UserType == 1 {
  3676. prescription.Creater = adminUserInfo.AdminUser.Id
  3677. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3678. }
  3679. }
  3680. }
  3681. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3682. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3683. }
  3684. //if/**/
  3685. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3686. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3687. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3688. // if getPermissionErr != nil {
  3689. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3690. // return
  3691. // } else if headNursePermission == nil {
  3692. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3693. // return
  3694. // }
  3695. //}
  3696. //prescription.Creater = dialysisPrescription.Creater
  3697. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3698. prescription.Modifier = adminUserInfo.AdminUser.Id
  3699. prescription.ID = dialysisPrescription.ID
  3700. }
  3701. solution := models.DialysisSolution{
  3702. RegistrarsId: adminUserInfo.AdminUser.Id,
  3703. UserOrgId: adminUserInfo.Org.Id,
  3704. Doctor: prescription_doctor,
  3705. PatientId: id,
  3706. ModeId: mode_id,
  3707. DialysisDuration: dialysis_duration,
  3708. PerfusionApparatus: perfusion_apparatus,
  3709. BloodFlowVolume: blood_flow_volume,
  3710. Dewater: dewater_amount,
  3711. DisplaceLiqui: displace_liqui,
  3712. ReplacementWay: replacement_way,
  3713. Anticoagulant: anticoagulant,
  3714. AnticoagulantShouji: anticoagulant_shouji,
  3715. AnticoagulantWeichi: anticoagulant_weichi,
  3716. AnticoagulantZongliang: anticoagulant_zongliang,
  3717. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3718. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3719. Kalium: kalium,
  3720. Sodium: sodium,
  3721. Calcium: calcium,
  3722. Bicarbonate: bicarbonate,
  3723. Glucose: glucose,
  3724. // DryWeight: dry_weight,
  3725. DialysateFlow: dialysate_flow,
  3726. DialysateTemperature: dialysate_temperature,
  3727. Conductivity: conductivity,
  3728. Remark: remark,
  3729. Status: 1,
  3730. CreatedTime: time.Now().Unix(),
  3731. UpdatedTime: time.Now().Unix(),
  3732. DialysisDurationMinute: dialysisDurationMinute,
  3733. DialysisDurationHour: dialysisDurationHour,
  3734. TargetUltrafiltration: targetUltrafiltration,
  3735. DialysateFormulation: dialysateFormulation,
  3736. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3737. BodyFluid: body_fluid,
  3738. SpecialMedicine: special_medicine,
  3739. SpecialMedicineOther: special_medicine_other,
  3740. DisplaceLiquiPart: displace_liqui_part,
  3741. DisplaceLiquiValue: displace_liqui_value,
  3742. BloodAccess: blood_access,
  3743. Ultrafiltration: ultrafiltration,
  3744. BodyFluidOther: body_fluid_other,
  3745. ReplacementTotal: replacement_total,
  3746. TargetKtv: target_ktv,
  3747. DialysisDialyszers: dialysis_dialyszers,
  3748. DialysisIrrigation: dialysis_irrigation,
  3749. HemodialysisPipelines: hemodialysis_pipelines,
  3750. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3751. PunctureNeedle: puncture_needle,
  3752. PunctureNeedleCount: puncture_needle_count,
  3753. Epo: epo,
  3754. EpoCount: epo_count,
  3755. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3756. PreImpulse: impulse,
  3757. SolutionStatus: 1,
  3758. DialysisRemark: dialysis_remark,
  3759. PrescribingNumber: prescribing_number,
  3760. PrescriptionSodium: prescription_sodium,
  3761. StartSodium: start_sodium,
  3762. SodiumCurve: sodium_curve,
  3763. TreatmentRemark: treatment_remark,
  3764. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3765. DialysisFluidFlow: dialysis_fluid_flow,
  3766. PrescriptionWater: prescription_water,
  3767. DialysisStrainer: dialysis_strainer,
  3768. Chaptalization: chaptalization,
  3769. WashingTime: washing_time,
  3770. WarshCount: warsh_count,
  3771. BloodAccessPartId: blood_access_part_id,
  3772. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3773. Dialyzate: dialyzate,
  3774. }
  3775. //针对河间咸的
  3776. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3777. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3778. solution.DisplaceLiquiPart = 0
  3779. solution.DisplaceLiquiValue = 0
  3780. }
  3781. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3782. prescription.DisplaceLiquiPart = 0
  3783. prescription.DisplaceLiquiValue = 0
  3784. }
  3785. }
  3786. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3787. if solution.PrescribingNumber == 0 {
  3788. solution.PrescribingNumber = 1
  3789. }
  3790. if prescription.PrescribingNumber == 0 {
  3791. prescription.PrescribingNumber = 1
  3792. }
  3793. if solution.PrescribingNumber == 0 && id == 14682 {
  3794. solution.PrescribingNumber = 2
  3795. }
  3796. if solution.PrescribingNumber == 0 && id == 18560 {
  3797. solution.PrescribingNumber = 2
  3798. }
  3799. if prescription.PrescribingNumber == 0 && id == 14682 {
  3800. prescription.PrescribingNumber = 2
  3801. }
  3802. if prescription.PrescribingNumber == 0 && id == 18560 {
  3803. prescription.PrescribingNumber = 2
  3804. }
  3805. }
  3806. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3807. //记录日志
  3808. byterequest, _ := json.Marshal(prescription)
  3809. prescriptionLog := models.XtDialysisPrescriptionLog{
  3810. UserOrgId: prescription.UserOrgId,
  3811. Ctime: time.Now().Unix(),
  3812. Mtime: 0,
  3813. ErrLog: string(byterequest),
  3814. AdminUserId: adminUserInfo.AdminUser.Id,
  3815. RecordDate: prescription.RecordDate,
  3816. PatientId: prescription.PatientId,
  3817. Source: "手机端新增长期处方",
  3818. Status: 1,
  3819. }
  3820. service.CreatePrescriptionLog(prescriptionLog)
  3821. finish := models.XtDialysisFinish{
  3822. IsFinish: 1,
  3823. UserOrgId: adminUserInfo.Org.Id,
  3824. Status: 1,
  3825. Ctime: time.Now().Unix(),
  3826. Mtime: 0,
  3827. Module: 1,
  3828. RecordDate: recordDate.Unix(),
  3829. Sourse: 1,
  3830. PatientId: id,
  3831. }
  3832. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3833. if dialysisFinish.ID == 0 {
  3834. service.CreateDialysisFinish(finish)
  3835. }
  3836. //获取最新1条
  3837. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3838. //更新状态
  3839. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3840. //长沙南雅医院,自动生成抗凝剂的临时处方
  3841. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3842. if prescribing_number == 0 {
  3843. prescribing_number = 1
  3844. }
  3845. advice := models.DoctorAdvice{
  3846. UserOrgId: adminUserInfo.Org.Id,
  3847. PatientId: id,
  3848. GroupNo: 0,
  3849. AdviceType: 2,
  3850. RecordDate: recordDate.Unix(),
  3851. AdviceDate: recordDate.Unix(),
  3852. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3853. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3854. AdviceDesc: "",
  3855. ReminderDate: 0,
  3856. SingleDose: prescription.AnticoagulantZongliang,
  3857. SingleDoseUnit: "iu",
  3858. DrugSpec: 0,
  3859. DrugSpecUnit: "",
  3860. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3861. PrescribingNumberUnit: "支",
  3862. DeliveryWay: "静脉注射",
  3863. ExecutionFrequency: "上机前",
  3864. AdviceDoctor: 0,
  3865. Status: 1,
  3866. CreatedTime: time.Now().Unix(),
  3867. UpdatedTime: time.Now().Unix(),
  3868. IsPrescription: 1,
  3869. ExecutionState: 2,
  3870. StopState: 2,
  3871. IsSettle: 2,
  3872. }
  3873. // 查询排班信息
  3874. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3875. if schedulePatient.ID > 0 {
  3876. if schedulePatient.ScheduleType == 1 {
  3877. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3878. }
  3879. if schedulePatient.ScheduleType == 2 {
  3880. advice.StartTime = recordDate.Unix() + 9*60*60
  3881. }
  3882. }
  3883. // 抗凝剂名称
  3884. switch anticoagulant {
  3885. case 1:
  3886. advice.AdviceName = "无肝素"
  3887. break
  3888. case 2:
  3889. advice.AdviceName = "普通肝素"
  3890. break
  3891. case 3:
  3892. advice.AdviceName = "低分子肝素"
  3893. break
  3894. case 4:
  3895. advice.AdviceName = "阿加曲班"
  3896. break
  3897. case 5:
  3898. advice.AdviceName = "枸橼酸钠"
  3899. break
  3900. case 6:
  3901. advice.AdviceName = "低分子肝素钙"
  3902. break
  3903. case 7:
  3904. advice.AdviceName = "低分子肝素钠"
  3905. break
  3906. case 8:
  3907. advice.AdviceName = "依诺肝素"
  3908. break
  3909. case 9:
  3910. advice.AdviceName = "达肝素"
  3911. break
  3912. case 10:
  3913. advice.AdviceName = "体外抗凝"
  3914. break
  3915. case 11:
  3916. advice.AdviceName = "那曲肝素"
  3917. break
  3918. case 12:
  3919. advice.AdviceName = "无抗凝剂"
  3920. break
  3921. }
  3922. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3923. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3924. advice.AdviceDoctor = appRole.AdminUserId
  3925. }
  3926. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3927. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3928. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3929. advice.AdviceName = "低分子肝素钠注射液"
  3930. // 修改患者临时医嘱里的抗凝剂医嘱
  3931. advice.ID = advicePrescription.ID
  3932. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3933. } else {
  3934. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3935. advice.AdviceName = "低分子肝素钠注射液"
  3936. service.CreateDoctorAdvice(&advice)
  3937. }
  3938. }
  3939. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3940. redis := service.RedisClient()
  3941. defer redis.Close()
  3942. //清空key 值
  3943. redis.Set(key, "", time.Second)
  3944. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3945. redis.Set(keyOne, "", time.Second)
  3946. }
  3947. //获取key,清空redis
  3948. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3949. redis := service.RedisClient()
  3950. defer redis.Close()
  3951. //清空key 值
  3952. redis.Set(key, "", time.Second)
  3953. //清空长期医嘱的key
  3954. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3955. redis.Set(soulution_key, "", time.Second)
  3956. //查询最近透析准备表里是否存在 透析器 灌流器
  3957. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3958. redis.Set(keyOne, "", time.Second)
  3959. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3960. redis.Set(keyTwo, "", time.Second)
  3961. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3962. redis.Set(keyThree, "", time.Second)
  3963. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3964. redis.Set(keyFour, "", time.Second)
  3965. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3966. //
  3967. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3968. //
  3969. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3970. //if len(mation)>0{
  3971. // for _, item := range splitStr {
  3972. // for _,it := range mation{
  3973. // if(item == it.SpecificationName){
  3974. //
  3975. // //查询最近一次的透析器
  3976. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3977. //
  3978. // if errcode == gorm.ErrRecordNotFound{
  3979. // //插入数据
  3980. // prepare := models.DialysisBeforePrepare{
  3981. // UserOrgId: adminUserInfo.Org.Id,
  3982. // PatientId: id,
  3983. // RecordDate: recordDate.Unix(),
  3984. // GoodTypeId: it.GoodTypeId,
  3985. // GoodId: it.ID,
  3986. // Count: 1,
  3987. // Ctime: time.Now().Unix(),
  3988. // Creater: adminUserInfo.AdminUser.Id,
  3989. // Status:1,
  3990. //
  3991. // }
  3992. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3993. // fmt.Println("",errcode)
  3994. // }
  3995. // }
  3996. // }
  3997. //
  3998. // }
  3999. //
  4000. // for _, item := range splitIrrigation {
  4001. // for _,it := range mation{
  4002. // if(item == it.SpecificationName){
  4003. // //查询最近一次的透析器
  4004. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4005. // if errcode == gorm.ErrRecordNotFound{
  4006. // //插入数据
  4007. // prepare := models.DialysisBeforePrepare{
  4008. // UserOrgId: adminUserInfo.Org.Id,
  4009. // PatientId: id,
  4010. // RecordDate: recordDate.Unix(),
  4011. // GoodTypeId: it.GoodTypeId,
  4012. // GoodId: it.ID,
  4013. // Count: 1,
  4014. // Ctime: time.Now().Unix(),
  4015. // Creater: adminUserInfo.AdminUser.Id,
  4016. // Status:1,
  4017. //
  4018. // }
  4019. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4020. // fmt.Println(errcode)
  4021. // }
  4022. // }
  4023. // }
  4024. // }
  4025. //}
  4026. c.ServeSuccessJSON(map[string]interface{}{
  4027. "solution": &solution,
  4028. "prescription": &prescription,
  4029. })
  4030. }
  4031. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4032. patient, _ := c.GetInt64("patient", 0)
  4033. adminUserInfo := c.GetMobileAdminUserInfo()
  4034. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4035. c.ServeSuccessJSON(map[string]interface{}{
  4036. "receiveTreatmentAsses": receiveTreatmentAsses,
  4037. })
  4038. }
  4039. func (this *DialysisAPIController) PostSignInfo() {
  4040. patientID, _ := this.GetInt64("patient_id")
  4041. recordDateStr := this.GetString("date")
  4042. if patientID <= 0 {
  4043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. if len(recordDateStr) == 0 {
  4047. recordDateStr = time.Now().Format("2006-01-02")
  4048. }
  4049. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4050. if parseDateErr != nil {
  4051. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4053. return
  4054. }
  4055. adminInfo := this.GetMobileAdminUserInfo()
  4056. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4057. if err != nil {
  4058. this.ErrorLog("签名失败:%v", err)
  4059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4060. return
  4061. }
  4062. this.ServeSuccessJSON(map[string]interface{}{
  4063. "doctor_id": adminInfo.AdminUser.Id,
  4064. })
  4065. }
  4066. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4067. patientID, _ := this.GetInt64("patient_id")
  4068. adminInfo := this.GetMobileAdminUserInfo()
  4069. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4070. this.ServeSuccessJSON(map[string]interface{}{
  4071. "monitor": record,
  4072. })
  4073. }
  4074. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4075. thisTime := time.Now()
  4076. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4077. timeLayout := "2006-01-02 15:04:05"
  4078. loc, _ := time.LoadLocation("Local")
  4079. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4080. theAssessmentDateTime := theStartTime.Unix()
  4081. patientID, _ := this.GetInt64("patient_id")
  4082. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4083. adminInfo := this.GetMobileAdminUserInfo()
  4084. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4085. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4086. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4087. var ultrafiltration_rate float64
  4088. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4089. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4090. fmt.Println(evaluation)
  4091. fmt.Println("prescription.ID", prescription.ID)
  4092. if prescription.ID > 0 {
  4093. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4094. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4095. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4096. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4097. record.UltrafiltrationRate = ultrafiltration_rate
  4098. }
  4099. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4100. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if adminInfo.Org.Id == 10510 {
  4104. record.UltrafiltrationRate = 0
  4105. }
  4106. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4108. record.UltrafiltrationRate = ultrafiltration_rate
  4109. }
  4110. if template.TemplateId == 20 || template.TemplateId == 22 {
  4111. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4112. record.UltrafiltrationRate = ultrafiltration_rate
  4113. }
  4114. // 只针对方济医院
  4115. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4116. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4117. ultrafiltration_rate = value
  4118. record.UltrafiltrationRate = ultrafiltration_rate
  4119. }
  4120. if template.TemplateId == 41 || template.TemplateId == 47 {
  4121. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4122. record.UltrafiltrationRate = ultrafiltration_rate
  4123. }
  4124. if template.TemplateId == 43 {
  4125. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4126. record.UltrafiltrationRate = ultrafiltration_rate
  4127. }
  4128. if template.TemplateId == 46 || template.TemplateId == 54 {
  4129. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4130. record.UltrafiltrationRate = ultrafiltration_rate
  4131. }
  4132. 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 {
  4133. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4134. record.UltrafiltrationRate = ultrafiltration_rate
  4135. }
  4136. if adminInfo.Org.Id == 10469 {
  4137. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4138. record.UltrafiltrationRate = ultrafiltration_rate
  4139. }
  4140. if adminInfo.Org.Id == 10667 {
  4141. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4142. record.UltrafiltrationRate = ultrafiltration_rate
  4143. }
  4144. if adminInfo.Org.Id == 10471 {
  4145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4146. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4147. }
  4148. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4150. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4151. }
  4152. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4154. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4155. }
  4156. if adminInfo.Org.Id == 10721 {
  4157. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4158. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4159. }
  4160. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4161. record.UltrafiltrationRate = 0
  4162. }
  4163. //if template.TemplateId == 47 {
  4164. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4165. // record.UltrafiltrationRate = ultrafiltration_rate
  4166. //}
  4167. }
  4168. }
  4169. // record.UltrafiltrationRate = ultrafiltration_rate
  4170. record.UltrafiltrationVolume = 0
  4171. 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
  4172. if ultrafiltration_rate > 0 {
  4173. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4174. record.UltrafiltrationVolume = value
  4175. }
  4176. }
  4177. 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
  4178. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4179. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4180. record.UltrafiltrationVolume = ultrafiltration_volume
  4181. }
  4182. }
  4183. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4184. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4185. record.UltrafiltrationVolume = ultrafiltration_volume
  4186. }
  4187. //长沙南雅
  4188. 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 {
  4189. if ultrafiltration_rate > 0 {
  4190. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4191. record.UltrafiltrationVolume = ultrafiltration_volume
  4192. }
  4193. }
  4194. if adminInfo.Org.Id == 10471 {
  4195. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4196. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4197. }
  4198. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4199. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4200. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4201. }
  4202. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4203. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4204. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4205. }
  4206. //长沙南雅累计血容量自动计算
  4207. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4208. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4209. //}
  4210. if template.TemplateId == 47 || template.TemplateId == 54 {
  4211. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4212. }
  4213. if adminInfo.Org.Id == 10510 {
  4214. record.UltrafiltrationVolume = 0
  4215. }
  4216. if adminInfo.Org.Id == 10721 {
  4217. if ultrafiltration_rate > 0 {
  4218. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4219. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4220. }
  4221. }
  4222. if adminInfo.Org.Id == 10721 {
  4223. var replacement_rate float64
  4224. var displacement_quantity float64
  4225. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4226. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4227. fmt.Println("replacement_rate-----------------", replacement_rate)
  4228. record.ReplacementRate = replacement_rate
  4229. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4230. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4231. fmt.Println("displacement_quantity-----------------", displacement_quantity)
  4232. record.DisplacementQuantity = displacement_quantity
  4233. }
  4234. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4235. this.ServeSuccessJSON(map[string]interface{}{
  4236. "monitor": record,
  4237. "lastMonitorRecordList": lastMonitorRecordList,
  4238. })
  4239. }
  4240. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4241. record_id, _ := this.GetInt64("id")
  4242. nurseID, _ := this.GetInt64("start_nurse")
  4243. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4244. bedID, _ := this.GetInt64("bed")
  4245. start_time := this.GetString("start_time")
  4246. schedual_type, _ := this.GetInt64("schedual_type")
  4247. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4248. change_nurse, _ := this.GetInt64("change_nurse")
  4249. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4250. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4251. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4252. patient_id, _ := this.GetInt64("patient_id")
  4253. record_date, _ := this.GetInt64("record_date")
  4254. puncture_needle := this.GetString("puncture_needle")
  4255. puncture_way := this.GetString("puncture_way")
  4256. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4257. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4258. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4259. nuclein_date_str := this.GetString("nuclein_date_str")
  4260. order_remark := this.GetString("order_remark")
  4261. schedule_remark := this.GetString("schedule_remark")
  4262. catheter_operation := this.GetString("catheter_operation")
  4263. blood_flow_volume := this.GetString("blood_flow_volume")
  4264. blood_drawing, _ := this.GetInt64("blood_drawing")
  4265. dialysis_strainer := this.GetString("dialysis_strainer")
  4266. if record_id == 0 {
  4267. this.ErrorLog("id:%v", record_id)
  4268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4269. return
  4270. }
  4271. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4272. if parseStartDateErr != nil {
  4273. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4275. return
  4276. }
  4277. adminUserInfo := this.GetMobileAdminUserInfo()
  4278. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4279. if getNurseErr != nil {
  4280. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4282. return
  4283. } else if nurse == nil {
  4284. this.ErrorLog("护士不存在")
  4285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4286. return
  4287. }
  4288. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4289. //if getNurseErr != nil {
  4290. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4291. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4292. // return
  4293. //} else if nurse == nil {
  4294. // this.ErrorLog("护士不存在")
  4295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4296. // return
  4297. //}
  4298. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4299. if getDeviceNumberErr != nil {
  4300. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4302. return
  4303. } else if deviceNumber == nil {
  4304. this.ErrorLog("床位号不存在")
  4305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4306. return
  4307. }
  4308. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4309. //
  4310. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4311. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4312. // if getPermissionErr != nil {
  4313. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4314. // return
  4315. // } else if headNursePermission == nil {
  4316. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4317. // return
  4318. // }
  4319. //}
  4320. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4321. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4322. timeLayout := "2006-01-02 15:04:05"
  4323. loc, _ := time.LoadLocation("Local")
  4324. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4325. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4326. schedulestartTime := theStartTime.Unix()
  4327. scheduleendTime := theEndTime.Unix()
  4328. var theNucleinDate int64
  4329. timeLayoutOne := "2006-01-02"
  4330. if len(nuclein_date_str) > 0 {
  4331. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4332. if err != nil {
  4333. utils.ErrorLog(err.Error())
  4334. }
  4335. theNucleinDate = theTime.Unix()
  4336. }
  4337. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4338. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4339. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4340. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4341. if err == gorm.ErrRecordNotFound { //空床位
  4342. // 修改了床位逻辑
  4343. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4344. if daySchedule.ID > 0 {
  4345. //daySchedule.BedId = bedID
  4346. //daySchedule.PartitionId = deviceNumber.ZoneID
  4347. //daySchedule.ScheduleType = schedual_type
  4348. //daySchedule.UpdatedTime = time.Now().Unix()
  4349. //err := service.UpdateSchedule(&daySchedule)
  4350. xtSchedule := models.Schedule{
  4351. PartitionId: deviceNumber.ZoneID,
  4352. BedId: bedID,
  4353. ScheduleType: schedual_type,
  4354. UpdatedTime: time.Now().Unix(),
  4355. }
  4356. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4357. if err != nil {
  4358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4359. return
  4360. }
  4361. }
  4362. } else if err == nil {
  4363. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4364. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4365. if daySchedule.ID > 0 {
  4366. //daySchedule.BedId = bedID
  4367. //daySchedule.PartitionId = deviceNumber.ZoneID
  4368. //
  4369. //daySchedule.ScheduleType = schedual_type
  4370. //daySchedule.UpdatedTime = time.Now().Unix()
  4371. //err := service.UpdateSchedule(&daySchedule)
  4372. xtSchedule := models.Schedule{
  4373. PartitionId: deviceNumber.ZoneID,
  4374. BedId: bedID,
  4375. ScheduleType: schedual_type,
  4376. UpdatedTime: time.Now().Unix(),
  4377. }
  4378. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4379. if err != nil {
  4380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4381. return
  4382. }
  4383. }
  4384. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4386. return
  4387. }
  4388. } else if err != nil {
  4389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4390. return
  4391. }
  4392. }
  4393. dialysisRecord := &models.DialysisOrder{
  4394. ID: record_id,
  4395. UserOrgId: adminUserInfo.Org.Id,
  4396. BedID: bedID,
  4397. StartNurse: nurseID,
  4398. StartTime: startDate.Unix(),
  4399. PunctureNurse: puncture_nurse,
  4400. Creator: adminUserInfo.AdminUser.Id,
  4401. Modifier: adminUserInfo.AdminUser.Id,
  4402. WashpipeNurse: washpipe_nurse,
  4403. SchedualType: schedual_type,
  4404. ChangeNurse: change_nurse,
  4405. DifficultPunctureNurse: difficult_puncture_nurse,
  4406. NewFistulaNurse: new_fistula_nurse,
  4407. QualityNurseId: quality_nurse_id,
  4408. PunctureNeedle: puncture_needle,
  4409. PunctureWay: puncture_way,
  4410. DialysisDialyszers: dialysis_dialyszers,
  4411. DialysisIrrigation: dialysis_irrigation,
  4412. BloodAccessId: blood_access_id,
  4413. NucleinDate: theNucleinDate,
  4414. OrderRemark: order_remark,
  4415. ScheduleRemark: schedule_remark,
  4416. CatheterOperation: catheter_operation,
  4417. BloodFlowVolume: blood_flow_volume,
  4418. BloodDrawing: blood_drawing,
  4419. DialysisStrainer: dialysis_strainer,
  4420. }
  4421. //修改床位号需要重新消毒
  4422. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4423. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4424. //查询第一条监测
  4425. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4426. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4427. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4428. redis := service.RedisClient()
  4429. //清空key 值
  4430. redis.Set(key, "", time.Second)
  4431. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4432. redis.Set(keyOne, "", time.Second)
  4433. defer redis.Close()
  4434. }
  4435. // 查询信息规挡的设置天数
  4436. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4437. if infor.ID > 0 && infor.WeekDay > 0 {
  4438. var cha_time int64
  4439. timeNowStr := time.Now().Format("2006-01-02")
  4440. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4441. //今日的日期减去设置的日期
  4442. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4443. if cha_time >= record_date {
  4444. //查询审核是否允许
  4445. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4446. //申请状态不允许的情况 拒绝修改
  4447. if infor.ApplicationStatus != 1 {
  4448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4449. return
  4450. }
  4451. }
  4452. }
  4453. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4454. //修改床位后重新生成消毒计划
  4455. if adminUserInfo.Org.Id == 10340 {
  4456. //根据床位号获取设备型号
  4457. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4458. //查询使用消毒最后一条消毒记录
  4459. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4460. fmt.Println("err", err)
  4461. if err == gorm.ErrRecordNotFound {
  4462. //查找排班
  4463. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4464. //查询改设备是否有消毒计划
  4465. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4466. //根据床位号获取设备id
  4467. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4468. //查询病人信息
  4469. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4470. var con = ""
  4471. if patients.IsInfectious == 0 {
  4472. con = ""
  4473. }
  4474. if patients.IsInfectious == 1 {
  4475. con = "无"
  4476. }
  4477. if patients.IsInfectious == 2 {
  4478. con = "有"
  4479. }
  4480. if errcode == nil {
  4481. var end_time int64
  4482. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4483. //新增消毒
  4484. information := models.DeviceInformation{
  4485. Date: dialysisRecord.DialysisDate,
  4486. Zone: dialysisRecord.ZoneId,
  4487. Class: dialysisRecord.SchedualType,
  4488. BedNumber: dialysisRecord.BedID,
  4489. PatientId: dialysisRecord.PatientId,
  4490. DialysisMode: scheduleByPatient.ModeId,
  4491. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4492. Disinfection: 1,
  4493. DialysisConcentration: 1,
  4494. DisinfectionStatus: 1,
  4495. Move: 1,
  4496. UserOrgId: dialysisRecord.UserOrgId,
  4497. DisinfectType: plan.Way,
  4498. DisinfectantType: plan.MachineDisinfectant,
  4499. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4500. Disinfectant: plan.Disinfectant,
  4501. Ctime: time.Now().Unix(),
  4502. Status: 1,
  4503. SignName: nurseID,
  4504. EquimentId: addmacher.ID,
  4505. DisinfectionResidue: 2,
  4506. Bed: addmacher.BedNumber,
  4507. StartTime: dialysisRecord.StartTime,
  4508. EndTime: dialysisRecord.EndTime,
  4509. Contagion: con,
  4510. WeightLoss: 0,
  4511. Hyperfiltratio: 0,
  4512. DialysisHour: "",
  4513. MachineRun: 1,
  4514. DisinfecStartime: dialysisRecord.EndTime,
  4515. DisinfecEndtime: end_time,
  4516. }
  4517. err := service.CreateInformationTwo(&information)
  4518. fmt.Println("报错", err)
  4519. }
  4520. }
  4521. }
  4522. order, _ := service.GetLastPatientOrder(record_id)
  4523. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4524. redis := service.RedisClient()
  4525. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4526. redis.Set(key, "", time.Second)
  4527. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4528. //清空key 值
  4529. redis.Set(keyOne, "", time.Second)
  4530. scheduleDateStartOne := startDate.Format("2006-01-02")
  4531. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4532. redis.Set(keyTwo, "", time.Second)
  4533. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4534. redis.Set(keyThree, "", time.Second)
  4535. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4536. redis.Set(keyFour, "", time.Second)
  4537. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4538. redis.Set(keyFive, "", time.Second)
  4539. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4540. redis.Set(keySix, "", time.Second)
  4541. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4542. redis.Set(keySeven, "", time.Second)
  4543. if updateErr != nil {
  4544. this.ErrorLog("修改上机失败:%v", updateErr)
  4545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4546. return
  4547. }
  4548. if updateErr == nil {
  4549. if tempDialysisRecord.Stage == 2 {
  4550. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4551. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4552. fmt.Println(value)
  4553. a, b := math.Modf(value)
  4554. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4555. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4556. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4557. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4558. redis := service.RedisClient()
  4559. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4560. redis.Set(key, "", time.Second)
  4561. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4562. redis.Set(keyOne, "", time.Second)
  4563. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4564. //清空key 值
  4565. redis.Set(keySix, "", time.Second)
  4566. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4567. redis.Set(keySeven, "", time.Second)
  4568. redis.Close()
  4569. if updateAssessmentErr != nil {
  4570. utils.ErrorLog("%v", updateAssessmentErr)
  4571. }
  4572. }
  4573. }
  4574. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4575. this.ServeSuccessJSON(map[string]interface{}{
  4576. "dialysis_order": dialysisRecords,
  4577. })
  4578. }
  4579. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4580. record_id, _ := c.GetInt64("id")
  4581. nurseID, _ := c.GetInt64("nurse")
  4582. end_time := c.GetString("end_time")
  4583. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4584. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4585. catheter := c.GetString("catheter")
  4586. cruor := c.GetString("cruor")
  4587. mission := c.GetString("mission")
  4588. condenser := c.GetString("condenser")
  4589. if record_id <= 0 || nurseID <= 0 {
  4590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4591. return
  4592. }
  4593. adminUserInfo := c.GetMobileAdminUserInfo()
  4594. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4595. if getNurseErr != nil {
  4596. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4598. return
  4599. } else if nurse == nil {
  4600. c.ErrorLog("护士不存在")
  4601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4602. return
  4603. }
  4604. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4605. if parseEndDateErr != nil {
  4606. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4608. return
  4609. }
  4610. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4611. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4612. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4613. // if getPermissionErr != nil {
  4614. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4615. // return
  4616. // } else if headNursePermission == nil {
  4617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4618. // return
  4619. // }
  4620. //}
  4621. // 查询信息规挡的设置天数
  4622. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4623. if infor.ID > 0 {
  4624. var cha_time int64
  4625. timeNowStr := time.Now().Format("2006-01-02")
  4626. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4627. //今日的日期减去设置的日期
  4628. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4629. if cha_time >= tempDialysisRecords.DialysisDate {
  4630. //查询审核是否允许
  4631. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4632. //申请状态不允许的情况 拒绝修改
  4633. if infor.ApplicationStatus != 1 {
  4634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4635. return
  4636. }
  4637. }
  4638. }
  4639. dialysisRecord := &models.DialysisOrder{
  4640. ID: record_id,
  4641. UserOrgId: adminUserInfo.Org.Id,
  4642. EndTime: endDate.Unix(),
  4643. FinishNurse: nurseID,
  4644. FinishModifier: adminUserInfo.AdminUser.Id,
  4645. PuncturePointHaematoma: puncture_point_haematoma,
  4646. BloodAccessInternalFistula: blood_access_internal_fistula,
  4647. Catheter: catheter,
  4648. Cruor: cruor,
  4649. Mission: mission,
  4650. Condenser: condenser,
  4651. }
  4652. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4653. redis := service.RedisClient()
  4654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4655. //清空key 值
  4656. redis.Set(key, "", time.Second)
  4657. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4658. //清空key 值
  4659. redis.Set(keyOne, "", time.Second)
  4660. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4661. redis.Set(keySeven, "", time.Second)
  4662. redis.Close()
  4663. if updateErr != nil {
  4664. c.ErrorLog("修改下机失败:%v", updateErr)
  4665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4666. return
  4667. }
  4668. if updateErr == nil {
  4669. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4670. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4671. a, b := math.Modf(value)
  4672. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4673. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4674. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4675. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4676. redis := service.RedisClient()
  4677. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4678. redis.Set(keyTen, "", time.Second)
  4679. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4680. redis.Set(keyTwo, "", time.Second)
  4681. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4682. redis.Set(key, "", time.Second)
  4683. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4684. redis.Set(keyThree, "", time.Second)
  4685. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4686. redis.Set(keySeven, "", time.Second)
  4687. defer redis.Close()
  4688. if updateAssessmentErr != nil {
  4689. utils.ErrorLog("%v", updateAssessmentErr)
  4690. }
  4691. }
  4692. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4693. c.ServeSuccessJSON(map[string]interface{}{
  4694. "dialysis_order": dialysisRecords,
  4695. })
  4696. }
  4697. func (c *DialysisAPIController) GetLongAdvice() {
  4698. patient_id, _ := c.GetInt64("id")
  4699. adminUserInfo := c.GetMobileAdminUserInfo()
  4700. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4701. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4702. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4703. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4704. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4705. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4706. c.ServeSuccessJSON(map[string]interface{}{
  4707. "status": "1",
  4708. })
  4709. return
  4710. } else { //开启推送提醒
  4711. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4712. var advice_three []*models.DoctorAdvice
  4713. recordDateStr := time.Now().Format("2006-01-02")
  4714. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4715. nowtime := recordDate.Unix()
  4716. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4717. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4718. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4719. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4720. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4721. for _, advice := range advices {
  4722. if advice.FrequencyType == 3 {
  4723. t := time.Now()
  4724. week := int(t.Weekday())
  4725. fmt.Println(t.Weekday())
  4726. fmt.Println(week)
  4727. switch week {
  4728. case 1:
  4729. if strings.Index(advice.WeekDay, "周一") == -1 {
  4730. advice_three = append(advice_three, advice)
  4731. }
  4732. break
  4733. case 2:
  4734. if strings.Index(advice.WeekDay, "周二") == -1 {
  4735. advice_three = append(advice_three, advice)
  4736. }
  4737. break
  4738. case 3:
  4739. if strings.Index(advice.WeekDay, "周三") == -1 {
  4740. advice_three = append(advice_three, advice)
  4741. }
  4742. break
  4743. case 4:
  4744. if strings.Index(advice.WeekDay, "周四") == -1 {
  4745. advice_three = append(advice_three, advice)
  4746. }
  4747. break
  4748. case 5:
  4749. if strings.Index(advice.WeekDay, "周五") == -1 {
  4750. advice_three = append(advice_three, advice)
  4751. }
  4752. break
  4753. case 6:
  4754. if strings.Index(advice.WeekDay, "周六") == -1 {
  4755. advice_three = append(advice_three, advice)
  4756. }
  4757. break
  4758. case 0:
  4759. if strings.Index(advice.WeekDay, "周日") == -1 {
  4760. advice_three = append(advice_three, advice)
  4761. }
  4762. break
  4763. }
  4764. }
  4765. }
  4766. for _, advice := range advices_two {
  4767. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4768. now := p.Unix()
  4769. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4770. dayStr2 := "-" + dayStr
  4771. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4772. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4773. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4774. for _, ad := range advices {
  4775. advice_three = append(advice_three, ad)
  4776. }
  4777. }
  4778. if err == nil {
  4779. c.ServeSuccessJSON(map[string]interface{}{
  4780. "status": "2",
  4781. "advices": advices,
  4782. "advices_two": RemoveRepeatedElement(advice_three),
  4783. "is_open_remind": config.IsOpenRemind,
  4784. "his_config_open": hisConfig.IsOpen,
  4785. "is_advice_open": is_advice_open.IsAdviceOpen,
  4786. "prescription_open": prescription_open.IsOpen,
  4787. })
  4788. }
  4789. }
  4790. }
  4791. func (c *DialysisAPIController) GetLongAdviceOne() {
  4792. patient_id, _ := c.GetInt64("id")
  4793. startTime := c.GetString("schedule_date")
  4794. timeLayout := "2006-01-02"
  4795. loc, _ := time.LoadLocation("Local")
  4796. var theStartTime int64
  4797. if len(startTime) > 0 {
  4798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4799. if err != nil {
  4800. utils.ErrorLog(err.Error())
  4801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4802. return
  4803. }
  4804. theStartTime = theTime.Unix()
  4805. }
  4806. adminUserInfo := c.GetMobileAdminUserInfo()
  4807. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4808. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4809. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4810. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4811. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4812. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4813. c.ServeSuccessJSON(map[string]interface{}{
  4814. "status": "1",
  4815. })
  4816. return
  4817. } else { //开启推送提醒
  4818. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4819. var advice_three []*models.DoctorAdvice
  4820. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4821. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4822. for _, advice := range advices {
  4823. if advice.FrequencyType == 3 {
  4824. t := time.Now()
  4825. week := int(t.Weekday())
  4826. fmt.Println(t.Weekday())
  4827. fmt.Println(week)
  4828. switch week {
  4829. case 1:
  4830. if strings.Index(advice.WeekDay, "周一") == -1 {
  4831. advice_three = append(advice_three, advice)
  4832. }
  4833. break
  4834. case 2:
  4835. if strings.Index(advice.WeekDay, "周二") == -1 {
  4836. advice_three = append(advice_three, advice)
  4837. }
  4838. break
  4839. case 3:
  4840. if strings.Index(advice.WeekDay, "周三") == -1 {
  4841. advice_three = append(advice_three, advice)
  4842. }
  4843. break
  4844. case 4:
  4845. if strings.Index(advice.WeekDay, "周四") == -1 {
  4846. advice_three = append(advice_three, advice)
  4847. }
  4848. break
  4849. case 5:
  4850. if strings.Index(advice.WeekDay, "周五") == -1 {
  4851. advice_three = append(advice_three, advice)
  4852. }
  4853. break
  4854. case 6:
  4855. if strings.Index(advice.WeekDay, "周六") == -1 {
  4856. advice_three = append(advice_three, advice)
  4857. }
  4858. break
  4859. case 0:
  4860. if strings.Index(advice.WeekDay, "周日") == -1 {
  4861. advice_three = append(advice_three, advice)
  4862. }
  4863. break
  4864. }
  4865. }
  4866. }
  4867. for _, advice := range advices_two {
  4868. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4869. now := p.Unix()
  4870. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4871. dayStr2 := "-" + dayStr
  4872. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4873. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4874. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4875. for _, ad := range advices {
  4876. advice_three = append(advice_three, ad)
  4877. }
  4878. }
  4879. if err == nil {
  4880. c.ServeSuccessJSON(map[string]interface{}{
  4881. "status": "2",
  4882. "advices": advices,
  4883. "advices_two": RemoveRepeatedElement(advice_three),
  4884. "is_open_remind": config.IsOpenRemind,
  4885. "his_config_open": hisConfig.IsOpen,
  4886. "is_advice_open": is_advice_open.IsAdviceOpen,
  4887. "prescription_open": prescription_open.IsOpen,
  4888. })
  4889. }
  4890. }
  4891. }
  4892. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4893. newArr = make([]*models.DoctorAdvice, 0)
  4894. for i := 0; i < len(arr); i++ {
  4895. repeat := false
  4896. for j := i + 1; j < len(arr); j++ {
  4897. if arr[i].ID == arr[j].ID {
  4898. repeat = true
  4899. break
  4900. }
  4901. }
  4902. if !repeat {
  4903. newArr = append(newArr, arr[i])
  4904. }
  4905. }
  4906. return
  4907. }
  4908. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4909. patient, _ := c.GetInt64("id", 0)
  4910. groupNo, _ := c.GetInt64("groupno", 0)
  4911. if patient <= 0 {
  4912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4913. return
  4914. }
  4915. adminUserInfo := c.GetMobileAdminUserInfo()
  4916. dataBody := make(map[string]interface{}, 0)
  4917. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4918. if err != nil {
  4919. utils.ErrorLog(err.Error())
  4920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4921. return
  4922. }
  4923. utils.ErrorLog("%v", dataBody)
  4924. timeLayout := "2006-01-02 15:04"
  4925. loc, _ := time.LoadLocation("Local")
  4926. timeLayout2 := "2006-01-02"
  4927. loc2, _ := time.LoadLocation("Local")
  4928. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4929. utils.ErrorLog("advice_type")
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. adviceType := int64(2)
  4934. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4935. utils.ErrorLog("advice_date")
  4936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4937. return
  4938. }
  4939. adviceDate, _ := dataBody["advice_date"].(string)
  4940. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4941. AdviceDate := theTime.Unix()
  4942. RecordDate := theTime.Unix()
  4943. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4944. utils.ErrorLog("start_time")
  4945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4946. return
  4947. }
  4948. startTime, _ := dataBody["start_time"].(string)
  4949. if len(startTime) == 0 {
  4950. utils.ErrorLog("len(start_time) == 0")
  4951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4952. return
  4953. }
  4954. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4955. if err != nil {
  4956. utils.ErrorLog(err.Error())
  4957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4958. return
  4959. }
  4960. StartTime := theTime.Unix()
  4961. Remark := ""
  4962. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4963. remark, _ := dataBody["remark"].(string)
  4964. Remark = remark
  4965. }
  4966. var advices []*models.GroupAdvice
  4967. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4968. utils.ErrorLog("advices")
  4969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4970. return
  4971. }
  4972. adviceNames := dataBody["advices"].([]interface{})
  4973. for _, adviceNameMap := range adviceNames {
  4974. adviceNameM := adviceNameMap.(map[string]interface{})
  4975. var advice models.GroupAdvice
  4976. advice.Remark = Remark
  4977. advice.AdviceType = adviceType
  4978. advice.StartTime = StartTime
  4979. advice.AdviceDate = AdviceDate
  4980. advice.RecordDate = RecordDate
  4981. advice.Status = 1
  4982. advice.CreatedTime = time.Now().Unix()
  4983. advice.UpdatedTime = time.Now().Unix()
  4984. advice.StopState = 2
  4985. advice.ExecutionState = 2
  4986. advice.UserOrgId = adminUserInfo.Org.Id
  4987. advice.PatientId = patient
  4988. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4989. advice.IsSettle = 2
  4990. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4991. utils.ErrorLog("advice_name")
  4992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4993. return
  4994. }
  4995. adviceName, _ := adviceNameM["advice_name"].(string)
  4996. if len(adviceName) == 0 {
  4997. utils.ErrorLog("len(advice_name) == 0")
  4998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4999. return
  5000. }
  5001. advice.AdviceName = adviceName
  5002. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5003. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5004. advice.DrugSpec = drugSpec
  5005. }
  5006. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5007. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5008. advice.AdviceDesc = adviceDesc
  5009. }
  5010. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5011. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5012. advice.DrugSpecUnit = drugSpecUnit
  5013. }
  5014. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5015. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5016. // advice.SingleDose = singleDose
  5017. //}
  5018. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5019. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5020. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5021. }
  5022. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5023. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5024. advice.SingleDoseUnit = singleDoseUnit
  5025. }
  5026. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5027. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5028. // advice.PrescribingNumber = prescribingNumber
  5029. //}
  5030. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5031. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5032. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5033. }
  5034. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5035. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5036. advice.PrescribingNumberUnit = prescribingNumberUnit
  5037. }
  5038. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5039. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5040. advice.DeliveryWay = deliveryWay
  5041. }
  5042. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5043. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5044. advice.ExecutionFrequency = executionFrequency
  5045. }
  5046. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5047. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5048. advice.FrequencyType = frequency_type
  5049. }
  5050. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5051. day_count := int64(adviceNameM["day_count"].(float64))
  5052. advice.DayCount = day_count
  5053. }
  5054. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5055. week_day, _ := adviceNameM["week_day"].(string)
  5056. advice.WeekDay = week_day
  5057. }
  5058. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5059. way := int64(adviceNameM["way"].(float64))
  5060. advice.Way = way
  5061. }
  5062. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5063. drug_id := int64(adviceNameM["drug_id"].(float64))
  5064. advice.DrugId = drug_id
  5065. }
  5066. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5067. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5068. advice.DrugNameId = drug_name_id
  5069. }
  5070. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5071. remark, _ := adviceNameM["remark"].(string)
  5072. advice.Remark = remark
  5073. }
  5074. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5075. groupno := int64(adviceNameM["groupno"].(float64))
  5076. advice.GroupNo = groupno
  5077. }
  5078. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5079. template_id, _ := adviceNameM["template_id"].(string)
  5080. advice.TemplateId = template_id
  5081. }
  5082. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5083. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5084. advice.ExecutionFrequency = executionFrequency
  5085. }
  5086. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5087. children := adviceNameM["child"].([]interface{})
  5088. if len(children) > 0 {
  5089. for _, childrenMap := range children {
  5090. childMap := childrenMap.(map[string]interface{})
  5091. var child models.GroupAdvice
  5092. child.Remark = Remark
  5093. child.AdviceType = adviceType
  5094. child.StartTime = StartTime
  5095. child.AdviceDate = AdviceDate
  5096. child.RecordDate = RecordDate
  5097. child.Status = 1
  5098. child.CreatedTime = time.Now().Unix()
  5099. child.UpdatedTime = time.Now().Unix()
  5100. child.StopState = 2
  5101. child.ExecutionState = 2
  5102. child.UserOrgId = adminUserInfo.Org.Id
  5103. child.PatientId = patient
  5104. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5105. child.IsSettle = 1
  5106. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5107. utils.ErrorLog("child advice_name")
  5108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5109. return
  5110. }
  5111. childAdviceName, _ := childMap["advice_name"].(string)
  5112. if len(childAdviceName) == 0 {
  5113. utils.ErrorLog("len(child advice_name) == 0")
  5114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5115. return
  5116. }
  5117. child.AdviceName = childAdviceName
  5118. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5119. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5120. child.AdviceDesc = childAdviceDesc
  5121. }
  5122. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5123. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5124. child.DrugSpec = childDrugSpec
  5125. }
  5126. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5127. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5128. child.DrugSpecUnit = childDrugSpecUnit
  5129. }
  5130. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5131. child.SingleDose = childMap["single_dose"].(float64)
  5132. }
  5133. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5134. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5135. child.SingleDoseUnit = childSingleDoseUnit
  5136. }
  5137. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5138. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5139. }
  5140. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5141. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5142. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5143. }
  5144. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5145. groupno := int64(childMap["groupno"].(float64))
  5146. advice.GroupNo = groupno
  5147. }
  5148. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5149. remark, _ := childMap["remark"].(string)
  5150. child.Remark = remark
  5151. }
  5152. child.DeliveryWay = advice.DeliveryWay
  5153. child.ExecutionFrequency = advice.ExecutionFrequency
  5154. advice.Children = append(advice.Children, &child)
  5155. }
  5156. }
  5157. }
  5158. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5159. if temp_advice.ID == 0 {
  5160. advices = append(advices, &advice)
  5161. }
  5162. }
  5163. if len(advices) > 0 {
  5164. finish := models.XtDialysisFinish{
  5165. IsFinish: 1,
  5166. UserOrgId: adminUserInfo.Org.Id,
  5167. Status: 1,
  5168. Ctime: time.Now().Unix(),
  5169. Mtime: 0,
  5170. Module: 4,
  5171. RecordDate: AdviceDate,
  5172. Sourse: 1,
  5173. PatientId: patient,
  5174. }
  5175. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5176. if dialysisFinish.ID == 0 {
  5177. service.CreateDialysisFinish(finish)
  5178. }
  5179. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5180. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5181. for _, item := range advices {
  5182. byterequest, _ := json.Marshal(item)
  5183. adviceLog := models.XtDoctorAdviceLog{
  5184. UserOrgId: adminUserInfo.Org.Id,
  5185. PatientId: patient,
  5186. AdminUserId: adminUserInfo.AdminUser.Id,
  5187. Module: 1,
  5188. ErrLog: string(byterequest),
  5189. Status: 1,
  5190. Ctime: time.Now().Unix(),
  5191. Mtime: 0,
  5192. Source: "手机端医嘱推送",
  5193. RecordDate: item.AdviceDate,
  5194. }
  5195. service.CreateDoctorAdviceLog(adviceLog)
  5196. }
  5197. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5198. redis := service.RedisClient()
  5199. //清空key 值
  5200. redis.Set(key, "", time.Second)
  5201. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5202. redis.Set(keyOne, "", time.Second)
  5203. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5204. defer redis.Close()
  5205. redis.Set(keyThree, "", time.Second)
  5206. if err != nil {
  5207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5208. return
  5209. }
  5210. c.ServeSuccessJSON(map[string]interface{}{
  5211. "msg": "ok",
  5212. "advices": list,
  5213. })
  5214. } else {
  5215. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5216. for _, item := range advices {
  5217. byterequest, _ := json.Marshal(item)
  5218. adviceLog := models.XtDoctorAdviceLog{
  5219. UserOrgId: adminUserInfo.Org.Id,
  5220. PatientId: patient,
  5221. AdminUserId: adminUserInfo.AdminUser.Id,
  5222. Module: 1,
  5223. ErrLog: string(byterequest),
  5224. Status: 1,
  5225. Ctime: time.Now().Unix(),
  5226. Mtime: 0,
  5227. Source: "手机端医嘱推送",
  5228. RecordDate: item.AdviceDate,
  5229. }
  5230. service.CreateDoctorAdviceLog(adviceLog)
  5231. }
  5232. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5233. redis := service.RedisClient()
  5234. //清空key 值
  5235. redis.Set(key, "", time.Second)
  5236. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5237. redis.Set(keyOne, "", time.Second)
  5238. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5239. defer redis.Close()
  5240. redis.Set(keyThree, "", time.Second)
  5241. if err != nil {
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5243. return
  5244. }
  5245. c.ServeSuccessJSON(map[string]interface{}{
  5246. "msg": "ok",
  5247. "advices": list,
  5248. })
  5249. }
  5250. } else {
  5251. c.ServeSuccessJSON(map[string]interface{}{
  5252. "msg": "ok",
  5253. })
  5254. }
  5255. return
  5256. }
  5257. func (c *DialysisAPIController) UploadDryWeight() {
  5258. patient_id, _ := c.GetInt64("id")
  5259. dry_weight, _ := c.GetFloat("dry_weight")
  5260. doctor_id, _ := c.GetInt64("doctor_id")
  5261. remark := c.GetString("remark")
  5262. adminUserInfo := c.GetMobileAdminUserInfo()
  5263. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5264. if err == gorm.ErrRecordNotFound {
  5265. dryWeight := &models.SgjPatientDryweight{
  5266. PatientId: patient_id,
  5267. DryWeight: dry_weight,
  5268. Remakes: remark,
  5269. Ctime: time.Now().Unix(),
  5270. Mtime: time.Now().Unix(),
  5271. Creator: doctor_id,
  5272. Status: 1,
  5273. UserOrgId: adminUserInfo.Org.Id,
  5274. AdjustedValue: "/",
  5275. UserId: adminUserInfo.AdminUser.Id,
  5276. }
  5277. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5278. redis := service.RedisClient()
  5279. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5280. redis.Set(keyOne, "", time.Second)
  5281. loc, _ := time.LoadLocation("Local")
  5282. nowTime := time.Now()
  5283. nowDay := nowTime.Format("2006-01-02")
  5284. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5286. redis.Set(key, "", time.Second)
  5287. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5288. redis.Set(keyTwo, "", time.Second)
  5289. redis.Close()
  5290. if createErr == nil {
  5291. c.ServeSuccessJSON(map[string]interface{}{
  5292. "msg": "提交成功",
  5293. "weight": dryWeight,
  5294. })
  5295. }
  5296. } else {
  5297. dryWeight := &models.SgjPatientDryweight{
  5298. PatientId: patient_id,
  5299. DryWeight: dry_weight,
  5300. Remakes: remark,
  5301. Ctime: time.Now().Unix(),
  5302. Mtime: time.Now().Unix(),
  5303. Creator: doctor_id,
  5304. Status: 1,
  5305. UserOrgId: adminUserInfo.Org.Id,
  5306. AdjustedValue: "/",
  5307. UserId: adminUserInfo.AdminUser.Id,
  5308. }
  5309. var value float64
  5310. value = dry_weight - weightAdjust.DryWeight
  5311. if value < 0 {
  5312. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5313. } else if value == 0 {
  5314. dryWeight.AdjustedValue = "/"
  5315. } else if value > 0 {
  5316. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5317. }
  5318. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5319. //康桥
  5320. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5321. timeNowStr := time.Now().Format("2006-01-02")
  5322. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5323. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5324. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5325. if beforAssesment.ID > 0 {
  5326. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5327. var dewater_amount float64
  5328. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5329. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5330. //获取key,清空redis
  5331. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5332. redis := service.RedisClient()
  5333. //清空key 值
  5334. redis.Set(key, "", time.Second)
  5335. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5336. //清空key 值
  5337. redis.Set(keyOne, "", time.Second)
  5338. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5339. //清空key 值
  5340. redis.Set(keyTwo, "", time.Second)
  5341. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5342. redis.Set(keySix, "", time.Second)
  5343. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5344. redis.Set(keySeven, "", time.Second)
  5345. }
  5346. }
  5347. redis := service.RedisClient()
  5348. loc, _ := time.LoadLocation("Local")
  5349. nowTime := time.Now()
  5350. nowDay := nowTime.Format("2006-01-02")
  5351. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5352. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5353. redis.Set(keyOne, "", time.Second)
  5354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5355. redis.Set(key, "", time.Second)
  5356. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5357. redis.Set(keyTwo, "", time.Second)
  5358. redis.Close()
  5359. if createErr == nil {
  5360. c.ServeSuccessJSON(map[string]interface{}{
  5361. "msg": "提交成功",
  5362. "weight": dryWeight,
  5363. })
  5364. }
  5365. }
  5366. }
  5367. func (c *DialysisAPIController) GetSolution() {
  5368. patient_id, _ := c.GetInt64("patient_id")
  5369. mode_id, _ := c.GetInt64("mode_id")
  5370. adminUserInfo := c.GetMobileAdminUserInfo()
  5371. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5372. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5373. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5374. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5375. if err != nil {
  5376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5377. return
  5378. }
  5379. c.ServeSuccessJSON(map[string]interface{}{
  5380. "solution": solution,
  5381. "prescription": prescription,
  5382. "system_prescription": system_prescription,
  5383. "dialysisPrescription": dialysisPrescription,
  5384. })
  5385. }
  5386. func (c *DialysisAPIController) GetSchedule() {
  5387. schedual_type, _ := c.GetInt64("schedual_type")
  5388. adminUserInfo := c.GetMobileAdminUserInfo()
  5389. scheduleTime, _ := c.GetInt64("record_date")
  5390. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5391. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5392. c.ServeSuccessJSON(map[string]interface{}{
  5393. "number": deviceNumber,
  5394. "list": list,
  5395. })
  5396. }
  5397. func (c *DialysisAPIController) GetPatientId() {
  5398. id, _ := c.GetInt64("id")
  5399. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5400. patientId, _ := service.GetPatientId(id)
  5401. //获取该患者的所有传染病
  5402. list, _ := service.GetPatientInfectious(id)
  5403. c.ServeSuccessJSON(map[string]interface{}{
  5404. "patient": patientId,
  5405. "infectioulist": list,
  5406. })
  5407. }
  5408. func (this *DialysisAPIController) GetDialysisSchedule() {
  5409. schedualDate := this.GetString("date")
  5410. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5411. if parseDateErr != nil {
  5412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5413. return
  5414. }
  5415. adminInfo := this.GetMobileAdminUserInfo()
  5416. orgID := adminInfo.Org.Id
  5417. redis := service.RedisClient()
  5418. defer redis.Close()
  5419. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5420. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5421. if len(scheduals) > 0 {
  5422. //缓存数据
  5423. scheduals_json, err := json.Marshal(scheduals)
  5424. if err == nil {
  5425. redis.Set(key, scheduals_json, time.Second*30)
  5426. }
  5427. }
  5428. this.ServeSuccessJSON(map[string]interface{}{
  5429. "scheduals": scheduals,
  5430. })
  5431. }
  5432. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5433. change_type, _ := this.GetInt64("type", 0)
  5434. record_date := this.GetString("record_time")
  5435. patient_id, _ := this.GetInt64("patient_id", 0)
  5436. timeLayout := "2006-01-02"
  5437. loc, _ := time.LoadLocation("Local")
  5438. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5439. record_time := theAdviceRecordTime.Unix()
  5440. adminUserInfo := this.GetMobileAdminUserInfo()
  5441. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5442. if err == nil {
  5443. if len(advices) == 0 {
  5444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5445. return
  5446. } else {
  5447. this.ServeSuccessJSON(map[string]interface{}{
  5448. "advices": advices,
  5449. "schedule": sch,
  5450. })
  5451. return
  5452. }
  5453. } else {
  5454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5455. return
  5456. }
  5457. }
  5458. func (c *DialysisAPIController) CreateConsumables() {
  5459. record_date := c.GetString("record_time")
  5460. patient_id, _ := c.GetInt64("patient_id", 0)
  5461. active, _ := c.GetInt64("active")
  5462. adminUser := c.GetMobileAdminUserInfo()
  5463. timeLayout := "2006-01-02"
  5464. loc, _ := time.LoadLocation("Local")
  5465. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5466. record_time := theRecordTime.Unix()
  5467. // 查询信息规挡的设置天数
  5468. orgid := c.GetMobileAdminUserInfo().Org.Id
  5469. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5470. if infor.ID > 0 {
  5471. var cha_time int64
  5472. timeNowStr := time.Now().Format("2006-01-02")
  5473. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5474. //今日的日期减去设置的日期
  5475. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5476. if cha_time >= record_time {
  5477. //查询审核是否允许
  5478. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5479. //申请状态不允许的情况 拒绝修改
  5480. if infor.ApplicationStatus != 1 {
  5481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5482. return
  5483. }
  5484. }
  5485. }
  5486. dataBody := make(map[string]interface{}, 0)
  5487. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5488. if err != nil {
  5489. utils.ErrorLog(err.Error())
  5490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5491. return
  5492. }
  5493. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5494. var beforePrepares []*models.DialysisBeforePrepareGoods
  5495. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5496. var dialysisBefor []*models.DialysisBeforePrepare
  5497. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5498. goods, _ := dataBody["goods"].([]interface{})
  5499. if len(goods) > 0 {
  5500. for _, item := range goods {
  5501. items := item.(map[string]interface{})
  5502. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5503. utils.ErrorLog("good_id")
  5504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5505. return
  5506. }
  5507. good_id := int64(items["good_id"].(float64))
  5508. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5509. utils.ErrorLog("good_type_id")
  5510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5511. return
  5512. }
  5513. good_type_id := int64(items["good_type_id"].(float64))
  5514. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5515. utils.ErrorLog("count")
  5516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5517. return
  5518. }
  5519. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5520. commdity_code := items["commdity_code"].(string)
  5521. fmt.Println("commdity", commdity_code)
  5522. prepareGoods := &models.DialysisBeforePrepareGoods{
  5523. GoodTypeId: good_type_id,
  5524. GoodId: good_id,
  5525. Count: count,
  5526. StorehouseId: houseConfig.StorehouseOutInfo,
  5527. }
  5528. beforePrepares = append(beforePrepares, prepareGoods)
  5529. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5530. GoodTypeId: good_type_id,
  5531. GoodId: good_id,
  5532. Count: count,
  5533. StorehouseId: houseConfig.StorehouseOutInfo,
  5534. }
  5535. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5536. prepare := &models.DialysisBeforePrepare{
  5537. GoodTypeId: good_type_id,
  5538. GoodId: good_id,
  5539. Count: count,
  5540. PatientId: patient_id,
  5541. RecordDate: record_time,
  5542. UserOrgId: adminUser.Org.Id,
  5543. Status: 1,
  5544. Ctime: time.Now().Unix(),
  5545. Creater: adminUser.AdminUser.Id,
  5546. CommdityCode: commdity_code,
  5547. StorehouseId: houseConfig.StorehouseOutInfo,
  5548. }
  5549. dialysisBefor = append(dialysisBefor, prepare)
  5550. }
  5551. }
  5552. //查询是否有库存
  5553. for _, item := range dialysisBefor {
  5554. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5555. if err == gorm.ErrRecordNotFound {
  5556. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5557. c.ServeSuccessJSON(map[string]interface{}{
  5558. "message": "1",
  5559. "good_name": goodObj.GoodName,
  5560. "specification_name": goodObj.SpecificationName,
  5561. })
  5562. return
  5563. }
  5564. if err != nil {
  5565. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5566. c.ServeSuccessJSON(map[string]interface{}{
  5567. "message": "1",
  5568. "good_name": goodObj.GoodName,
  5569. "specification_name": goodObj.SpecificationName,
  5570. })
  5571. return
  5572. }
  5573. }
  5574. fmt.Println("active-----------------------", active)
  5575. fmt.Println("len(goods)-----------------------", len(goods))
  5576. //新增
  5577. if active == 1 && len(goods) > 0 {
  5578. for _, item := range dialysisBefor {
  5579. dialyPrepareOne := models.DialysisBeforePrepare{
  5580. GoodTypeId: item.GoodTypeId,
  5581. GoodId: item.GoodId,
  5582. PatientId: item.PatientId,
  5583. RecordDate: item.RecordDate,
  5584. UserOrgId: item.UserOrgId,
  5585. Count: item.Count,
  5586. Ctime: time.Now().Unix(),
  5587. Creater: item.Creater,
  5588. CommdityCode: item.CommdityCode,
  5589. Status: 1,
  5590. StorehouseId: houseConfig.StorehouseOutInfo,
  5591. }
  5592. //先清除再插入
  5593. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5594. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5595. //查询默认仓库
  5596. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5597. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5598. var total_count int64
  5599. for _, it := range stockList {
  5600. total_count += it.StockCount
  5601. }
  5602. //基础库插入数据
  5603. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5604. //更新库存
  5605. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5606. var flush_count int64
  5607. for _, it := range goodList {
  5608. flush_count += it.StockCount
  5609. }
  5610. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5611. }
  5612. if err == nil {
  5613. c.ServeSuccessJSON(map[string]interface{}{
  5614. "msg": "保存成功",
  5615. "message": "2",
  5616. })
  5617. return
  5618. } else {
  5619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5620. return
  5621. }
  5622. }
  5623. if len(beforePrepares) > 0 && active == 2 {
  5624. for _, item := range beforePrepares {
  5625. //1.查看该患者该耗材型号最后一次出库数量
  5626. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5627. //判断当前出库数量和最后一次出库数量的大小
  5628. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5629. if item.Count <= goodInfo.Count {
  5630. //退库
  5631. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5632. //查询今日出库数据
  5633. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5634. for _, it := range list {
  5635. prepare := models.DialysisBeforePrepare{
  5636. UserOrgId: it.OrgId,
  5637. PatientId: patient_id,
  5638. RecordDate: it.RecordTime,
  5639. GoodId: it.GoodId,
  5640. GoodTypeId: it.GoodTypeId,
  5641. Count: it.Count,
  5642. Ctime: time.Now().Unix(),
  5643. Creater: adminUser.AdminUser.Id,
  5644. Status: 1,
  5645. StorehouseId: houseConfig.StorehouseOutInfo,
  5646. }
  5647. //删除准备表数据
  5648. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5649. service.CreateDialysisBeforePrepareOne(&prepare)
  5650. }
  5651. }
  5652. var last_total int64
  5653. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5654. if item.Count >= goodInfo.Count {
  5655. //查询当前批次当前耗材最后一条出库数据
  5656. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5657. //计算当前出库和最后一次出库数据相差数据
  5658. last_total = item.Count - lastOutInfo.Count
  5659. //查询该批次剩余库存
  5660. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5661. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5662. if lastInfo.StockCount >= last_total {
  5663. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5664. //查询今日出库数据
  5665. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5666. for _, it := range list {
  5667. prepare := models.DialysisBeforePrepare{
  5668. UserOrgId: it.OrgId,
  5669. PatientId: patient_id,
  5670. RecordDate: it.RecordTime,
  5671. GoodId: it.GoodId,
  5672. GoodTypeId: it.GoodTypeId,
  5673. Count: it.Count,
  5674. Ctime: time.Now().Unix(),
  5675. Creater: adminUser.AdminUser.Id,
  5676. Status: 1,
  5677. StorehouseId: houseConfig.StorehouseOutInfo,
  5678. }
  5679. //删除准备表数据
  5680. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5681. service.CreateDialysisBeforePrepareOne(&prepare)
  5682. //查询默认仓库
  5683. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5684. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5685. var total_count int64
  5686. for _, it := range stockList {
  5687. total_count += it.StockCount
  5688. }
  5689. //基础库插入数据
  5690. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5691. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5692. var flush_count int64
  5693. for _, it := range goodList {
  5694. flush_count += it.StockCount
  5695. }
  5696. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5697. }
  5698. }
  5699. //如果库存不够,则出库到下一个批次
  5700. if lastInfo.StockCount < last_total {
  5701. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5702. //查询今日出库数据
  5703. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5704. for _, it := range list {
  5705. prepare := models.DialysisBeforePrepare{
  5706. UserOrgId: it.OrgId,
  5707. PatientId: patient_id,
  5708. RecordDate: it.RecordTime,
  5709. GoodId: it.GoodId,
  5710. GoodTypeId: it.GoodTypeId,
  5711. Count: it.Count,
  5712. Ctime: time.Now().Unix(),
  5713. Creater: adminUser.AdminUser.Id,
  5714. Status: 1,
  5715. StorehouseId: houseConfig.StorehouseOutInfo,
  5716. }
  5717. //删除准备表数据
  5718. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5719. service.CreateDialysisBeforePrepareOne(&prepare)
  5720. //查询默认仓库
  5721. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5722. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5723. var total_count int64
  5724. for _, it := range stockList {
  5725. total_count += it.StockCount
  5726. }
  5727. //基础库插入数据
  5728. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5729. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5730. var flush_count int64
  5731. for _, it := range goodList {
  5732. flush_count += it.StockCount
  5733. }
  5734. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5735. }
  5736. if err != nil {
  5737. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5738. c.ServeSuccessJSON(map[string]interface{}{
  5739. "message": "1",
  5740. "good_name": goodObj.GoodName,
  5741. "specification_name": goodObj.SpecificationName,
  5742. })
  5743. return
  5744. }
  5745. }
  5746. }
  5747. if err != nil {
  5748. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5749. c.ServeSuccessJSON(map[string]interface{}{
  5750. "message": "1",
  5751. "good_name": goodObj.GoodName,
  5752. "specification_name": goodObj.SpecificationName,
  5753. })
  5754. return
  5755. }
  5756. }
  5757. }
  5758. }
  5759. var errs error
  5760. if errs == nil {
  5761. c.ServeSuccessJSON(map[string]interface{}{
  5762. "msg": "提交成功",
  5763. "message": "2",
  5764. "good_name": "",
  5765. "specification_name": "",
  5766. })
  5767. return
  5768. } else {
  5769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5770. return
  5771. }
  5772. }
  5773. func (c *DialysisAPIController) CreateStockOutInfo() {
  5774. patient_id, _ := c.GetInt64("patient_id", 0)
  5775. record_date := c.GetString("record_time")
  5776. if patient_id <= 0 {
  5777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5778. return
  5779. }
  5780. adminInfo := c.GetMobileAdminUserInfo()
  5781. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5782. timeLayout := "2006-01-02"
  5783. loc, _ := time.LoadLocation("Local")
  5784. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5785. record_time := theRecordTime.Unix()
  5786. // 查询信息规挡的设置天数
  5787. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5788. if infor.ID > 0 && infor.WeekDay > 0 {
  5789. var cha_time int64
  5790. timeNowStr := time.Now().Format("2006-01-02")
  5791. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5792. //今日的日期减去设置的日期
  5793. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5794. if cha_time >= record_time {
  5795. //查询审核是否允许
  5796. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5797. //申请状态不允许的情况 拒绝修改
  5798. if infor.ApplicationStatus != 1 {
  5799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5800. return
  5801. }
  5802. }
  5803. }
  5804. //创建步骤表
  5805. finish := models.XtDialysisFinish{
  5806. IsFinish: 1,
  5807. UserOrgId: adminInfo.Org.Id,
  5808. Status: 1,
  5809. Ctime: time.Now().Unix(),
  5810. Mtime: 0,
  5811. Module: 11,
  5812. RecordDate: record_time,
  5813. Sourse: 1,
  5814. PatientId: patient_id,
  5815. }
  5816. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5817. if dialysisFinish.ID == 0 {
  5818. service.CreateDialysisFinish(finish)
  5819. }
  5820. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5821. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5822. //去重
  5823. consumables = RemoveRepeatedGood(consumables)
  5824. if adminInfo.Org.Id == 9919 {
  5825. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5826. //查询是否有库存
  5827. for _, item := range consumables {
  5828. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5829. if item.Count > warehouse.Count {
  5830. goodErrcode := models.XtGoodErrcode{
  5831. UserOrgId: item.UserOrgId,
  5832. Errcode: "自动出库库存不足",
  5833. GoodId: item.GoodId,
  5834. Status: 1,
  5835. Ctime: time.Now().Unix(),
  5836. Mtime: 0,
  5837. Count: 0,
  5838. StockCount: 0,
  5839. Creater: creator,
  5840. BatchNumberId: warehouse.ID,
  5841. WarehouseOutId: 0,
  5842. }
  5843. service.CreateGoodErrcode(goodErrcode)
  5844. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "message": "1",
  5847. "good_name": goodObj.GoodName,
  5848. "specification_name": goodObj.SpecificationName,
  5849. })
  5850. return
  5851. }
  5852. }
  5853. //查询是否有出库单
  5854. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5855. if err == gorm.ErrRecordNotFound {
  5856. //没有记录,则创建出库单
  5857. timeStr := time.Now().Format("2006-01-02")
  5858. timeArr := strings.Split(timeStr, "-")
  5859. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5860. total = total + 1
  5861. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5862. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5863. number = number + total
  5864. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5865. creater := adminInfo.AdminUser.Id
  5866. warehouseOut := models.WarehouseOut{
  5867. WarehouseOutOrderNumber: warehousing_out_order,
  5868. OperationTime: time.Now().Unix(),
  5869. OrgId: adminInfo.Org.Id,
  5870. Creater: creater,
  5871. Ctime: time.Now().Unix(),
  5872. Status: 1,
  5873. WarehouseOutTime: record_time,
  5874. Dealer: 0,
  5875. Manufacturer: 0,
  5876. Type: 1,
  5877. IsSys: 1,
  5878. StorehouseId: houseConfig.StorehouseOutInfo,
  5879. IsCheck: 1,
  5880. }
  5881. err := service.AddSigleWarehouseOut(&warehouseOut)
  5882. if err != nil {
  5883. goodErrcode := models.XtGoodErrcode{
  5884. UserOrgId: adminInfo.Org.Id,
  5885. Errcode: "创建出库单失败",
  5886. GoodId: 0,
  5887. Status: 1,
  5888. Ctime: time.Now().Unix(),
  5889. Mtime: 0,
  5890. Count: 0,
  5891. StockCount: 0,
  5892. Creater: creator,
  5893. BatchNumberId: 0,
  5894. WarehouseOutId: 0,
  5895. }
  5896. service.CreateGoodErrcode(goodErrcode)
  5897. utils.TraceLog("创建出库单失败 err = %v", err)
  5898. } else {
  5899. for _, item := range consumables {
  5900. //出库
  5901. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5902. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5903. if err == nil {
  5904. goodErrcode := models.XtGoodErrcode{
  5905. UserOrgId: adminInfo.Org.Id,
  5906. Errcode: "自动出库接口报错",
  5907. GoodId: 0,
  5908. Status: 1,
  5909. Ctime: time.Now().Unix(),
  5910. Mtime: 0,
  5911. Count: 0,
  5912. StockCount: 0,
  5913. Creater: creator,
  5914. BatchNumberId: 0,
  5915. WarehouseOutId: 0,
  5916. }
  5917. service.CreateGoodErrcode(goodErrcode)
  5918. utils.TraceLog("创建出库单失败 err = %v", err)
  5919. }
  5920. //查询
  5921. //出库数量相加
  5922. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5923. if errs != nil {
  5924. goodErrcode := models.XtGoodErrcode{
  5925. UserOrgId: item.UserOrgId,
  5926. Errcode: "创建剩余库存字段报错",
  5927. GoodId: item.GoodId,
  5928. Status: 1,
  5929. Ctime: time.Now().Unix(),
  5930. Mtime: 0,
  5931. Count: 0,
  5932. StockCount: 0,
  5933. Creater: creater,
  5934. BatchNumberId: 0,
  5935. WarehouseOutId: 0,
  5936. }
  5937. service.CreateGoodErrcode(goodErrcode)
  5938. }
  5939. }
  5940. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5941. if len(list) == 0 {
  5942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5943. return
  5944. }
  5945. for _, item := range list {
  5946. prepare := models.DialysisBeforePrepare{
  5947. UserOrgId: adminInfo.Org.Id,
  5948. PatientId: patient_id,
  5949. RecordDate: record_time,
  5950. GoodId: item.GoodId,
  5951. GoodTypeId: item.GoodTypeId,
  5952. Count: item.Count,
  5953. Creater: adminInfo.AdminUser.Id,
  5954. Status: 1,
  5955. Ctime: time.Now().Unix(),
  5956. StorehouseId: houseConfig.StorehouseOutInfo,
  5957. }
  5958. //清空准备表数据
  5959. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5960. if err != nil {
  5961. goodErrcode := models.XtGoodErrcode{
  5962. UserOrgId: item.OrgId,
  5963. Errcode: "自动出库清空准备表数据报错",
  5964. GoodId: item.GoodId,
  5965. Status: 1,
  5966. Ctime: time.Now().Unix(),
  5967. Mtime: 0,
  5968. Count: 0,
  5969. StockCount: 0,
  5970. Creater: creater,
  5971. BatchNumberId: 0,
  5972. WarehouseOutId: 0,
  5973. }
  5974. service.CreateGoodErrcode(goodErrcode)
  5975. }
  5976. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5977. if errs != nil {
  5978. goodErrcode := models.XtGoodErrcode{
  5979. UserOrgId: item.OrgId,
  5980. Errcode: "自动出库创建准备表数据报错",
  5981. GoodId: item.GoodId,
  5982. Status: 1,
  5983. Ctime: time.Now().Unix(),
  5984. Mtime: 0,
  5985. Count: 0,
  5986. StockCount: 0,
  5987. Creater: creater,
  5988. BatchNumberId: 0,
  5989. WarehouseOutId: 0,
  5990. }
  5991. service.CreateGoodErrcode(goodErrcode)
  5992. }
  5993. //查询默认仓库
  5994. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5995. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5996. var total_count int64
  5997. for _, it := range stockList {
  5998. total_count += it.StockCount
  5999. }
  6000. //基础库插入数据
  6001. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6002. if errcodes != nil {
  6003. goodErrcode := models.XtGoodErrcode{
  6004. UserOrgId: item.OrgId,
  6005. Errcode: "自动出库基础库插入数据",
  6006. GoodId: item.GoodId,
  6007. Status: 1,
  6008. Ctime: time.Now().Unix(),
  6009. Mtime: 0,
  6010. Count: 0,
  6011. StockCount: 0,
  6012. Creater: creater,
  6013. BatchNumberId: 0,
  6014. WarehouseOutId: 0,
  6015. }
  6016. service.CreateGoodErrcode(goodErrcode)
  6017. }
  6018. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6019. var flush_count int64
  6020. for _, it := range goodList {
  6021. flush_count += it.StockCount
  6022. }
  6023. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6024. if errsss != nil {
  6025. goodErrcode := models.XtGoodErrcode{
  6026. UserOrgId: item.OrgId,
  6027. Errcode: "自动出库剩余库存更新数据",
  6028. GoodId: item.GoodId,
  6029. Status: 1,
  6030. Ctime: time.Now().Unix(),
  6031. Mtime: 0,
  6032. Count: 0,
  6033. StockCount: 0,
  6034. Creater: creater,
  6035. BatchNumberId: 0,
  6036. WarehouseOutId: 0,
  6037. }
  6038. service.CreateGoodErrcode(goodErrcode)
  6039. }
  6040. }
  6041. }
  6042. //
  6043. } else if err == nil {
  6044. for _, item := range consumables {
  6045. //出库
  6046. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6047. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6048. if err != nil {
  6049. goodErrcode := models.XtGoodErrcode{
  6050. UserOrgId: adminInfo.Org.Id,
  6051. Errcode: "自动出库接口报错",
  6052. GoodId: 0,
  6053. Status: 1,
  6054. Ctime: time.Now().Unix(),
  6055. Mtime: 0,
  6056. Count: 0,
  6057. StockCount: 0,
  6058. Creater: creator,
  6059. BatchNumberId: 0,
  6060. WarehouseOutId: 0,
  6061. }
  6062. service.CreateGoodErrcode(goodErrcode)
  6063. }
  6064. //出库数量相加
  6065. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6066. if errss != nil {
  6067. goodErrcode := models.XtGoodErrcode{
  6068. UserOrgId: item.UserOrgId,
  6069. Errcode: "创建剩余库存字段报错",
  6070. GoodId: item.GoodId,
  6071. Status: 1,
  6072. Ctime: time.Now().Unix(),
  6073. Mtime: time.Now().Unix(),
  6074. Count: 0,
  6075. StockCount: 0,
  6076. Creater: item.Creater,
  6077. BatchNumberId: 0,
  6078. WarehouseOutId: 0,
  6079. }
  6080. service.CreateGoodErrcode(goodErrcode)
  6081. }
  6082. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6083. if len(list) == 0 {
  6084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6085. return
  6086. }
  6087. for _, item := range list {
  6088. prepare := models.DialysisBeforePrepare{
  6089. UserOrgId: adminInfo.Org.Id,
  6090. PatientId: patient_id,
  6091. RecordDate: record_time,
  6092. GoodId: item.GoodId,
  6093. GoodTypeId: item.GoodTypeId,
  6094. Count: item.Count,
  6095. Creater: adminInfo.AdminUser.Id,
  6096. Status: 1,
  6097. Ctime: time.Now().Unix(),
  6098. StorehouseId: houseConfig.StorehouseOutInfo,
  6099. }
  6100. //清空准备表数据
  6101. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6102. if errs != nil {
  6103. goodErrcode := models.XtGoodErrcode{
  6104. UserOrgId: adminInfo.Org.Id,
  6105. Errcode: "自动出库清空准备表数据报错",
  6106. GoodId: 0,
  6107. Status: 1,
  6108. Ctime: time.Now().Unix(),
  6109. Mtime: 0,
  6110. Count: 0,
  6111. StockCount: 0,
  6112. Creater: creator,
  6113. BatchNumberId: 0,
  6114. WarehouseOutId: 0,
  6115. }
  6116. service.CreateGoodErrcode(goodErrcode)
  6117. }
  6118. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6119. if errcodes != nil {
  6120. goodErrcode := models.XtGoodErrcode{
  6121. UserOrgId: adminInfo.Org.Id,
  6122. Errcode: "自动出库创建准备表数据报错",
  6123. GoodId: 0,
  6124. Status: 1,
  6125. Ctime: time.Now().Unix(),
  6126. Mtime: 0,
  6127. Count: 0,
  6128. StockCount: 0,
  6129. Creater: creator,
  6130. BatchNumberId: 0,
  6131. WarehouseOutId: 0,
  6132. }
  6133. service.CreateGoodErrcode(goodErrcode)
  6134. }
  6135. //查询默认仓库
  6136. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6137. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6138. var total_count int64
  6139. for _, it := range stockList {
  6140. total_count += it.StockCount
  6141. }
  6142. //基础库插入数据
  6143. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6144. if errcodes != nil {
  6145. goodErrcode := models.XtGoodErrcode{
  6146. UserOrgId: adminInfo.Org.Id,
  6147. Errcode: "自动出库基础库插入数据报错",
  6148. GoodId: 0,
  6149. Status: 1,
  6150. Ctime: time.Now().Unix(),
  6151. Mtime: 0,
  6152. Count: 0,
  6153. StockCount: 0,
  6154. Creater: creator,
  6155. BatchNumberId: 0,
  6156. WarehouseOutId: 0,
  6157. }
  6158. service.CreateGoodErrcode(goodErrcode)
  6159. }
  6160. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6161. var flush_count int64
  6162. for _, it := range goodList {
  6163. flush_count += it.StockCount
  6164. }
  6165. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6166. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6167. if errss != nil {
  6168. goodErrcode := models.XtGoodErrcode{
  6169. UserOrgId: item.OrgId,
  6170. Errcode: "自动出库剩余库存更新数据",
  6171. GoodId: item.GoodId,
  6172. Status: 1,
  6173. Ctime: time.Now().Unix(),
  6174. Mtime: 0,
  6175. Count: 0,
  6176. StockCount: 0,
  6177. Creater: creater,
  6178. BatchNumberId: 0,
  6179. WarehouseOutId: 0,
  6180. }
  6181. service.CreateGoodErrcode(goodErrcode)
  6182. }
  6183. }
  6184. }
  6185. }
  6186. c.ServeSuccessJSON(map[string]interface{}{
  6187. "msg": "提交成功",
  6188. "message": "2",
  6189. "good_name": "",
  6190. "specification_name": "",
  6191. })
  6192. return
  6193. }
  6194. if record.IsOpen == 1 {
  6195. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6196. //查询是否有库存
  6197. for _, item := range consumables {
  6198. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6199. if item.Count > warehouse.Count {
  6200. goodErrcode := models.XtGoodErrcode{
  6201. UserOrgId: item.UserOrgId,
  6202. Errcode: "自动出库库存不足",
  6203. GoodId: item.GoodId,
  6204. Status: 1,
  6205. Ctime: time.Now().Unix(),
  6206. Mtime: 0,
  6207. Count: 0,
  6208. StockCount: 0,
  6209. Creater: creator,
  6210. BatchNumberId: warehouse.ID,
  6211. WarehouseOutId: 0,
  6212. }
  6213. service.CreateGoodErrcode(goodErrcode)
  6214. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6215. c.ServeSuccessJSON(map[string]interface{}{
  6216. "message": "1",
  6217. "good_name": goodObj.GoodName,
  6218. "specification_name": goodObj.SpecificationName,
  6219. })
  6220. return
  6221. }
  6222. }
  6223. //查询是否有出库单
  6224. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6225. if err == gorm.ErrRecordNotFound {
  6226. //没有记录,则创建出库单
  6227. timeStr := time.Now().Format("2006-01-02")
  6228. timeArr := strings.Split(timeStr, "-")
  6229. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6230. total = total + 1
  6231. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6232. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6233. number = number + total
  6234. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6235. creater := adminInfo.AdminUser.Id
  6236. warehouseOut := models.WarehouseOut{
  6237. WarehouseOutOrderNumber: warehousing_out_order,
  6238. OperationTime: time.Now().Unix(),
  6239. OrgId: adminInfo.Org.Id,
  6240. Creater: creater,
  6241. Ctime: time.Now().Unix(),
  6242. Status: 1,
  6243. WarehouseOutTime: record_time,
  6244. Dealer: 0,
  6245. Manufacturer: 0,
  6246. Type: 1,
  6247. IsSys: 1,
  6248. StorehouseId: houseConfig.StorehouseOutInfo,
  6249. IsCheck: 1,
  6250. }
  6251. err := service.AddSigleWarehouseOut(&warehouseOut)
  6252. if err != nil {
  6253. goodErrcode := models.XtGoodErrcode{
  6254. UserOrgId: adminInfo.Org.Id,
  6255. Errcode: "创建出库单失败",
  6256. GoodId: 0,
  6257. Status: 1,
  6258. Ctime: time.Now().Unix(),
  6259. Mtime: 0,
  6260. Count: 0,
  6261. StockCount: 0,
  6262. Creater: creator,
  6263. BatchNumberId: 0,
  6264. WarehouseOutId: 0,
  6265. }
  6266. service.CreateGoodErrcode(goodErrcode)
  6267. utils.TraceLog("创建出库单失败 err = %v", err)
  6268. } else {
  6269. for _, item := range consumables {
  6270. //出库
  6271. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6272. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6273. if err == nil {
  6274. goodErrcode := models.XtGoodErrcode{
  6275. UserOrgId: adminInfo.Org.Id,
  6276. Errcode: "自动出库接口报错",
  6277. GoodId: 0,
  6278. Status: 1,
  6279. Ctime: time.Now().Unix(),
  6280. Mtime: 0,
  6281. Count: 0,
  6282. StockCount: 0,
  6283. Creater: creator,
  6284. BatchNumberId: 0,
  6285. WarehouseOutId: 0,
  6286. }
  6287. service.CreateGoodErrcode(goodErrcode)
  6288. utils.TraceLog("创建出库单失败 err = %v", err)
  6289. }
  6290. //查询
  6291. //出库数量相加
  6292. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6293. if errs != nil {
  6294. goodErrcode := models.XtGoodErrcode{
  6295. UserOrgId: item.UserOrgId,
  6296. Errcode: "创建剩余库存字段报错",
  6297. GoodId: item.GoodId,
  6298. Status: 1,
  6299. Ctime: time.Now().Unix(),
  6300. Mtime: 0,
  6301. Count: 0,
  6302. StockCount: 0,
  6303. Creater: creater,
  6304. BatchNumberId: 0,
  6305. WarehouseOutId: 0,
  6306. }
  6307. service.CreateGoodErrcode(goodErrcode)
  6308. }
  6309. }
  6310. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6311. if len(list) == 0 {
  6312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6313. return
  6314. }
  6315. for _, item := range list {
  6316. prepare := models.DialysisBeforePrepare{
  6317. UserOrgId: adminInfo.Org.Id,
  6318. PatientId: patient_id,
  6319. RecordDate: record_time,
  6320. GoodId: item.GoodId,
  6321. GoodTypeId: item.GoodTypeId,
  6322. Count: item.Count,
  6323. Creater: adminInfo.AdminUser.Id,
  6324. Status: 1,
  6325. Ctime: time.Now().Unix(),
  6326. StorehouseId: houseConfig.StorehouseOutInfo,
  6327. }
  6328. //清空准备表数据
  6329. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6330. if err != 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. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6347. if errs != nil {
  6348. goodErrcode := models.XtGoodErrcode{
  6349. UserOrgId: item.OrgId,
  6350. Errcode: "自动出库创建准备表数据报错",
  6351. GoodId: item.GoodId,
  6352. Status: 1,
  6353. Ctime: time.Now().Unix(),
  6354. Mtime: 0,
  6355. Count: 0,
  6356. StockCount: 0,
  6357. Creater: creater,
  6358. BatchNumberId: 0,
  6359. WarehouseOutId: 0,
  6360. }
  6361. service.CreateGoodErrcode(goodErrcode)
  6362. }
  6363. //查询默认仓库
  6364. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6365. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6366. var total_count int64
  6367. for _, it := range stockList {
  6368. total_count += it.StockCount
  6369. }
  6370. //基础库插入数据
  6371. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6372. if errcodes != nil {
  6373. goodErrcode := models.XtGoodErrcode{
  6374. UserOrgId: item.OrgId,
  6375. Errcode: "自动出库基础库插入数据",
  6376. GoodId: item.GoodId,
  6377. Status: 1,
  6378. Ctime: time.Now().Unix(),
  6379. Mtime: 0,
  6380. Count: 0,
  6381. StockCount: 0,
  6382. Creater: creater,
  6383. BatchNumberId: 0,
  6384. WarehouseOutId: 0,
  6385. }
  6386. service.CreateGoodErrcode(goodErrcode)
  6387. }
  6388. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6389. var flush_count int64
  6390. for _, it := range goodList {
  6391. flush_count += it.StockCount
  6392. }
  6393. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6394. if errsss != nil {
  6395. goodErrcode := models.XtGoodErrcode{
  6396. UserOrgId: item.OrgId,
  6397. Errcode: "自动出库剩余库存更新数据",
  6398. GoodId: item.GoodId,
  6399. Status: 1,
  6400. Ctime: time.Now().Unix(),
  6401. Mtime: 0,
  6402. Count: 0,
  6403. StockCount: 0,
  6404. Creater: creater,
  6405. BatchNumberId: 0,
  6406. WarehouseOutId: 0,
  6407. }
  6408. service.CreateGoodErrcode(goodErrcode)
  6409. }
  6410. }
  6411. }
  6412. //
  6413. } else if err == nil {
  6414. for _, item := range consumables {
  6415. //出库
  6416. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6417. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6418. if err != nil {
  6419. goodErrcode := models.XtGoodErrcode{
  6420. UserOrgId: adminInfo.Org.Id,
  6421. Errcode: "自动出库接口报错",
  6422. GoodId: 0,
  6423. Status: 1,
  6424. Ctime: time.Now().Unix(),
  6425. Mtime: 0,
  6426. Count: 0,
  6427. StockCount: 0,
  6428. Creater: creator,
  6429. BatchNumberId: 0,
  6430. WarehouseOutId: 0,
  6431. }
  6432. service.CreateGoodErrcode(goodErrcode)
  6433. }
  6434. //出库数量相加
  6435. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6436. if errss != nil {
  6437. goodErrcode := models.XtGoodErrcode{
  6438. UserOrgId: item.UserOrgId,
  6439. Errcode: "创建剩余库存字段报错",
  6440. GoodId: item.GoodId,
  6441. Status: 1,
  6442. Ctime: time.Now().Unix(),
  6443. Mtime: time.Now().Unix(),
  6444. Count: 0,
  6445. StockCount: 0,
  6446. Creater: item.Creater,
  6447. BatchNumberId: 0,
  6448. WarehouseOutId: 0,
  6449. }
  6450. service.CreateGoodErrcode(goodErrcode)
  6451. }
  6452. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6453. if len(list) == 0 {
  6454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6455. return
  6456. }
  6457. for _, item := range list {
  6458. prepare := models.DialysisBeforePrepare{
  6459. UserOrgId: adminInfo.Org.Id,
  6460. PatientId: patient_id,
  6461. RecordDate: record_time,
  6462. GoodId: item.GoodId,
  6463. GoodTypeId: item.GoodTypeId,
  6464. Count: item.Count,
  6465. Creater: adminInfo.AdminUser.Id,
  6466. Status: 1,
  6467. Ctime: time.Now().Unix(),
  6468. StorehouseId: houseConfig.StorehouseOutInfo,
  6469. }
  6470. //清空准备表数据
  6471. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6472. if errs != nil {
  6473. goodErrcode := models.XtGoodErrcode{
  6474. UserOrgId: adminInfo.Org.Id,
  6475. Errcode: "自动出库清空准备表数据报错",
  6476. GoodId: 0,
  6477. Status: 1,
  6478. Ctime: time.Now().Unix(),
  6479. Mtime: 0,
  6480. Count: 0,
  6481. StockCount: 0,
  6482. Creater: creator,
  6483. BatchNumberId: 0,
  6484. WarehouseOutId: 0,
  6485. }
  6486. service.CreateGoodErrcode(goodErrcode)
  6487. }
  6488. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6489. if errcodes != nil {
  6490. goodErrcode := models.XtGoodErrcode{
  6491. UserOrgId: adminInfo.Org.Id,
  6492. Errcode: "自动出库创建准备表数据报错",
  6493. GoodId: 0,
  6494. Status: 1,
  6495. Ctime: time.Now().Unix(),
  6496. Mtime: 0,
  6497. Count: 0,
  6498. StockCount: 0,
  6499. Creater: creator,
  6500. BatchNumberId: 0,
  6501. WarehouseOutId: 0,
  6502. }
  6503. service.CreateGoodErrcode(goodErrcode)
  6504. }
  6505. //查询默认仓库
  6506. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6507. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6508. var total_count int64
  6509. for _, it := range stockList {
  6510. total_count += it.StockCount
  6511. }
  6512. //基础库插入数据
  6513. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6514. if errcodes != nil {
  6515. goodErrcode := models.XtGoodErrcode{
  6516. UserOrgId: adminInfo.Org.Id,
  6517. Errcode: "自动出库基础库插入数据报错",
  6518. GoodId: 0,
  6519. Status: 1,
  6520. Ctime: time.Now().Unix(),
  6521. Mtime: 0,
  6522. Count: 0,
  6523. StockCount: 0,
  6524. Creater: creator,
  6525. BatchNumberId: 0,
  6526. WarehouseOutId: 0,
  6527. }
  6528. service.CreateGoodErrcode(goodErrcode)
  6529. }
  6530. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6531. var flush_count int64
  6532. for _, it := range goodList {
  6533. flush_count += it.StockCount
  6534. }
  6535. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6536. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6537. if errss != nil {
  6538. goodErrcode := models.XtGoodErrcode{
  6539. UserOrgId: item.OrgId,
  6540. Errcode: "自动出库剩余库存更新数据",
  6541. GoodId: item.GoodId,
  6542. Status: 1,
  6543. Ctime: time.Now().Unix(),
  6544. Mtime: 0,
  6545. Count: 0,
  6546. StockCount: 0,
  6547. Creater: creater,
  6548. BatchNumberId: 0,
  6549. WarehouseOutId: 0,
  6550. }
  6551. service.CreateGoodErrcode(goodErrcode)
  6552. }
  6553. }
  6554. }
  6555. }
  6556. c.ServeSuccessJSON(map[string]interface{}{
  6557. "msg": "提交成功",
  6558. "message": "2",
  6559. "good_name": "",
  6560. "specification_name": "",
  6561. })
  6562. return
  6563. } else {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6565. return
  6566. }
  6567. }
  6568. func (c *DialysisAPIController) EditConsumables() {
  6569. patient_id, _ := c.GetInt64("patient_id", 0)
  6570. record_date := c.GetString("record_time")
  6571. if patient_id <= 0 {
  6572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6573. return
  6574. }
  6575. adminInfo := c.GetMobileAdminUserInfo()
  6576. timeLayout := "2006-01-02"
  6577. loc, _ := time.LoadLocation("Local")
  6578. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6579. record_time := theRecordTime.Unix()
  6580. // 查询信息规挡的设置天数
  6581. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6582. if infor.ID > 0 && infor.WeekDay > 0 {
  6583. var cha_time int64
  6584. timeNowStr := time.Now().Format("2006-01-02")
  6585. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6586. //今日的日期减去设置的日期
  6587. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6588. if cha_time >= record_time {
  6589. //查询审核是否允许
  6590. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6591. //申请状态不允许的情况 拒绝修改
  6592. if infor.ApplicationStatus != 1 {
  6593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6594. return
  6595. }
  6596. }
  6597. }
  6598. dataBody := make(map[string]interface{}, 0)
  6599. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6600. if err != nil {
  6601. utils.ErrorLog(err.Error())
  6602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6603. return
  6604. }
  6605. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6606. var beforePrepares []*models.DialysisBeforePrepareGoods
  6607. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6608. var cancelbefor []*models.DialysisBeforePrepareGoods
  6609. var outbefor []*models.DialysisBeforePrepareGoods
  6610. //判断是否开启自动出库
  6611. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6612. if record.IsOpen == 1 {
  6613. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6614. goods, _ := dataBody["goods"].([]interface{})
  6615. if len(goods) > 0 {
  6616. for _, item := range goods {
  6617. items := item.(map[string]interface{})
  6618. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6619. utils.ErrorLog("good_id")
  6620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6621. return
  6622. }
  6623. good_id := int64(items["good_id"].(float64))
  6624. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6625. utils.ErrorLog("good_type_id")
  6626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6627. return
  6628. }
  6629. good_type_id := int64(items["good_type_id"].(float64))
  6630. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6631. utils.ErrorLog("count")
  6632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6633. return
  6634. }
  6635. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6636. commdity_code := items["commdity_code"].(string)
  6637. fmt.Println(commdity_code)
  6638. prepareGoods := &models.DialysisBeforePrepareGoods{
  6639. GoodTypeId: good_type_id,
  6640. GoodId: good_id,
  6641. Count: count,
  6642. StorehouseId: houseConfig.StorehouseOutInfo,
  6643. }
  6644. beforePrepares = append(beforePrepares, prepareGoods)
  6645. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6646. GoodTypeId: good_type_id,
  6647. GoodId: good_id,
  6648. Count: count,
  6649. StorehouseId: houseConfig.StorehouseOutInfo,
  6650. }
  6651. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6652. }
  6653. for _, item := range beforePrepares {
  6654. //1.查看该患者该耗材型号最后一次出库数量
  6655. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6656. //判断当前出库数量和最后一次出库数量的大小
  6657. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6658. if item.Count < goodInfo.Count {
  6659. cancelbefor = append(cancelbefor, item)
  6660. }
  6661. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6662. if item.Count > goodInfo.Count {
  6663. outbefor = append(outbefor, item)
  6664. }
  6665. //处理编辑耗材新增不了的问题
  6666. if goodInfo.Count == item.Count {
  6667. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6668. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6669. }
  6670. }
  6671. if len(cancelbefor) > 0 {
  6672. //退库
  6673. for _, item := range cancelbefor {
  6674. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6675. creater := adminInfo.AdminUser.Id
  6676. //查询该患者当天已经出库的耗材信息
  6677. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6678. var delete_count int64 = 0
  6679. delete_count = warehouseOutInfos.Count - item.Count
  6680. //增加库存数量
  6681. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6682. //减少实际出库库存数量
  6683. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6684. // 删除出库完成后,要增加对应批次的库存数量
  6685. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6686. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6687. //更新剩余库存
  6688. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6689. var flush_count int64
  6690. for _, it := range goodListOne {
  6691. flush_count += it.StockCount
  6692. }
  6693. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6694. //查询剩余库存
  6695. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6696. var sum_count int64
  6697. for _, item := range goodList {
  6698. sum_count += item.StockCount
  6699. }
  6700. // 在出库记录表里记录退库详情
  6701. warehouseOutInfo := &models.WarehouseOutInfo{
  6702. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6703. WarehouseOutId: warehouseOut.ID,
  6704. Status: 1,
  6705. Ctime: time.Now().Unix(),
  6706. OrgId: adminInfo.Org.Id,
  6707. Type: 1,
  6708. IsSys: 1,
  6709. SysRecordTime: record_time,
  6710. GoodTypeId: item.GoodTypeId,
  6711. GoodId: item.GoodId,
  6712. PatientId: patient_id,
  6713. ConsumableType: 2,
  6714. StorehouseId: houseConfig.StorehouseOutInfo,
  6715. IsCheck: 1,
  6716. OverCount: sum_count,
  6717. }
  6718. warehouseOutInfo.Count = item.Count
  6719. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6720. warehouseOutInfo.Price = stockInInfo.Price
  6721. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6722. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6723. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6724. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6725. warehouseOutInfo.Number = warehouseOutInfos.Number
  6726. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6727. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6728. //查找当天是否存在出库记录
  6729. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6730. if errcod == gorm.ErrRecordNotFound {
  6731. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6732. //插入详情明细表
  6733. stockFlow := models.VmStockFlow{
  6734. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6735. WarehouseOutId: warehouseOut.ID,
  6736. GoodId: item.GoodId,
  6737. Number: warehouseOutInfos.Number,
  6738. ProductDate: stockInInfo.ProductDate,
  6739. ExpireDate: stockInInfo.ExpiryDate,
  6740. Count: item.Count,
  6741. Price: stockInInfo.Price,
  6742. Status: 1,
  6743. Ctime: record_time,
  6744. UserOrgId: adminInfo.Org.Id,
  6745. Manufacturer: stockInInfo.Manufacturer,
  6746. Dealer: stockInInfo.Dealer,
  6747. LicenseNumber: stockInInfo.LicenseNumber,
  6748. IsEdit: 2,
  6749. Creator: creater,
  6750. SystemTime: record_time,
  6751. ConsumableType: 3,
  6752. WarehousingDetailId: 0,
  6753. IsSys: 1,
  6754. UpdateCreator: creater,
  6755. PatientId: patient_id,
  6756. StorehouseId: houseConfig.StorehouseOutInfo,
  6757. }
  6758. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6759. if errflow == gorm.ErrRecordNotFound {
  6760. //创建流水表
  6761. err := service.CreateStockFlowOne(stockFlow)
  6762. fmt.Println("err", err)
  6763. } else if errflow == nil {
  6764. //插入详情明细表
  6765. stockFlow := models.VmStockFlow{
  6766. ID: exsit.ID,
  6767. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6768. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6769. WarehouseOutId: warehouseOut.ID,
  6770. GoodId: item.GoodId,
  6771. Number: warehouseOutInfos.Number,
  6772. ProductDate: stockInInfo.ProductDate,
  6773. ExpireDate: stockInInfo.ExpiryDate,
  6774. Count: exsit.Count - delete_count,
  6775. Price: stockInInfo.Price,
  6776. Status: 1,
  6777. Ctime: record_time,
  6778. UserOrgId: adminInfo.Org.Id,
  6779. Manufacturer: stockInInfo.Manufacturer,
  6780. Dealer: stockInInfo.Dealer,
  6781. LicenseNumber: stockInInfo.LicenseNumber,
  6782. IsEdit: 2,
  6783. Creator: creater,
  6784. SystemTime: record_time,
  6785. ConsumableType: 3,
  6786. WarehousingDetailId: 0,
  6787. IsSys: 1,
  6788. UpdateCreator: creater,
  6789. PatientId: patient_id,
  6790. StorehouseId: houseConfig.StorehouseOutInfo,
  6791. }
  6792. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6793. }
  6794. } else if errcod == nil {
  6795. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6796. //查询剩余库存
  6797. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6798. var sum_count int64
  6799. for _, item := range goodList {
  6800. sum_count += item.StockCount
  6801. }
  6802. //创建退库单,生成退库数据
  6803. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6804. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6805. operation_time := time.Now().Unix()
  6806. creater := adminInfo.AdminUser.Id
  6807. //创建退库单
  6808. timeStr := time.Now().Format("2006-01-02")
  6809. timeArr := strings.Split(timeStr, "-")
  6810. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6811. total = total + 1
  6812. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6813. cancelStock := models.CancelStock{
  6814. OrderNumber: orderNumber,
  6815. OperaTime: operation_time,
  6816. OrgId: adminInfo.Org.Id,
  6817. Creater: creater,
  6818. Ctime: time.Now().Unix(),
  6819. Status: 1,
  6820. ReturnTime: record_time,
  6821. Type: 1,
  6822. StorehouseId: houseConfig.StorehouseOutInfo,
  6823. IsCheck: 1,
  6824. }
  6825. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6826. if msgerrkonde == gorm.ErrRecordNotFound {
  6827. service.AddSigleCancelStock(&cancelStock)
  6828. }
  6829. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6830. //查询是否有出库
  6831. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6832. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6833. deaerler, _ := service.GetDealerById(info.Dealer)
  6834. if info.ID > 0 {
  6835. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6836. cancelStockInfo := models.CancelStockInfo{
  6837. GoodId: item.GoodId,
  6838. CancelStockId: cancel.ID,
  6839. GoodTypeId: good.GoodTypeId,
  6840. Count: delete_count,
  6841. Price: info.Price,
  6842. Total: 0,
  6843. ProductDate: info.ProductDate,
  6844. ExpiryDate: info.ExpiryDate,
  6845. Ctime: time.Now().Unix(),
  6846. Status: 1,
  6847. OrgId: adminInfo.Org.Id,
  6848. OrderNumber: cancel.OrderNumber,
  6849. Type: 0,
  6850. Dealer: deaerler.DealerName,
  6851. Manufacturer: manufacturer.ManufacturerName,
  6852. Number: info.Number,
  6853. RegisterAccount: "",
  6854. Remark: "",
  6855. WarehouseInfoId: info.WarehouseInfotId,
  6856. PatientId: info.PatientId,
  6857. RecordDate: info.SysRecordTime,
  6858. StorehouseId: houseConfig.StorehouseOutInfo,
  6859. IsCheck: 1,
  6860. }
  6861. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6862. //退库数量增加
  6863. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6864. //查询剩余库存
  6865. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6866. var over_count int64
  6867. for _, it := range goodList {
  6868. over_count += it.StockCount
  6869. }
  6870. flow := models.VmStockFlow{
  6871. WarehousingId: info.WarehouseInfotId,
  6872. GoodId: item.GoodId,
  6873. Number: info.Number,
  6874. LicenseNumber: info.LicenseNumber,
  6875. Count: delete_count,
  6876. UserOrgId: adminInfo.Org.Id,
  6877. PatientId: patient_id,
  6878. SystemTime: info.SysRecordTime,
  6879. ConsumableType: 7,
  6880. IsSys: 0,
  6881. WarehousingOrder: "",
  6882. WarehouseOutId: info.WarehouseOutId,
  6883. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6884. IsEdit: 0,
  6885. CancelStockId: cancel.ID,
  6886. CancelOrderNumber: cancel.OrderNumber,
  6887. Manufacturer: manufacturer.ID,
  6888. Dealer: 0,
  6889. Creator: adminInfo.AdminUser.Id,
  6890. UpdateCreator: 0,
  6891. Status: 1,
  6892. Ctime: record_time,
  6893. Mtime: 0,
  6894. Price: info.Price,
  6895. WarehousingDetailId: info.WarehouseInfotId,
  6896. WarehouseOutDetailId: info.ID,
  6897. CancelOutDetailId: cancelInfo.ID,
  6898. ProductDate: info.ProductDate,
  6899. ExpireDate: info.ExpiryDate,
  6900. StorehouseId: houseConfig.StorehouseOutInfo,
  6901. OverCount: over_count,
  6902. }
  6903. service.CreateStockFlowOne(flow)
  6904. }
  6905. }
  6906. //更改自动出库的表格
  6907. details := models.BloodAutomaticReduceDetail{
  6908. WarehouseOutId: warehouseOutInfo.ID,
  6909. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6910. PatientId: patient_id,
  6911. Ctime: time.Now().Unix(),
  6912. Mtime: time.Now().Unix(),
  6913. Status: 1,
  6914. RecordTime: record_time,
  6915. OrgId: adminInfo.Org.Id,
  6916. GoodId: item.GoodId,
  6917. GoodTypeId: item.GoodTypeId,
  6918. Count: item.Count,
  6919. StorehouseId: houseConfig.StorehouseOutInfo,
  6920. }
  6921. //查询当天耗材是否已经存在数据
  6922. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6923. if errcode == gorm.ErrRecordNotFound {
  6924. service.CreateAutoReduceRecord(&details)
  6925. } else if errcode == nil {
  6926. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6927. service.CreateAutoReduceRecord(&details)
  6928. }
  6929. //查询默认仓库
  6930. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6931. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6932. var total_count int64
  6933. for _, it := range stockList {
  6934. total_count += it.StockCount
  6935. }
  6936. //基础库插入数据
  6937. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6938. }
  6939. }
  6940. if len(outbefor) > 0 {
  6941. //出库
  6942. for _, item := range outbefor {
  6943. var last_total int64
  6944. //1.查看该患者该耗材型号最后一次出库数量
  6945. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6946. //计算当前出库和最后一次出库数据相差数据
  6947. last_total = item.Count - goodInfoOne.Count
  6948. //查询该耗材的总库存
  6949. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6950. // 如果库存差大于剩余库存则提示库存不足
  6951. if last_total > wareinfo.StockCount {
  6952. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6953. c.ServeSuccessJSON(map[string]interface{}{
  6954. "message": "1",
  6955. "good_name": goodObj.GoodName,
  6956. "specification_name": goodObj.SpecificationName,
  6957. })
  6958. return
  6959. } else {
  6960. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6961. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6962. if err == gorm.ErrRecordNotFound {
  6963. //没有记录,则创建出库单
  6964. timeStr := time.Now().Format("2006-01-02")
  6965. timeArr := strings.Split(timeStr, "-")
  6966. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6967. total = total + 1
  6968. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6969. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6970. number = number + total
  6971. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6972. warehouseOut := models.WarehouseOut{
  6973. WarehouseOutOrderNumber: warehousing_out_order,
  6974. OperationTime: time.Now().Unix(),
  6975. OrgId: adminInfo.Org.Id,
  6976. Creater: adminInfo.AdminUser.Id,
  6977. Ctime: time.Now().Unix(),
  6978. Status: 1,
  6979. WarehouseOutTime: record_time,
  6980. Dealer: 0,
  6981. Manufacturer: 0,
  6982. Type: 1,
  6983. IsSys: 1,
  6984. StorehouseId: houseConfig.StorehouseOutInfo,
  6985. IsCheck: 1,
  6986. }
  6987. service.AddSigleWarehouseOut(&warehouseOut)
  6988. }
  6989. //出库
  6990. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6991. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6992. //1.查看该患者该耗材型号最后一次出库数量
  6993. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6994. prepare := models.DialysisBeforePrepare{
  6995. UserOrgId: adminInfo.Org.Id,
  6996. PatientId: patient_id,
  6997. RecordDate: record_time,
  6998. GoodId: item.GoodId,
  6999. GoodTypeId: item.GoodTypeId,
  7000. Count: item.Count - goodInfoTwo.Count,
  7001. Ctime: time.Now().Unix(),
  7002. Mtime: 0,
  7003. Creater: adminInfo.AdminUser.Id,
  7004. Modifier: adminInfo.AdminUser.Id,
  7005. Status: 1,
  7006. CommdityCode: "",
  7007. NewCount: 0,
  7008. ProjectId: 0,
  7009. StorehouseId: houseConfig.StorehouseOutInfo,
  7010. }
  7011. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7012. //增加出库数量
  7013. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7014. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7015. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7016. var total_count int64
  7017. for _, it := range stockList {
  7018. total_count += it.StockCount
  7019. }
  7020. //基础库插入数据
  7021. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7022. //剩余库存
  7023. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7024. var flush_count int64
  7025. for _, it := range goodList {
  7026. flush_count += it.StockCount
  7027. }
  7028. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7029. }
  7030. }
  7031. }
  7032. //查询今日出库数据
  7033. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7034. for _, it := range list {
  7035. prepare := models.DialysisBeforePrepare{
  7036. UserOrgId: it.OrgId,
  7037. PatientId: patient_id,
  7038. RecordDate: it.RecordTime,
  7039. GoodId: it.GoodId,
  7040. GoodTypeId: it.GoodTypeId,
  7041. Count: it.Count,
  7042. Ctime: time.Now().Unix(),
  7043. Creater: adminInfo.AdminUser.Id,
  7044. Status: 1,
  7045. StorehouseId: houseConfig.StorehouseOutInfo,
  7046. ProjectId: it.ProjectId,
  7047. }
  7048. //删除准备表数据
  7049. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7050. service.CreateDialysisBeforePrepareOne(&prepare)
  7051. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7052. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7053. var total_count int64
  7054. for _, it := range stockList {
  7055. total_count += it.StockCount
  7056. }
  7057. //基础库插入数据
  7058. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7059. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7060. var flush_count int64
  7061. for _, it := range goodList {
  7062. flush_count += it.StockCount
  7063. }
  7064. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7065. }
  7066. }
  7067. }
  7068. //更新自动出库的地方
  7069. var errs error
  7070. if errs == nil {
  7071. c.ServeSuccessJSON(map[string]interface{}{
  7072. "msg": "修改成功",
  7073. "message": "2",
  7074. "good_name": "",
  7075. "specification_name": "",
  7076. })
  7077. return
  7078. } else {
  7079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7080. return
  7081. }
  7082. }
  7083. }
  7084. func (c *DialysisAPIController) GetDialysisGoods() {
  7085. schedualDate := c.GetString("schedule_date")
  7086. schedule_type, _ := c.GetInt64("schedule_type")
  7087. partition_id, _ := c.GetInt64("partition_id")
  7088. page, _ := c.GetInt("page")
  7089. patient_id, _ := c.GetInt64("patient_id")
  7090. schedualEndDate := int64(0)
  7091. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7092. if parseDateErr != nil && len(schedualDate) != 0 {
  7093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7094. return
  7095. }
  7096. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7097. if parseDateErr != nil && len(schedualDate) != 0 {
  7098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7099. return
  7100. }
  7101. schedualEndDate = endDate.Unix()
  7102. adminUser := c.GetMobileAdminUserInfo()
  7103. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7104. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7105. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7106. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7107. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7108. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7109. //获取当天该病人的透析处方
  7110. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7111. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7112. if err == gorm.ErrRecordNotFound {
  7113. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7114. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7115. if patient_id != 0 {
  7116. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7117. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7118. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7119. //获取患者总的出库数据
  7120. item.LastAutomaticReduceDetail = goodUser
  7121. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7122. item.Project = project
  7123. for _, it := range item.AutomaticReduceDetail {
  7124. var total int64
  7125. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7126. for _, its := range auto {
  7127. total += its.Count
  7128. }
  7129. it.Count = total
  7130. }
  7131. }
  7132. }
  7133. c.ServeSuccessJSON(map[string]interface{}{
  7134. "dialysis_goods": dialysisGoods,
  7135. "good_type": goodTypes,
  7136. "total": total,
  7137. "prescribe": prescribe,
  7138. "good_info": good_info,
  7139. "warehouseOutList": warehouseOutList,
  7140. "config": config,
  7141. "outConfig": outConfig,
  7142. "settleConfig": settleConfig,
  7143. })
  7144. return
  7145. } else if err == nil {
  7146. //获取当天排班的每个患者的库存使用情况
  7147. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7148. //获取患者总的出库数据
  7149. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7150. if patient_id != 0 {
  7151. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7152. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7153. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7154. item.Project = project
  7155. item.LastAutomaticReduceDetail = goodUser
  7156. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7157. for _, it := range item.AutomaticReduceDetail {
  7158. var total int64
  7159. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7160. for _, its := range auto {
  7161. total += its.Count
  7162. }
  7163. it.Count = total
  7164. }
  7165. }
  7166. }
  7167. if err == nil {
  7168. c.ServeSuccessJSON(map[string]interface{}{
  7169. "dialysis_goods": dialysisGoods,
  7170. "good_type": goodTypes,
  7171. "total": total,
  7172. "prescribe": prescribe,
  7173. "good_info": good_info,
  7174. "project": project,
  7175. "warehouseOutList": warehouseOutList,
  7176. "config": config,
  7177. "outConfig": outConfig,
  7178. "settleConfig": settleConfig,
  7179. })
  7180. return
  7181. } else {
  7182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7183. return
  7184. }
  7185. } else if err != nil {
  7186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7187. return
  7188. }
  7189. }
  7190. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7191. start_time := c.GetString("start_time")
  7192. end_time := c.GetString("end_time")
  7193. timeLayout := "2006-01-02"
  7194. loc, _ := time.LoadLocation("Local")
  7195. var theStartTime int64
  7196. if len(start_time) > 0 {
  7197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7198. if err != nil {
  7199. utils.ErrorLog(err.Error())
  7200. }
  7201. theStartTime = theTime.Unix()
  7202. }
  7203. var theEndtTime int64
  7204. if len(end_time) > 0 {
  7205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7206. if err != nil {
  7207. utils.ErrorLog(err.Error())
  7208. }
  7209. theEndtTime = theTime.Unix()
  7210. }
  7211. adminUser := c.GetMobileAdminUserInfo()
  7212. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7213. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7214. if err == nil {
  7215. c.ServeSuccessJSON(map[string]interface{}{
  7216. "stock_out": outInfo,
  7217. "stockCount": stockCount,
  7218. })
  7219. return
  7220. } else {
  7221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7222. return
  7223. }
  7224. }
  7225. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7226. patient_id, _ := c.GetInt64("patient_id", 0)
  7227. record_time := c.GetString("record_time")
  7228. adminUser := c.GetMobileAdminUserInfo()
  7229. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7230. if parseDateErr != nil && len(record_time) != 0 {
  7231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7232. return
  7233. }
  7234. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7235. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7236. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7237. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7238. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7239. //获取今日患者的透析处方参数
  7240. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7241. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7242. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7243. c.ServeSuccessJSON(map[string]interface{}{
  7244. "good_type": goodTypes,
  7245. "good_user": goodUser,
  7246. "good_info": good_info,
  7247. "last_good_user": lastGoodUserDetial,
  7248. "project": project,
  7249. "prescription": prescribe,
  7250. "outInfo": outInfo,
  7251. "configs": configs,
  7252. })
  7253. return
  7254. }
  7255. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7256. patient_id, _ := c.GetInt64("patient_id", 0)
  7257. record_date := c.GetString("record_time")
  7258. timeLayout := "2006-01-02"
  7259. loc, _ := time.LoadLocation("Local")
  7260. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7261. record_time := theRecordTime.Unix()
  7262. adminInfo := c.GetMobileAdminUserInfo()
  7263. dataBody := make(map[string]interface{}, 0)
  7264. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7265. if err != nil {
  7266. utils.ErrorLog(err.Error())
  7267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7268. return
  7269. }
  7270. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7271. var beforePrepares []*models.DialysisBeforePrepareGoods
  7272. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7273. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7274. goods, _ := dataBody["goods"].([]interface{})
  7275. if len(goods) > 0 {
  7276. for _, item := range goods {
  7277. items := item.(map[string]interface{})
  7278. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7279. utils.ErrorLog("good_id")
  7280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7281. return
  7282. }
  7283. good_id := int64(items["good_id"].(float64))
  7284. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7285. utils.ErrorLog("good_type_id")
  7286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7287. return
  7288. }
  7289. good_type_id := int64(items["good_type_id"].(float64))
  7290. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7291. utils.ErrorLog("count")
  7292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7293. return
  7294. }
  7295. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7296. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7297. utils.ErrorLog("project_id")
  7298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7299. return
  7300. }
  7301. project_id := int64(items["project_id"].(float64))
  7302. new_count := int64(items["new_count"].(float64))
  7303. old_count := int64(items["old_count"].(float64))
  7304. prepare := &models.DialysisBeforePrepareGoods{
  7305. GoodId: good_id,
  7306. GoodTypeId: good_type_id,
  7307. Count: count,
  7308. ProjectId: project_id,
  7309. StorehouseId: houseConfig.StorehouseOutInfo,
  7310. NewCount: new_count,
  7311. OldCount: old_count,
  7312. }
  7313. beforePrepares = append(beforePrepares, prepare)
  7314. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7315. GoodId: good_id,
  7316. GoodTypeId: good_type_id,
  7317. Count: count,
  7318. ProjectId: project_id,
  7319. StorehouseId: houseConfig.StorehouseOutInfo,
  7320. NewCount: new_count,
  7321. OldCount: old_count,
  7322. }
  7323. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7324. }
  7325. }
  7326. }
  7327. //查询是否有库存
  7328. for _, item := range beforePrepares {
  7329. if item.NewCount > 0 {
  7330. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7331. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7332. if item.Count > warehouse.Count {
  7333. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7334. c.ServeSuccessJSON(map[string]interface{}{
  7335. "message": "1",
  7336. "good_name": goodObj.GoodName,
  7337. "specification_name": goodObj.SpecificationName,
  7338. })
  7339. return
  7340. }
  7341. }
  7342. }
  7343. // 查询信息规挡的设置天数
  7344. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7345. if infor.ID > 0 && infor.WeekDay > 0 {
  7346. var cha_time int64
  7347. timeNowStr := time.Now().Format("2006-01-02")
  7348. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7349. //今日的日期减去设置的日期
  7350. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7351. if cha_time >= record_time {
  7352. //查询审核是否允许
  7353. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7354. //申请状态不允许的情况 拒绝修改
  7355. if infor.ApplicationStatus != 1 {
  7356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7357. return
  7358. }
  7359. }
  7360. }
  7361. //出库逻辑
  7362. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7363. if err != nil {
  7364. utils.ErrorLog(err.Error())
  7365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7366. return
  7367. }
  7368. finish := models.XtDialysisFinish{
  7369. IsFinish: 1,
  7370. UserOrgId: adminInfo.Org.Id,
  7371. Status: 1,
  7372. Ctime: time.Now().Unix(),
  7373. Mtime: 0,
  7374. Module: 11,
  7375. RecordDate: record_time,
  7376. Sourse: 1,
  7377. PatientId: patient_id,
  7378. }
  7379. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7380. if dialysisFinish.ID == 0 {
  7381. service.CreateDialysisFinish(finish)
  7382. }
  7383. //查询当天出库的数据
  7384. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7385. for _, item := range list {
  7386. prepare := models.DialysisBeforePrepare{
  7387. UserOrgId: item.OrgId,
  7388. PatientId: item.PatientId,
  7389. RecordDate: item.RecordTime,
  7390. GoodId: item.GoodId,
  7391. GoodTypeId: item.GoodTypeId,
  7392. Count: item.Count,
  7393. Creater: adminInfo.AdminUser.Id,
  7394. Status: 1,
  7395. Ctime: time.Now().Unix(),
  7396. ProjectId: item.ProjectId,
  7397. StorehouseId: houseConfig.StorehouseOutInfo,
  7398. }
  7399. //清空准备表的数据
  7400. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7401. //插入准备表数据
  7402. service.CreateDialysisBeforePrepareOne(&prepare)
  7403. //查询默认仓库
  7404. //查询默认仓库
  7405. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7406. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7407. var total_count int64
  7408. for _, it := range stockList {
  7409. total_count += it.StockCount
  7410. }
  7411. //基础库插入数据
  7412. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7413. ////更新剩余库存
  7414. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7415. var flush_count int64
  7416. for _, it := range goodList {
  7417. flush_count += it.StockCount
  7418. }
  7419. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7420. if errs != nil {
  7421. goodErrcode := models.XtGoodErrcode{
  7422. UserOrgId: item.OrgId,
  7423. Errcode: "手动出库更新剩余出库失败",
  7424. GoodId: item.GoodId,
  7425. Status: 1,
  7426. Ctime: time.Now().Unix(),
  7427. Mtime: 0,
  7428. Count: 0,
  7429. StockCount: 0,
  7430. Creater: adminInfo.AdminUser.Id,
  7431. BatchNumberId: 0,
  7432. WarehouseOutId: 0,
  7433. }
  7434. service.CreateGoodErrcode(goodErrcode)
  7435. }
  7436. }
  7437. //更新自动出库的地方
  7438. var errs error
  7439. if errs == nil {
  7440. c.ServeSuccessJSON(map[string]interface{}{
  7441. "msg": "修改成功",
  7442. "message": "2",
  7443. "good_name": "",
  7444. "specification_name": "",
  7445. })
  7446. return
  7447. } else {
  7448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7449. return
  7450. }
  7451. }
  7452. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7453. newArr = make([]*models.DialysisBeforePrepare, 0)
  7454. for i := 0; i < len(arr); i++ {
  7455. repeat := false
  7456. for j := i + 1; j < len(arr); j++ {
  7457. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7458. repeat = true
  7459. break
  7460. }
  7461. }
  7462. if !repeat {
  7463. newArr = append(newArr, arr[i])
  7464. }
  7465. }
  7466. return
  7467. }
  7468. func (c *DialysisAPIController) GetAllDrug() {
  7469. patient_id, _ := c.GetInt64("patient_id", 0)
  7470. adminInfo := c.GetMobileAdminUserInfo()
  7471. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7472. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7473. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7474. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7475. c.ServeSuccessJSON(map[string]interface{}{
  7476. "base_drug_config": drugStockConfig,
  7477. "private_drug_config": privateDrugConfig,
  7478. "base_drug_list": drugList,
  7479. "private_drug_list": privateDrugList,
  7480. })
  7481. }
  7482. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7483. newArr = make([]*models.DialysisBeforePrepare, 0)
  7484. for i := 0; i < len(arr); i++ {
  7485. repeat := false
  7486. for j := i + 1; j < len(arr); j++ {
  7487. if arr[i].GoodId == arr[j].GoodId {
  7488. repeat = true
  7489. break
  7490. }
  7491. }
  7492. if !repeat {
  7493. newArr = append(newArr, arr[i])
  7494. }
  7495. }
  7496. return
  7497. }
  7498. func (c *DialysisAPIController) GetDepartment() {
  7499. adminInfo := c.GetMobileAdminUserInfo()
  7500. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7501. if err == nil {
  7502. c.ServeSuccessJSON(map[string]interface{}{
  7503. "departments": departments,
  7504. })
  7505. } else {
  7506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7507. return
  7508. }
  7509. }
  7510. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7511. types, _ := c.GetInt("type", 0)
  7512. start_time := c.GetString("start_time")
  7513. end_time := c.GetString("end_time")
  7514. orgId := c.GetMobileAdminUserInfo().Org.Id
  7515. timeLayout := "2006-01-02"
  7516. loc, _ := time.LoadLocation("Local")
  7517. var startTime int64
  7518. if len(start_time) > 0 {
  7519. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7520. if err != nil {
  7521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7522. return
  7523. }
  7524. startTime = theTime.Unix()
  7525. }
  7526. var endTime int64
  7527. if len(end_time) > 0 {
  7528. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7529. if err != nil {
  7530. utils.ErrorLog(err.Error())
  7531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7532. return
  7533. }
  7534. endTime = theTime.Unix()
  7535. }
  7536. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7537. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7538. if err != nil {
  7539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7540. } else {
  7541. c.ServeSuccessJSON(map[string]interface{}{
  7542. "list": list,
  7543. "type": types,
  7544. "stockTotal": stockTotal,
  7545. })
  7546. }
  7547. }
  7548. func (c *DialysisAPIController) GetPrescriptionList() {
  7549. start_time := c.GetString("start_time")
  7550. end_time := c.GetString("end_time")
  7551. schedule_type, _ := c.GetInt64("schedule_type")
  7552. partion_id, _ := c.GetInt64("partion_id")
  7553. orgId := c.GetMobileAdminUserInfo().Org.Id
  7554. timeLayout := "2006-01-02"
  7555. loc, _ := time.LoadLocation("Local")
  7556. var startTime int64
  7557. if len(start_time) > 0 {
  7558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7559. if err != nil {
  7560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7561. return
  7562. }
  7563. startTime = theTime.Unix()
  7564. }
  7565. var endTime int64
  7566. if len(end_time) > 0 {
  7567. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7568. if err != nil {
  7569. utils.ErrorLog(err.Error())
  7570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7571. return
  7572. }
  7573. endTime = theTime.Unix()
  7574. }
  7575. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7576. fmt.Println("schedulelist22222222", schedulelist)
  7577. c.ServeSuccessJSON(map[string]interface{}{
  7578. "list": schedulelist,
  7579. })
  7580. return
  7581. }
  7582. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7583. ids := c.GetString("ids")
  7584. //patient_id, _ := c.GetInt64("patient_id")
  7585. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7586. idArray := strings.Split(ids, ",")
  7587. err := service.BatchDeleteMonitor(idArray)
  7588. fmt.Print("err", err)
  7589. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7590. //redis := service.RedisClient()
  7591. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7592. //redis.Set(key, "", time.Second)
  7593. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7594. //redis.Set(keyOne, "", time.Second)
  7595. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7596. //redis.Close()
  7597. c.ServeSuccessJSON(map[string]interface{}{
  7598. "msg": "批量删除成功",
  7599. })
  7600. return
  7601. }
  7602. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7603. id, _ := c.GetInt64("id")
  7604. timeLayout := "2006-01-02"
  7605. loc, _ := time.LoadLocation("Local")
  7606. //start_time := time.Now().Format("2006-01-02")
  7607. start_time := c.GetString("start_time")
  7608. end_time := c.GetString("end_time")
  7609. var startdateunix int64
  7610. if len(start_time) > 0 {
  7611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7612. if err != nil {
  7613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7614. return
  7615. }
  7616. startdateunix = theTime.Unix()
  7617. }
  7618. var enddateunix int64
  7619. if len(end_time) > 0 {
  7620. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7621. if err != nil {
  7622. utils.ErrorLog(err.Error())
  7623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7624. return
  7625. }
  7626. enddateunix = theTime.Unix()
  7627. }
  7628. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7629. //nowTime := time.Now()
  7630. //endTime := nowTime.AddDate(-30, 0, 0)
  7631. //endTimes := endTime.Format("2006-01-02")
  7632. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7633. org_id := c.GetMobileAdminUserInfo().Org.Id
  7634. //if org_id == 10579 {
  7635. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7636. // c.ServeSuccessJSON(map[string]interface{}{
  7637. // "list": list,
  7638. // })
  7639. // return
  7640. //} else {
  7641. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7642. // c.ServeSuccessJSON(map[string]interface{}{
  7643. // "list": list,
  7644. // })
  7645. // return
  7646. //}
  7647. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7648. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7649. c.ServeSuccessJSON(map[string]interface{}{
  7650. "list": list,
  7651. })
  7652. return
  7653. } else {
  7654. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7655. c.ServeSuccessJSON(map[string]interface{}{
  7656. "list": list,
  7657. })
  7658. }
  7659. return
  7660. }
  7661. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7662. dataBody := make(map[string]interface{}, 0)
  7663. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7664. ids := c.GetString("ids")
  7665. idArray := strings.Split(ids, ",")
  7666. origin, _ := c.GetInt64("origin")
  7667. if origin == 1 {
  7668. err = service.BatchDeleteAdvice(idArray)
  7669. fmt.Print("err", err)
  7670. c.ServeSuccessJSON(map[string]interface{}{
  7671. "msg": "批量删除成功",
  7672. })
  7673. return
  7674. }
  7675. if origin == 2 {
  7676. service.BatchDeleteHisAdvice(idArray)
  7677. }
  7678. }
  7679. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7680. good_id, _ := c.GetInt64("good_id")
  7681. count, _ := c.GetInt64("count")
  7682. record_time, _ := c.GetInt64("record_time")
  7683. patient_id, _ := c.GetInt64("patient_id")
  7684. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7685. c.ServeSuccessJSON(map[string]interface{}{
  7686. "detail": detail,
  7687. })
  7688. return
  7689. }
  7690. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7691. good_id, _ := c.GetInt64("good_id")
  7692. record_time, _ := c.GetInt64("record_time")
  7693. patient_id, _ := c.GetInt64("patient_id")
  7694. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7695. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7696. fmt.Print("err", err)
  7697. c.ServeSuccessJSON(map[string]interface{}{
  7698. "msg": "批量删除成功",
  7699. })
  7700. return
  7701. }
  7702. func (c *DialysisAPIController) BatchAdviceCheck() {
  7703. ids := c.GetString("ids")
  7704. idArray := strings.Split(ids, ",")
  7705. creator, _ := c.GetInt64("creator")
  7706. origin, _ := c.GetInt64("origin")
  7707. if origin == 1 {
  7708. err := service.BatchAdviceCheck(idArray, creator)
  7709. fmt.Println(err)
  7710. list, _ := service.GetAdviceExecutionById(idArray)
  7711. c.ServeSuccessJSON(map[string]interface{}{
  7712. "list": list,
  7713. })
  7714. return
  7715. }
  7716. if origin == 2 {
  7717. service.BatchHisAdviceCheck(idArray, creator)
  7718. list, _ := service.GetHisAdviceExecutionById(idArray)
  7719. c.ServeSuccessJSON(map[string]interface{}{
  7720. "list": list,
  7721. })
  7722. return
  7723. }
  7724. }
  7725. func (c *DialysisAPIController) BatchAdviceExecution() {
  7726. ids := c.GetString("ids")
  7727. idArray := strings.Split(ids, ",")
  7728. executionTime := c.GetString("execution_time")
  7729. creator, _ := c.GetInt64("creator")
  7730. timeLayout := "2006-01-02 15:04:05"
  7731. loc, _ := time.LoadLocation("Local")
  7732. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7733. orgin, _ := c.GetInt64("origin")
  7734. if orgin == 1 {
  7735. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7736. list, _ := service.GetAdviceExecutionById(idArray)
  7737. fmt.Println(err)
  7738. c.ServeSuccessJSON(map[string]interface{}{
  7739. "list": list,
  7740. })
  7741. return
  7742. }
  7743. if orgin == 2 {
  7744. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7745. list, _ := service.GetHisAdviceExecutionById(idArray)
  7746. fmt.Println(err)
  7747. c.ServeSuccessJSON(map[string]interface{}{
  7748. "list": list,
  7749. })
  7750. return
  7751. }
  7752. }
  7753. func (c *DialysisAPIController) UpdateStockGoods() {
  7754. good_id, _ := c.GetInt64("good_id")
  7755. record_time, _ := c.GetInt64("record_time")
  7756. patient_id, _ := c.GetInt64("patient_id")
  7757. count, _ := c.GetInt64("count")
  7758. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7759. fmt.Print("err", err)
  7760. c.ServeSuccessJSON(map[string]interface{}{
  7761. "msg": "更新成功",
  7762. })
  7763. return
  7764. }
  7765. // 当前数据比上一次出库数据少
  7766. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7767. //查询该患者当天已经出库的耗材信息
  7768. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7769. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7770. for i := len(goods_yc) - 1; i >= 0; i-- {
  7771. goods_yc_temp := goods_yc[i]
  7772. for j := len(goods) - 1; j >= 0; j-- {
  7773. goods_temp := goods[j]
  7774. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7775. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7776. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7777. if goods_yc_temp.Count == goods_temp.Count {
  7778. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7779. goods = append(goods[:j], goods[j+1:]...)
  7780. break
  7781. }
  7782. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7783. if goods_yc_temp.Count > goods_temp.Count {
  7784. temp_count := goods_yc_temp.Count - goods_temp.Count
  7785. goods_yc[i].Count = temp_count
  7786. goods = append(goods[:j], goods[j+1:]...)
  7787. break
  7788. }
  7789. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7790. if goods_yc_temp.Count < goods_temp.Count {
  7791. temp_count := goods_temp.Count - goods_yc_temp.Count
  7792. goods[j].Count = temp_count
  7793. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7794. break
  7795. }
  7796. }
  7797. }
  7798. }
  7799. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7800. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7801. //退库
  7802. if len(goods_yc) > 0 {
  7803. for _, good_yc := range goods_yc {
  7804. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7805. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7806. }
  7807. }
  7808. return nil
  7809. }
  7810. // 耗材出库删除
  7811. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7812. // 先根据相关信息查询当天该耗材的出库信息
  7813. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7814. if err != nil {
  7815. return err
  7816. }
  7817. var delete_count int64 = 0
  7818. delete_count = warehouseOutInfos.Count - count
  7819. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7820. // 在出库记录表里记录退库详情
  7821. warehouseOutInfo := &models.WarehouseOutInfo{
  7822. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7823. WarehouseOutId: warehouseOut.ID,
  7824. Status: 1,
  7825. Ctime: time.Now().Unix(),
  7826. OrgId: orgID,
  7827. Type: 1,
  7828. IsSys: 1,
  7829. SysRecordTime: record_time,
  7830. GoodTypeId: good_yc.GoodTypeId,
  7831. GoodId: good_yc.GoodId,
  7832. PatientId: good_yc.PatientId,
  7833. ConsumableType: 2,
  7834. StorehouseId: houseConfig.StorehouseOutInfo,
  7835. IsCheck: 1,
  7836. }
  7837. warehouseOutInfo.Count = count
  7838. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7839. warehouseOutInfo.Price = stockInInfo.Price
  7840. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7841. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7842. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7843. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7844. warehouseOutInfo.Number = warehouseOutInfos.Number
  7845. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7846. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7847. //查找当天是否存在出库记录
  7848. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7849. if errcod == gorm.ErrRecordNotFound {
  7850. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7851. //插入详情明细表
  7852. stockFlow := models.VmStockFlow{
  7853. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7854. WarehouseOutId: warehouseOut.ID,
  7855. GoodId: good_yc.GoodId,
  7856. Number: warehouseOutInfos.Number,
  7857. ProductDate: stockInInfo.ProductDate,
  7858. ExpireDate: stockInInfo.ExpiryDate,
  7859. Count: count,
  7860. Price: stockInInfo.Price,
  7861. Status: 1,
  7862. Ctime: time.Now().Unix(),
  7863. UserOrgId: good_yc.OrgId,
  7864. Manufacturer: stockInInfo.Manufacturer,
  7865. Dealer: stockInInfo.Dealer,
  7866. LicenseNumber: stockInInfo.LicenseNumber,
  7867. IsEdit: 2,
  7868. Creator: creater,
  7869. SystemTime: record_time,
  7870. ConsumableType: 3,
  7871. WarehousingDetailId: 0,
  7872. IsSys: 1,
  7873. UpdateCreator: creater,
  7874. PatientId: patient_id,
  7875. StorehouseId: houseConfig.StorehouseOutInfo,
  7876. }
  7877. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7878. if errflow == gorm.ErrRecordNotFound {
  7879. //创建流水表
  7880. err := service.CreateStockFlowOne(stockFlow)
  7881. fmt.Println("err", err)
  7882. } else if errflow == nil {
  7883. //插入详情明细表
  7884. stockFlow := models.VmStockFlow{
  7885. ID: exsit.ID,
  7886. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7887. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7888. WarehouseOutId: warehouseOut.ID,
  7889. GoodId: good_yc.GoodId,
  7890. Number: warehouseOutInfos.Number,
  7891. ProductDate: stockInInfo.ProductDate,
  7892. ExpireDate: stockInInfo.ExpiryDate,
  7893. Count: exsit.Count - delete_count,
  7894. Price: stockInInfo.Price,
  7895. Status: 1,
  7896. Ctime: time.Now().Unix(),
  7897. UserOrgId: good_yc.OrgId,
  7898. Manufacturer: stockInInfo.Manufacturer,
  7899. Dealer: stockInInfo.Dealer,
  7900. LicenseNumber: stockInInfo.LicenseNumber,
  7901. IsEdit: 2,
  7902. Creator: creater,
  7903. SystemTime: record_time,
  7904. ConsumableType: 3,
  7905. WarehousingDetailId: 0,
  7906. IsSys: 1,
  7907. UpdateCreator: creater,
  7908. PatientId: patient_id,
  7909. StorehouseId: houseConfig.StorehouseOutInfo,
  7910. }
  7911. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7912. }
  7913. if errOne != nil {
  7914. return errOne
  7915. }
  7916. } else if errcod == nil {
  7917. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7918. //插入详情明细表
  7919. stockFlow := models.VmStockFlow{
  7920. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7921. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7922. WarehouseOutId: warehouseOut.ID,
  7923. GoodId: good_yc.GoodId,
  7924. Number: warehouseOutInfos.Number,
  7925. ProductDate: stockInInfo.ProductDate,
  7926. ExpireDate: stockInInfo.ExpiryDate,
  7927. Count: count,
  7928. Price: stockInInfo.Price,
  7929. Status: 1,
  7930. Ctime: time.Now().Unix(),
  7931. UserOrgId: good_yc.OrgId,
  7932. Manufacturer: stockInInfo.Manufacturer,
  7933. Dealer: stockInInfo.Dealer,
  7934. LicenseNumber: stockInInfo.LicenseNumber,
  7935. IsEdit: 2,
  7936. Creator: creater,
  7937. SystemTime: record_time,
  7938. ConsumableType: 3,
  7939. WarehousingDetailId: 0,
  7940. IsSys: 1,
  7941. UpdateCreator: creater,
  7942. PatientId: patient_id,
  7943. ReturnCount: delete_count,
  7944. StorehouseId: houseConfig.StorehouseOutInfo,
  7945. }
  7946. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7947. if errflows == gorm.ErrRecordNotFound {
  7948. //创建流水表
  7949. service.CreateStockFlowOne(stockFlow)
  7950. } else if errflows == nil {
  7951. stockFlow := models.VmStockFlow{
  7952. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7953. ID: exsit.ID,
  7954. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7955. WarehouseOutId: warehouseOut.ID,
  7956. GoodId: good_yc.GoodId,
  7957. Number: warehouseOutInfos.Number,
  7958. ProductDate: stockInInfo.ProductDate,
  7959. ExpireDate: stockInInfo.ExpiryDate,
  7960. Count: exsit.Count - delete_count,
  7961. Price: stockInInfo.Price,
  7962. Status: 1,
  7963. Ctime: time.Now().Unix(),
  7964. UserOrgId: good_yc.OrgId,
  7965. Manufacturer: stockInInfo.Manufacturer,
  7966. Dealer: stockInInfo.Dealer,
  7967. LicenseNumber: stockInInfo.LicenseNumber,
  7968. IsEdit: 2,
  7969. Creator: creater,
  7970. SystemTime: record_time,
  7971. ConsumableType: 3,
  7972. WarehousingDetailId: 0,
  7973. IsSys: 1,
  7974. UpdateCreator: creater,
  7975. PatientId: patient_id,
  7976. ReturnCount: delete_count,
  7977. StorehouseId: houseConfig.StorehouseOutInfo,
  7978. }
  7979. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7980. }
  7981. }
  7982. //更改自动出库的表格
  7983. details := models.BloodAutomaticReduceDetail{
  7984. WarehouseOutId: warehouseOutInfo.ID,
  7985. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7986. PatientId: patient_id,
  7987. Ctime: time.Now().Unix(),
  7988. Mtime: time.Now().Unix(),
  7989. Status: 1,
  7990. RecordTime: record_time,
  7991. OrgId: orgID,
  7992. GoodId: good_yc.GoodId,
  7993. GoodTypeId: good_yc.GoodTypeId,
  7994. Count: count,
  7995. StorehouseId: houseConfig.StorehouseOutInfo,
  7996. }
  7997. //查询当天耗材是否已经存在数据
  7998. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7999. if errcode == gorm.ErrRecordNotFound {
  8000. errTwo := service.CreateAutoReduceRecord(&details)
  8001. if errTwo != nil {
  8002. return errTwo
  8003. }
  8004. } else if errcode == nil {
  8005. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8006. service.CreateAutoReduceRecord(&details)
  8007. }
  8008. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8009. //增加出库库存数量
  8010. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8011. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8012. fmt.Println("errOne", errOne)
  8013. // 删除出库完成后,要增加对应批次的库存数量
  8014. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8015. if errThree != nil {
  8016. return errThree
  8017. }
  8018. if good_yc.Count == 0 {
  8019. return nil
  8020. } else {
  8021. return errors.New("退库和出库数据不匹配")
  8022. }
  8023. }
  8024. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8025. //查询该患者当天已经出库的耗材信息
  8026. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8027. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8028. for i := len(goods_yc) - 1; i >= 0; i-- {
  8029. goods_yc_temp := goods_yc[i]
  8030. for j := len(goods) - 1; j >= 0; j-- {
  8031. goods_temp := goods[j]
  8032. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8033. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8034. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8035. if goods_yc_temp.Count == goods_temp.Count {
  8036. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8037. goods = append(goods[:j], goods[j+1:]...)
  8038. break
  8039. }
  8040. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8041. if goods_yc_temp.Count > goods_temp.Count {
  8042. temp_count := goods_yc_temp.Count - goods_temp.Count
  8043. goods_yc[i].Count = temp_count
  8044. goods = append(goods[:j], goods[j+1:]...)
  8045. break
  8046. }
  8047. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8048. if goods_yc_temp.Count < goods_temp.Count {
  8049. temp_count := goods_temp.Count - goods_yc_temp.Count
  8050. goods[j].Count = temp_count
  8051. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8052. break
  8053. }
  8054. }
  8055. }
  8056. }
  8057. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8058. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8059. fmt.Println("剩余需要出库的", len(goods))
  8060. if len(goods) > 0 {
  8061. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8062. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8063. if err == gorm.ErrRecordNotFound {
  8064. //没有记录,则创建出库单
  8065. timeStr := time.Now().Format("2006-01-02")
  8066. timeArr := strings.Split(timeStr, "-")
  8067. total, _ := service.FindAllWarehouseOut(orgID)
  8068. total = total + 1
  8069. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8070. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8071. number = number + total
  8072. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8073. warehouseOut := models.WarehouseOut{
  8074. WarehouseOutOrderNumber: warehousing_out_order,
  8075. OperationTime: time.Now().Unix(),
  8076. OrgId: orgID,
  8077. Creater: creater,
  8078. Ctime: time.Now().Unix(),
  8079. Status: 1,
  8080. WarehouseOutTime: record_time,
  8081. Dealer: 0,
  8082. Manufacturer: 0,
  8083. Type: 1,
  8084. IsSys: 1,
  8085. StorehouseId: houseConfig.StorehouseOutInfo,
  8086. IsCheck: 1,
  8087. }
  8088. err := service.AddSigleWarehouseOut(&warehouseOut)
  8089. if err != nil {
  8090. utils.TraceLog("创建出库单失败 err = %v", err)
  8091. return err
  8092. } else {
  8093. out = warehouseOut
  8094. }
  8095. }
  8096. for _, item := range goods {
  8097. var newCount int64 = 0
  8098. for _, it := range goodOne {
  8099. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8100. newCount = it.Count
  8101. }
  8102. }
  8103. prepare := models.DialysisBeforePrepare{
  8104. GoodTypeId: item.GoodTypeId,
  8105. GoodId: item.GoodId,
  8106. Count: item.Count,
  8107. StorehouseId: houseConfig.StorehouseOutInfo,
  8108. }
  8109. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8110. //增加出库数量
  8111. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8112. }
  8113. }
  8114. if len(goods_yc) > 0 {
  8115. for _, good_yc := range goods_yc {
  8116. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8117. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8118. }
  8119. }
  8120. return nil
  8121. }
  8122. // 耗材出库删除
  8123. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8124. // 先根据相关信息查询当天该耗材的出库信息
  8125. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8126. if err != nil {
  8127. return err
  8128. }
  8129. var delete_count int64 = 0
  8130. for _, ware := range warehouseOutInfos {
  8131. // 判断当前出库的数据和删除出库数量
  8132. if good_yc.Count <= ware.Count {
  8133. delete_count = good_yc.Count
  8134. } else {
  8135. delete_count = ware.Count
  8136. }
  8137. warehouseOutInfo := &models.WarehouseOutInfo{
  8138. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8139. WarehouseOutId: warehouseOut.ID,
  8140. Status: 1,
  8141. Ctime: time.Now().Unix(),
  8142. Remark: "",
  8143. OrgId: orgID,
  8144. Type: 1,
  8145. Manufacturer: 0,
  8146. Dealer: 0,
  8147. IsSys: 0,
  8148. SysRecordTime: record_time,
  8149. GoodTypeId: good_yc.GoodTypeId,
  8150. GoodId: good_yc.GoodId,
  8151. StorehouseId: warehouseOut.StorehouseId,
  8152. IsCheck: 1,
  8153. }
  8154. warehouseOutInfo.Count = delete_count
  8155. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8156. warehouseOutInfo.Price = stockInInfo.Price
  8157. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8158. if errOne != nil {
  8159. return errOne
  8160. }
  8161. // 删除出库完成后,要改变流水库存(有疑问)
  8162. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8163. fmt.Println("errOne", errOne)
  8164. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8165. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8166. //扣减出库数量
  8167. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8168. if errThree != nil {
  8169. return errThree
  8170. }
  8171. }
  8172. if good_yc.Count == 0 {
  8173. return nil
  8174. } else {
  8175. return errors.New("退库和出库数据不匹配")
  8176. }
  8177. }
  8178. func (this *DialysisAPIController) GetMobileScheduleList() {
  8179. limit, _ := this.GetInt64("limit")
  8180. page, _ := this.GetInt64("page")
  8181. type_options_visible, _ := this.GetInt64("type_options_visible")
  8182. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8183. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8184. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8185. }
  8186. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8187. newArr = make([]*models.HisPrescriptionProject, 0)
  8188. for i := 0; i < len(arr); i++ {
  8189. repeat := false
  8190. for j := i + 1; j < len(arr); j++ {
  8191. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8192. repeat = true
  8193. break
  8194. }
  8195. }
  8196. if !repeat {
  8197. newArr = append(newArr, arr[i])
  8198. }
  8199. }
  8200. return
  8201. }
  8202. func (this *DialysisAPIController) GetRoleList() {
  8203. admin_user_id, _ := this.GetInt64("admin_user_id")
  8204. orgid := this.GetMobileAdminUserInfo().Org.Id
  8205. list, err := service.GetRoleList(orgid, admin_user_id)
  8206. fmt.Println(err)
  8207. this.ServeSuccessJSON(map[string]interface{}{
  8208. "list": list,
  8209. })
  8210. return
  8211. }
  8212. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8213. // 先根据相关信息查询当天该耗材的出库信息
  8214. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8215. if err != nil {
  8216. return err
  8217. }
  8218. var delete_count int64 = 0
  8219. delete_count = warehouseOutInfos.Count - count
  8220. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8221. // 删除出库完成后,要增加对应批次的库存数量
  8222. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8223. if errThree != nil {
  8224. return errThree
  8225. }
  8226. //增加退库数量
  8227. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8228. //扣减出库数量
  8229. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8230. //查询剩余库存
  8231. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8232. var sum_count int64
  8233. for _, item := range goodList {
  8234. sum_count += item.StockCount
  8235. }
  8236. // 在出库记录表里记录退库详情
  8237. warehouseOutInfo := &models.WarehouseOutInfo{
  8238. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8239. WarehouseOutId: warehouseOut.ID,
  8240. Status: 1,
  8241. Ctime: time.Now().Unix(),
  8242. OrgId: orgID,
  8243. Type: 1,
  8244. IsSys: 1,
  8245. SysRecordTime: record_time,
  8246. GoodTypeId: good_yc.GoodTypeId,
  8247. GoodId: good_yc.GoodId,
  8248. PatientId: good_yc.PatientId,
  8249. ConsumableType: 2,
  8250. StorehouseId: houseConfig.StorehouseOutInfo,
  8251. IsCheck: 1,
  8252. OverCount: sum_count,
  8253. }
  8254. warehouseOutInfo.Count = count
  8255. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8256. warehouseOutInfo.Price = stockInInfo.Price
  8257. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8258. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8259. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8260. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8261. warehouseOutInfo.Number = warehouseOutInfos.Number
  8262. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8263. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8264. //查找当天是否存在出库记录
  8265. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8266. if errcod == gorm.ErrRecordNotFound {
  8267. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8268. //插入详情明细表
  8269. if errOne != nil {
  8270. return errOne
  8271. }
  8272. //插入详情明细表
  8273. stockFlow := models.VmStockFlow{
  8274. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8275. WarehouseOutId: warehouseOut.ID,
  8276. GoodId: good_yc.GoodId,
  8277. Number: warehouseOutInfos.Number,
  8278. ProductDate: stockInInfo.ProductDate,
  8279. ExpireDate: stockInInfo.ExpiryDate,
  8280. Count: count,
  8281. Price: stockInInfo.Price,
  8282. Status: 1,
  8283. Ctime: record_time,
  8284. UserOrgId: good_yc.OrgId,
  8285. Manufacturer: stockInInfo.Manufacturer,
  8286. Dealer: stockInInfo.Dealer,
  8287. LicenseNumber: stockInInfo.LicenseNumber,
  8288. IsEdit: 2,
  8289. Creator: creater,
  8290. SystemTime: record_time,
  8291. ConsumableType: 3,
  8292. WarehousingDetailId: 0,
  8293. IsSys: 1,
  8294. UpdateCreator: creater,
  8295. PatientId: patient_id,
  8296. StorehouseId: houseConfig.StorehouseOutInfo,
  8297. OverCount: sum_count,
  8298. ProjectId: good_yc.ProjectId,
  8299. }
  8300. err := service.CreateStockFlowOne(stockFlow)
  8301. fmt.Println("err", err)
  8302. } else if errcod == nil {
  8303. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8304. }
  8305. //创建退库单
  8306. operation_time := time.Now().Unix()
  8307. //创建退库单
  8308. timeStr := time.Now().Format("2006-01-02")
  8309. timeArr := strings.Split(timeStr, "-")
  8310. total, _ := service.FindAllCancelStockTotal(orgID)
  8311. total = total + 1
  8312. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8313. cancelStock := models.CancelStock{
  8314. OrderNumber: orderNumber,
  8315. OperaTime: operation_time,
  8316. OrgId: orgID,
  8317. Creater: warehouseOut.Creater,
  8318. Ctime: time.Now().Unix(),
  8319. Status: 1,
  8320. ReturnTime: record_time,
  8321. Type: 1,
  8322. StorehouseId: stockInInfo.StorehouseId,
  8323. IsCheck: 1,
  8324. }
  8325. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8326. if msgerrkonde == gorm.ErrRecordNotFound {
  8327. service.AddSigleCancelStock(&cancelStock)
  8328. }
  8329. cancel, _ := service.GetLastCancelStockById(orgID)
  8330. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8331. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8332. cancelStockInfo := models.CancelStockInfo{
  8333. GoodId: stockInInfo.GoodId,
  8334. CancelStockId: cancel.ID,
  8335. GoodTypeId: stockInInfo.GoodTypeId,
  8336. Count: delete_count,
  8337. Price: stockInInfo.PackingPrice,
  8338. Total: 0,
  8339. ProductDate: stockInInfo.ProductDate,
  8340. ExpiryDate: stockInInfo.ExpiryDate,
  8341. Ctime: record_time,
  8342. Status: 1,
  8343. OrgId: orgID,
  8344. OrderNumber: cancel.OrderNumber,
  8345. Type: 0,
  8346. Dealer: deaerler.DealerName,
  8347. Manufacturer: manufacturer.ManufacturerName,
  8348. Number: stockInInfo.Number,
  8349. RegisterAccount: "",
  8350. Remark: "",
  8351. WarehouseInfoId: stockInInfo.ID,
  8352. PatientId: patient_id,
  8353. RecordDate: record_time,
  8354. StorehouseId: stockInInfo.StorehouseId,
  8355. IsCheck: 1,
  8356. }
  8357. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8358. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8359. flow := models.VmStockFlow{
  8360. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8361. GoodId: good_yc.GoodId,
  8362. Number: warehouseOutInfos.Number,
  8363. LicenseNumber: stockInInfo.LicenseNumber,
  8364. Count: delete_count,
  8365. UserOrgId: orgID,
  8366. PatientId: patient_id,
  8367. SystemTime: record_time,
  8368. ConsumableType: 7,
  8369. IsSys: 0,
  8370. WarehousingOrder: "",
  8371. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8372. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8373. IsEdit: 0,
  8374. CancelStockId: cancel.ID,
  8375. CancelOrderNumber: cancel.OrderNumber,
  8376. Manufacturer: manufacturer.ID,
  8377. Dealer: 0,
  8378. Creator: warehouseOut.Creater,
  8379. UpdateCreator: 0,
  8380. Status: 1,
  8381. Ctime: record_time,
  8382. Mtime: 0,
  8383. Price: stockInInfo.Price,
  8384. WarehousingDetailId: stockInInfo.ID,
  8385. WarehouseOutDetailId: warehouseOutInfos.ID,
  8386. CancelOutDetailId: cancelInfo.ID,
  8387. ProductDate: stockInInfo.ProductDate,
  8388. ExpireDate: stockInInfo.ExpiryDate,
  8389. StorehouseId: houseConfig.StorehouseOutInfo,
  8390. OverCount: sum_count,
  8391. }
  8392. service.CreateStockFlowOne(flow)
  8393. //更改自动出库的表格
  8394. details := models.BloodAutomaticReduceDetail{
  8395. WarehouseOutId: warehouseOutInfo.ID,
  8396. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8397. PatientId: patient_id,
  8398. Ctime: time.Now().Unix(),
  8399. Mtime: time.Now().Unix(),
  8400. Status: 1,
  8401. RecordTime: record_time,
  8402. OrgId: orgID,
  8403. GoodId: good_yc.GoodId,
  8404. GoodTypeId: good_yc.GoodTypeId,
  8405. Count: count,
  8406. StorehouseId: houseConfig.StorehouseOutInfo,
  8407. }
  8408. //查询当天耗材是否已经存在数据
  8409. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8410. if errcode == gorm.ErrRecordNotFound {
  8411. errTwo := service.CreateAutoReduceRecord(&details)
  8412. if errTwo != nil {
  8413. return errTwo
  8414. }
  8415. } else if errcode == nil {
  8416. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8417. service.CreateAutoReduceRecord(&details)
  8418. }
  8419. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8420. //增加出库库存数量
  8421. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8422. if good_yc.Count == 0 {
  8423. return nil
  8424. } else {
  8425. return errors.New("退库和出库数据不匹配")
  8426. }
  8427. }
  8428. func (this *DialysisAPIController) SavePatientSign() {
  8429. adminUserInfo := this.GetMobileAdminUserInfo()
  8430. patient_id, _ := this.GetInt64("patient_id")
  8431. dialysis_date, _ := this.GetInt64("dialysis_date")
  8432. orgid := adminUserInfo.Org.Id
  8433. var esdata models.DialysisOrder
  8434. var err error
  8435. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8437. return
  8438. }
  8439. esdata.Hash = esdata.Hash
  8440. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8441. order := models.DialysisOrder{
  8442. Hash: esdata.Hash,
  8443. Url: esdata.Url,
  8444. }
  8445. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8446. redis := service.RedisClient()
  8447. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8448. redis.Set(key, "", time.Second)
  8449. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8450. //清空key 值
  8451. redis.Set(keyOne, "", time.Second)
  8452. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8453. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8454. //redis.Set(keyTwo, "", time.Second)
  8455. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8456. redis.Set(keyThree, "", time.Second)
  8457. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8458. redis.Set(keyFour, "", time.Second)
  8459. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8460. redis.Set(keyFive, "", time.Second)
  8461. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8462. redis.Set(keySix, "", time.Second)
  8463. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8464. redis.Set(keySeven, "", time.Second)
  8465. if err != nil {
  8466. fmt.Println(err)
  8467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8468. return
  8469. }
  8470. this.ServeSuccessJSON(map[string]interface{}{
  8471. "electronic_signature": esdata,
  8472. })
  8473. }
  8474. func (this *DialysisAPIController) GetPatientSign() {
  8475. patient_id, _ := this.GetInt64("patient_id")
  8476. dialysis_date, _ := this.GetInt64("dialysis_date")
  8477. adminUserInfo := this.GetMobileAdminUserInfo()
  8478. orgId := adminUserInfo.Org.Id
  8479. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8480. if err != nil {
  8481. fmt.Println(err)
  8482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8483. return
  8484. }
  8485. this.ServeSuccessJSON(map[string]interface{}{
  8486. "dialysisOrder": dialysisOrder,
  8487. })
  8488. }
  8489. func (this *DialysisAPIController) GetScheduleByPatient() {
  8490. patient_id, _ := this.GetInt64("patient_id")
  8491. schedule_date, _ := this.GetInt64("schedule_date")
  8492. orgid := this.GetMobileAdminUserInfo().Org.Id
  8493. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8494. this.ServeSuccessJSON(map[string]interface{}{
  8495. "schedule": schedule,
  8496. })
  8497. }
  8498. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8499. org_id := this.GetMobileAdminUserInfo().Org.Id
  8500. patient_id, _ := this.GetInt64("patient_id")
  8501. schedule_date, _ := this.GetInt64("schedule_date")
  8502. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8503. this.ServeSuccessJSON(map[string]interface{}{
  8504. "order": order,
  8505. })
  8506. }
  8507. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8508. org_id := this.GetMobileAdminUserInfo().Org.Id
  8509. schedule_date := this.GetString("schedule_date")
  8510. schedule_type, _ := this.GetInt64("schedule_type")
  8511. timeLayout := "2006-01-02"
  8512. loc, _ := time.LoadLocation("Local")
  8513. var startdateunix int64
  8514. if len(schedule_date) > 0 {
  8515. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8516. if err != nil {
  8517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8518. return
  8519. }
  8520. startdateunix = theTime.Unix()
  8521. }
  8522. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8523. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8524. devices, _ := service.GetAllDevicetByListSix(org_id)
  8525. for key, item := range scheduals {
  8526. // 床位信息
  8527. for _, device := range devices {
  8528. if item.BedId == device.ID {
  8529. scheduals[key].DeviceNumber = device
  8530. break
  8531. }
  8532. }
  8533. }
  8534. this.ServeSuccessJSON(map[string]interface{}{
  8535. "list": list,
  8536. "scheduals": scheduals,
  8537. })
  8538. }
  8539. func (this *DialysisAPIController) SavePatientPicture() {
  8540. patient_id, _ := this.GetInt64("patient_id")
  8541. dialysis_date, _ := this.GetInt64("schedule_date")
  8542. avatar := this.GetString("avatar")
  8543. fmt.Println("patient_id", patient_id)
  8544. orgId := this.GetMobileAdminUserInfo().Org.Id
  8545. order := models.DialysisOrder{
  8546. Url: avatar,
  8547. }
  8548. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8549. redis := service.RedisClient()
  8550. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8551. redis.Set(key, "", time.Second)
  8552. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8553. //清空key 值
  8554. redis.Set(keyOne, "", time.Second)
  8555. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8556. redis.Set(keyThree, "", time.Second)
  8557. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8558. redis.Set(keyFour, "", time.Second)
  8559. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8560. redis.Set(keyFive, "", time.Second)
  8561. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8562. redis.Set(keySix, "", time.Second)
  8563. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8564. redis.Set(keySeven, "", time.Second)
  8565. if err != nil {
  8566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8567. return
  8568. }
  8569. this.ServeSuccessJSON(map[string]interface{}{
  8570. "order": order,
  8571. })
  8572. }
  8573. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8574. ids := this.GetString("ids")
  8575. idSplit := strings.Split(ids, ",")
  8576. orgId := this.GetMobileAdminUserInfo().Org.Id
  8577. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8578. execution_time := this.GetString("exce_time")
  8579. timeLayout2 := "2006-01-02 15:04:05"
  8580. loc, _ := time.LoadLocation("Local")
  8581. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8582. if errs != nil {
  8583. utils.ErrorLog(errs.Error())
  8584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8585. return
  8586. }
  8587. //his客户
  8588. if config.IsOpen == 1 {
  8589. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8590. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8591. for _, item := range list {
  8592. for _, it := range adviceList {
  8593. if item.DrugId == it.DrugId {
  8594. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8595. }
  8596. }
  8597. }
  8598. for _, item := range list {
  8599. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8600. var sum_out_count int64
  8601. for _, itemThree := range item.ChildDoctorAdvice {
  8602. var prescribing_number int64
  8603. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8604. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8605. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8606. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8607. }
  8608. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8609. prescribing_number = parseIntPrescribingNumber
  8610. }
  8611. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8612. prescribing_number = parseIntPrescribingNumber
  8613. }
  8614. sum_out_count += prescribing_number
  8615. }
  8616. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8617. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8618. //库存不足
  8619. if sum_out_count > drugStockOut.FlushCount {
  8620. this.ServeSuccessJSON(map[string]interface{}{
  8621. "msg": "2",
  8622. "drug": medical,
  8623. "ids": ids,
  8624. })
  8625. return
  8626. }
  8627. }
  8628. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8629. //执行医嘱
  8630. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8631. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8632. for _, item := range advices {
  8633. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8634. redis := service.RedisClient()
  8635. //清空key 值
  8636. redis.Set(key, "", time.Second)
  8637. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8638. redis.Set(keyTwo, "", time.Second)
  8639. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8640. redis.Set(keyThree, "", time.Second)
  8641. recordDate := theTime.Format("2006-01-02")
  8642. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8643. redis.Set(keyFour, "", time.Second)
  8644. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8645. redis.Set(keyFive, "", time.Second)
  8646. defer redis.Close()
  8647. }
  8648. if errs == nil {
  8649. //药品管理信息
  8650. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8651. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8652. if drugStockConfig.IsOpen == 1 {
  8653. for _, item := range advices {
  8654. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8655. config, _ := service.GetDrugOpenConfigOne(orgId)
  8656. if config.IsOpen != 1 {
  8657. //查询该药品是否有库存
  8658. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8659. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8660. if medical.IsUse == 2 {
  8661. if config.IsOpen != 1 {
  8662. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8663. service.HisDrugsDelivery(orgId, creater, &advice)
  8664. if orgId == 3877 || orgId == 10265 {
  8665. //查询该药品是否有出库记录
  8666. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8667. if len(flowMap) == 0 {
  8668. errs := service.UpdateHisAdviceById(advice.ID)
  8669. if errs != nil {
  8670. drugError := models.XtDrugError{
  8671. UserOrgId: orgId,
  8672. DrugId: item.DrugId,
  8673. RecordDate: item.AdviceDate,
  8674. PatientId: item.PatientId,
  8675. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8676. Status: 1,
  8677. Ctime: time.Now().Unix(),
  8678. Mtime: 0,
  8679. SumCount: 0,
  8680. Prescribingnumber: advice.PrescribingNumber,
  8681. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8682. }
  8683. service.CreateDrugError(drugError)
  8684. }
  8685. this.ServeSuccessJSON(map[string]interface{}{
  8686. "msg": "2",
  8687. "drug": medical,
  8688. "ids": ids,
  8689. })
  8690. return
  8691. }
  8692. }
  8693. }
  8694. if pharmacyConfig.IsOpen != 1 {
  8695. service.HisDrugsDelivery(orgId, creater, &advice)
  8696. if orgId == 3877 || orgId == 10265 {
  8697. //查询该药品是否有出库记录
  8698. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8699. if len(flowMap) == 0 {
  8700. errs := service.UpdateHisAdviceById(advice.ID)
  8701. if errs != nil {
  8702. drugError := models.XtDrugError{
  8703. UserOrgId: orgId,
  8704. DrugId: item.DrugId,
  8705. RecordDate: item.AdviceDate,
  8706. PatientId: item.PatientId,
  8707. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8708. Status: 1,
  8709. Ctime: time.Now().Unix(),
  8710. Mtime: 0,
  8711. SumCount: 0,
  8712. Prescribingnumber: advice.PrescribingNumber,
  8713. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8714. }
  8715. service.CreateDrugError(drugError)
  8716. }
  8717. this.ServeSuccessJSON(map[string]interface{}{
  8718. "msg": "2",
  8719. "drug": medical,
  8720. "ids": ids,
  8721. })
  8722. return
  8723. }
  8724. }
  8725. }
  8726. //更新字典里面的库存
  8727. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8728. var sum_count int64
  8729. for _, its := range stockInfo {
  8730. if its.MaxUnit == medical.MaxUnit {
  8731. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8732. }
  8733. sum_count += its.StockMaxNumber + its.StockMinNumber
  8734. }
  8735. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8736. //剩余库存
  8737. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8738. }
  8739. }
  8740. }
  8741. }
  8742. }
  8743. this.ServeSuccessJSON(map[string]interface{}{
  8744. "msg": "1",
  8745. "ids": ids,
  8746. })
  8747. return
  8748. } else {
  8749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8750. }
  8751. }
  8752. //血透客户
  8753. if config.IsOpen == 2 || config.IsOpen == 0 {
  8754. //药品管理信息
  8755. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8756. if drugStockConfig.IsOpen == 1 {
  8757. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8758. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8759. for _, item := range list {
  8760. for _, it := range adviceList {
  8761. if item.DrugId == it.DrugId {
  8762. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8763. }
  8764. }
  8765. }
  8766. for _, item := range list {
  8767. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8768. var sum_out_count int64
  8769. for _, itemThree := range item.ChildDoctorAdvice {
  8770. var prescribing_number int64
  8771. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8772. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8773. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8774. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8775. }
  8776. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8777. prescribing_number = parseIntPrescribingNumber
  8778. }
  8779. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8780. prescribing_number = parseIntPrescribingNumber
  8781. }
  8782. sum_out_count += prescribing_number
  8783. }
  8784. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8785. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8786. //库存不足
  8787. if sum_out_count > drugStockOut.FlushCount {
  8788. this.ServeSuccessJSON(map[string]interface{}{
  8789. "msg": "2",
  8790. "drug": medical,
  8791. "ids": ids,
  8792. })
  8793. return
  8794. }
  8795. }
  8796. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8797. //执行医嘱
  8798. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8799. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8800. for _, item := range advices {
  8801. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8802. redis := service.RedisClient()
  8803. //清空key 值
  8804. redis.Set(key, "", time.Second)
  8805. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8806. redis.Set(keyTwo, "", time.Second)
  8807. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8808. redis.Set(keyThree, "", time.Second)
  8809. recordDate := theTime.Format("2006-01-02")
  8810. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8811. redis.Set(keyFour, "", time.Second)
  8812. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8813. redis.Set(keyFive, "", time.Second)
  8814. defer redis.Close()
  8815. }
  8816. if errs == nil {
  8817. for _, item := range advices {
  8818. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8819. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8820. //查询是否出库按钮开启
  8821. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8822. if adviceSetting.IsAdviceOpen == 1 {
  8823. //查询是否出库按钮开启
  8824. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8825. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8826. if prescriptionConfig.IsOpen == 1 {
  8827. if medical.IsUse == 2 {
  8828. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8829. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8830. }
  8831. if pharmacyConfig.IsOpen != 1 {
  8832. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8833. }
  8834. //更新字典里面的库存
  8835. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8836. var sum_count int64
  8837. for _, its := range stockInfo {
  8838. if its.MaxUnit == medical.MaxUnit {
  8839. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8840. }
  8841. sum_count += its.StockMaxNumber + its.StockMinNumber
  8842. }
  8843. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8844. //剩余库存
  8845. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8846. }
  8847. }
  8848. } else {
  8849. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8850. if medical.IsUse == 2 {
  8851. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8852. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8853. }
  8854. if pharmacyConfig.IsOpen != 1 {
  8855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8856. }
  8857. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8858. var sum_count int64
  8859. for _, its := range stockInfo {
  8860. if its.MaxUnit == medical.MaxUnit {
  8861. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8862. }
  8863. sum_count += its.StockMaxNumber + its.StockMinNumber
  8864. }
  8865. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8866. //剩余库存
  8867. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8868. }
  8869. }
  8870. }
  8871. }
  8872. this.ServeSuccessJSON(map[string]interface{}{
  8873. "msg": "1",
  8874. "ids": ids,
  8875. })
  8876. return
  8877. } else {
  8878. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8879. //执行医嘱
  8880. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8881. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8882. for _, item := range advices {
  8883. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8884. redis := service.RedisClient()
  8885. //清空key 值
  8886. redis.Set(key, "", time.Second)
  8887. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8888. redis.Set(keyTwo, "", time.Second)
  8889. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8890. redis.Set(keyThree, "", time.Second)
  8891. recordDate := theTime.Format("2006-01-02")
  8892. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8893. redis.Set(keyFour, "", time.Second)
  8894. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8895. redis.Set(keyFive, "", time.Second)
  8896. defer redis.Close()
  8897. }
  8898. this.ServeSuccessJSON(map[string]interface{}{
  8899. "msg": "1",
  8900. "ids": ids,
  8901. })
  8902. return
  8903. }
  8904. }
  8905. }
  8906. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8907. ids := this.GetString("ids")
  8908. idSplit := strings.Split(ids, ",")
  8909. orgId := this.GetMobileAdminUserInfo().Org.Id
  8910. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8911. if config.IsOpen == 1 {
  8912. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8913. this.ServeSuccessJSON(map[string]interface{}{
  8914. "msg": "1",
  8915. "ids": ids,
  8916. })
  8917. return
  8918. }
  8919. if config.IsOpen == 0 || config.IsOpen == 2 {
  8920. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8921. this.ServeSuccessJSON(map[string]interface{}{
  8922. "msg": "1",
  8923. "ids": ids,
  8924. })
  8925. return
  8926. }
  8927. }
  8928. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8929. ids := this.GetString("ids")
  8930. idSplit := strings.Split(ids, ",")
  8931. orgId := this.GetMobileAdminUserInfo().Org.Id
  8932. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8933. //his
  8934. if config.IsOpen == 1 {
  8935. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8936. theTime := time.Now()
  8937. advices := models.HisDoctorAdviceThirty{
  8938. CheckTime: theTime.Unix(),
  8939. Checker: checker,
  8940. UpdatedTime: time.Now().Unix(),
  8941. }
  8942. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8943. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8944. for _, item := range list {
  8945. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8946. redis := service.RedisClient()
  8947. //清空key 值
  8948. redis.Set(key, "", time.Second)
  8949. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8950. redis.Set(keyTwo, "", time.Second)
  8951. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8952. redis.Set(keyThree, "", time.Second)
  8953. recordDate := theTime.Format("2006-01-02")
  8954. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8955. redis.Set(keyFour, "", time.Second)
  8956. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8957. redis.Set(keyFive, "", time.Second)
  8958. defer redis.Close()
  8959. }
  8960. this.ServeSuccessJSON(map[string]interface{}{
  8961. "msg": "1",
  8962. "ids": ids,
  8963. })
  8964. return
  8965. }
  8966. //血透
  8967. if config.IsOpen == 0 || config.IsOpen == 2 {
  8968. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8969. theTime := time.Now()
  8970. advices := models.DoctorAdvice{
  8971. CheckTime: theTime.Unix(),
  8972. Checker: checker,
  8973. UpdatedTime: time.Now().Unix(),
  8974. }
  8975. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8976. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8977. for _, item := range list {
  8978. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8979. redis := service.RedisClient()
  8980. //清空key 值
  8981. redis.Set(key, "", time.Second)
  8982. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8983. redis.Set(keyTwo, "", time.Second)
  8984. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8985. redis.Set(keyThree, "", time.Second)
  8986. recordDate := theTime.Format("2006-01-02")
  8987. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8988. redis.Set(keyFour, "", time.Second)
  8989. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8990. redis.Set(keyFive, "", time.Second)
  8991. defer redis.Close()
  8992. }
  8993. this.ServeSuccessJSON(map[string]interface{}{
  8994. "msg": "1",
  8995. "ids": ids,
  8996. })
  8997. return
  8998. }
  8999. }
  9000. func (this *DialysisAPIController) CheckSchedule() {
  9001. patientID, _ := this.GetInt64("patient_id")
  9002. recordDateStr := this.GetString("record_date")
  9003. nurseID, _ := this.GetInt64("start_nurse")
  9004. schedual_type, _ := this.GetInt64("schedual_type")
  9005. bedID, _ := this.GetInt64("bed")
  9006. start_time := this.GetString("start_time")
  9007. fmt.Println("patientID", patientID)
  9008. fmt.Println("recordDateStr", recordDateStr)
  9009. fmt.Println("nurseID", nurseID)
  9010. fmt.Println("schedual_type------", schedual_type)
  9011. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9013. return
  9014. }
  9015. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9016. if parseStartDateErr != nil {
  9017. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9019. return
  9020. }
  9021. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9022. if parseErr != nil {
  9023. this.ErrorLog("时间解析失败:%v", parseErr)
  9024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9025. return
  9026. }
  9027. adminUserInfo := this.GetMobileAdminUserInfo()
  9028. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9029. if getPatientErr != nil {
  9030. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9032. return
  9033. } else if patient == nil {
  9034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9035. return
  9036. }
  9037. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9038. if getNurseErr != nil {
  9039. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9041. return
  9042. } else if nurse == nil {
  9043. this.ErrorLog("护士不存在")
  9044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9045. return
  9046. }
  9047. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9048. if getDeviceNumberErr != nil {
  9049. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9051. return
  9052. } else if deviceNumber == nil {
  9053. this.ErrorLog("床位号不存在")
  9054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9055. return
  9056. }
  9057. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9058. if getRecordErr != nil {
  9059. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9061. return
  9062. } else if dialysisRecord != nil {
  9063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9064. return
  9065. }
  9066. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9067. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9068. timeLayout := "2006-01-02 15:04:05"
  9069. loc, _ := time.LoadLocation("Local")
  9070. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9071. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9072. schedulestartTime := theStartTime.Unix()
  9073. scheduleendTime := theEndTime.Unix()
  9074. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9075. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9076. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9077. //查询该床位是否有人用了
  9078. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9079. if err == nil {
  9080. if schedule.ID == 0 {
  9081. this.ServeSuccessJSON(map[string]interface{}{
  9082. "status": 0,
  9083. "msg": "请求失败",
  9084. })
  9085. } else {
  9086. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9087. if order.ID > 0 { //该机位被其他人占用了
  9088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9089. return
  9090. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9091. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9092. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9093. this.ServeSuccessJSON(map[string]interface{}{
  9094. "status": 1,
  9095. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9096. })
  9097. return
  9098. } else {
  9099. this.ServeSuccessJSON(map[string]interface{}{
  9100. "status": 0,
  9101. "msg": "",
  9102. })
  9103. }
  9104. }
  9105. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9106. this.ServeSuccessJSON(map[string]interface{}{
  9107. "status": 2,
  9108. "msg": "当前机位已有患者在使用,请重新选择!",
  9109. })
  9110. }
  9111. }
  9112. } else {
  9113. this.ServeSuccessJSON(map[string]interface{}{
  9114. "status": 0,
  9115. "msg": "",
  9116. })
  9117. }
  9118. }
  9119. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9120. orgId := this.GetMobileAdminUserInfo().Org.Id
  9121. schedule_type, _ := this.GetInt64("schedule_type")
  9122. partion_type, _ := this.GetInt64("partion_type")
  9123. start_time := this.GetString("start_time")
  9124. timeLayout := "2006-01-02"
  9125. loc, _ := time.LoadLocation("Local")
  9126. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9127. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9128. _, config := service.FindXTHisRecordByOrgId(orgId)
  9129. appId := this.GetMobileAdminUserInfo().App.Id
  9130. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9131. if err == nil {
  9132. this.ServeSuccessJSON(map[string]interface{}{
  9133. "list": list,
  9134. "config": config,
  9135. "doctorList": doctorList,
  9136. })
  9137. return
  9138. } else {
  9139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9140. return
  9141. }
  9142. }
  9143. func (this *DialysisAPIController) SaveMobileInformation() {
  9144. patient_id, _ := this.GetInt64("patient_id")
  9145. record_date, _ := this.GetInt64("record_date")
  9146. startTime := this.GetString("start_time")
  9147. module, _ := this.GetInt64("module")
  9148. remark := this.GetString("remark")
  9149. timeLayout := "2006-01-02 15:04"
  9150. loc, _ := time.LoadLocation("Local")
  9151. if len(startTime) == 0 {
  9152. utils.ErrorLog("len(start_time) == 0")
  9153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9154. return
  9155. }
  9156. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9157. if err != nil {
  9158. utils.ErrorLog(err.Error())
  9159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9160. return
  9161. }
  9162. StartTime := theTime.Unix()
  9163. fmt.Println("startime-------------", StartTime)
  9164. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9165. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9166. information := models.XtDialysisInformation{
  9167. Module: module,
  9168. PatientId: patient_id,
  9169. RecordDate: record_date,
  9170. ApplicationDate: StartTime,
  9171. Creater: creater,
  9172. ApplicationStatus: 2,
  9173. Checker: 0,
  9174. CheckTime: 0,
  9175. Remark: remark,
  9176. UserOrgId: user_org_id,
  9177. Ctime: time.Now().Unix(),
  9178. Status: 1,
  9179. Mtime: 0,
  9180. }
  9181. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9182. if infor.ID == 0 {
  9183. service.SaveDialysisInformation(information)
  9184. }
  9185. if infor.ID > 0 {
  9186. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9187. }
  9188. this.ServeSuccessJSON(map[string]interface{}{
  9189. "information": information,
  9190. })
  9191. return
  9192. }
  9193. func (this *DialysisAPIController) GetMobileInformation() {
  9194. limit, _ := this.GetInt64("limit")
  9195. page, _ := this.GetInt64("page")
  9196. orgid := this.GetMobileAdminUserInfo().Org.Id
  9197. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9198. appid := this.GetMobileAdminUserInfo().App.Id
  9199. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9200. patients, _ := service.GetAllpatientThirty(orgid)
  9201. this.ServeSuccessJSON(map[string]interface{}{
  9202. "information": information,
  9203. "total": total,
  9204. "doclist": doclist,
  9205. "patients": patients,
  9206. })
  9207. return
  9208. }
  9209. func (this *DialysisAPIController) GetMobileInformationOne() {
  9210. limit, _ := this.GetInt64("limit")
  9211. page, _ := this.GetInt64("page")
  9212. orgid := this.GetMobileAdminUserInfo().Org.Id
  9213. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9214. appid := this.GetMobileAdminUserInfo().App.Id
  9215. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9216. patients, _ := service.GetAllpatientThirty(orgid)
  9217. this.ServeSuccessJSON(map[string]interface{}{
  9218. "information": information,
  9219. "total": total,
  9220. "doclist": doclist,
  9221. "patients": patients,
  9222. })
  9223. return
  9224. }
  9225. func (this *DialysisAPIController) CheckMobileInformation() {
  9226. id, _ := this.GetInt64("id")
  9227. application_status, _ := this.GetInt64("application_status")
  9228. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9229. checktime := time.Now().Unix()
  9230. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9231. if err == nil {
  9232. this.ServeSuccessJSON(map[string]interface{}{
  9233. "msg": "ok",
  9234. })
  9235. return
  9236. }
  9237. }
  9238. func (c *DialysisAPIController) GetControlMonitorList() {
  9239. partition, _ := c.GetInt64("partition")
  9240. monitorDate := c.GetString("date")
  9241. patient_id, _ := c.GetInt64("patient_id")
  9242. pat_type, _ := c.GetInt64("pat_type")
  9243. timeLayout := "2006-01-02"
  9244. loc, _ := time.LoadLocation("Local")
  9245. var theStartTime int64
  9246. if len(monitorDate) > 0 {
  9247. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9248. if err != nil {
  9249. theStartTime = 0
  9250. }
  9251. theStartTime = theTime.Unix()
  9252. }
  9253. adminInfo := c.GetMobileAdminUserInfo()
  9254. orgID := adminInfo.Org.Id
  9255. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9256. if err != nil {
  9257. c.ErrorLog("获取排班信息失败:%v", err)
  9258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9259. } else {
  9260. if len(monitor) > 0 {
  9261. //获取所有床位
  9262. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9263. //获取所有分区
  9264. zoneList, _ := service.GetAllZoneByList(orgID)
  9265. //获取透析处方
  9266. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9267. //获取透前评估
  9268. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9269. //获取上机
  9270. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9271. //获取透后
  9272. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9273. //获取透后监测
  9274. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9275. //获取所有的患者
  9276. patients, _ := service.GetAllPatientListByListOne(orgID)
  9277. //获取所有透析模式
  9278. treatments, _ := service.GetAllTreatModeByList(orgID)
  9279. //获取所有医嘱
  9280. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9281. //获取双人核对
  9282. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9283. //治疗小结
  9284. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9285. //待消毒
  9286. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9287. for key, item := range monitor {
  9288. // 获取床位信息
  9289. for _, it := range numberList {
  9290. if item.BedId == it.ID {
  9291. monitor[key].DeviceNumber = it
  9292. break
  9293. }
  9294. }
  9295. //获取分区信息
  9296. for _, it := range zoneList {
  9297. if item.PartitionId == it.ID {
  9298. monitor[key].DeviceZone = it
  9299. }
  9300. }
  9301. for _, prescription := range prescriptions {
  9302. if item.PatientId == prescription.PatientId {
  9303. monitor[key].Prescription = prescription
  9304. break
  9305. }
  9306. }
  9307. for _, it := range checkList {
  9308. if item.PatientId == it.PatientId {
  9309. monitor[key].DoubleCheck = it
  9310. break
  9311. }
  9312. }
  9313. for _, it := range summaryList {
  9314. if item.PatientId == it.PatientId {
  9315. monitor[key].TreatmentSummaryForList = it
  9316. break
  9317. }
  9318. }
  9319. // 透前评估
  9320. for _, assessmentBefore := range assessmentBefores {
  9321. if item.PatientId == assessmentBefore.PatientId {
  9322. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9323. break
  9324. }
  9325. }
  9326. // 透析上下机
  9327. for _, dialysisOrder := range dialysisOrders {
  9328. if item.PatientId == dialysisOrder.PatientId {
  9329. monitor[key].DialysisOrder = dialysisOrder
  9330. break
  9331. }
  9332. }
  9333. // 治疗小节
  9334. for _, afterDislysis := range AssessmentAfterDislysis {
  9335. if item.PatientId == afterDislysis.PatientId {
  9336. monitor[key].AssessmentAfterDislysis = afterDislysis
  9337. break
  9338. }
  9339. }
  9340. for _, it := range monitorlist {
  9341. if item.PatientId == it.PatientId {
  9342. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9343. }
  9344. }
  9345. for _, it := range adviceList {
  9346. if item.PatientId == it.PatientId {
  9347. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9348. }
  9349. }
  9350. for _, patient := range patients {
  9351. if item.PatientId == patient.ID {
  9352. monitor[key].MonitorPatients = patient
  9353. break
  9354. }
  9355. }
  9356. for _, treatment := range treatments {
  9357. if item.ModeId == treatment.ID {
  9358. monitor[key].TreatmentMode = treatment
  9359. break
  9360. }
  9361. }
  9362. for _, infor := range informationList {
  9363. if item.PatientId == infor.PatientId {
  9364. monitor[key].NewDeviceInformation = infor
  9365. break
  9366. }
  9367. }
  9368. }
  9369. }
  9370. }
  9371. patients, err := service.GetAllpatientFourty(orgID)
  9372. var mds []*models.NewMonitorDialysisScheduleList
  9373. if pat_type == 0 {
  9374. for _, item := range monitor {
  9375. mds = append(mds, item)
  9376. }
  9377. }
  9378. //待医嘱核对
  9379. if pat_type == 1 {
  9380. for _, item := range monitor {
  9381. if len(item.AdviceList) > 0 {
  9382. mds = append(mds, item)
  9383. }
  9384. }
  9385. }
  9386. //待开小结
  9387. if pat_type == 2 {
  9388. for _, item := range monitor {
  9389. if item.TreatmentSummaryForList == nil {
  9390. mds = append(mds, item)
  9391. }
  9392. }
  9393. }
  9394. //待下机
  9395. if pat_type == 3 {
  9396. for _, item := range monitor {
  9397. if item.DialysisOrder != nil {
  9398. if item.DialysisOrder.ID > 0 {
  9399. mds = append(mds, item)
  9400. }
  9401. }
  9402. }
  9403. }
  9404. //待消毒
  9405. if pat_type == 4 {
  9406. for _, item := range monitor {
  9407. if item.NewDeviceInformation == nil {
  9408. mds = append(mds, item)
  9409. }
  9410. }
  9411. }
  9412. //待双人核对
  9413. if pat_type == 5 {
  9414. for _, item := range monitor {
  9415. if item.DoubleCheck == nil {
  9416. mds = append(mds, item)
  9417. }
  9418. }
  9419. }
  9420. //医嘱未执行
  9421. if pat_type == 6 {
  9422. for _, item := range monitor {
  9423. if len(item.AdviceList) > 0 {
  9424. mds = append(mds, item)
  9425. }
  9426. }
  9427. }
  9428. //患者未签名
  9429. if pat_type == 7 {
  9430. for _, item := range monitor {
  9431. if item.DialysisOrder != nil {
  9432. if item.DialysisOrder.ID > 0 {
  9433. mds = append(mds, item)
  9434. }
  9435. }
  9436. }
  9437. }
  9438. //目标超滤于实际超滤不同
  9439. if pat_type == 8 {
  9440. for _, item := range monitor {
  9441. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9442. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9443. mds = append(mds, item)
  9444. }
  9445. }
  9446. }
  9447. }
  9448. //血压少于5次
  9449. if pat_type == 9 {
  9450. for _, item := range monitor {
  9451. if len(item.MonitoringRecord) < 5 {
  9452. mds = append(mds, item)
  9453. }
  9454. }
  9455. }
  9456. if pat_type == 10 {
  9457. for _, item := range monitor {
  9458. if len(item.MonitoringRecord) == 0 {
  9459. mds = append(mds, item)
  9460. }
  9461. }
  9462. }
  9463. if pat_type == 11 {
  9464. for _, item := range monitor {
  9465. if len(item.MonitoringRecord) > 0 {
  9466. mds = append(mds, item)
  9467. }
  9468. }
  9469. }
  9470. if pat_type == 12 {
  9471. for _, item := range monitor {
  9472. if len(item.MonitoringRecord) > 0 {
  9473. mds = append(mds, item)
  9474. }
  9475. }
  9476. }
  9477. if err == nil {
  9478. c.ServeSuccessJSON(map[string]interface{}{
  9479. "monitor": mds,
  9480. "patients": patients,
  9481. })
  9482. } else {
  9483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9484. }
  9485. }
  9486. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9487. admin_user_id, _ := c.GetInt64("admin_user_id")
  9488. timeStr := time.Now().Format("2006-01-02")
  9489. timeLayout := "2006-01-02 15:04:05"
  9490. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9491. timenow := timeStringToTime.Unix()
  9492. orgId := c.GetMobileAdminUserInfo().Org.Id
  9493. //查询当前护士的患者
  9494. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9495. var patientIds []int64
  9496. for _, item := range orderList {
  9497. patientIds = append(patientIds, item.PatientId)
  9498. }
  9499. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9500. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9501. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9502. //药品管理信息
  9503. _, drugStockConfig := service.FindHisConfig(orgId)
  9504. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9505. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9506. c.ServeSuccessJSON(map[string]interface{}{
  9507. "adviceList": adviceList,
  9508. "hisAdviceList": hisAdviceList,
  9509. "projectList": projectList,
  9510. "drugStockConfig": drugStockConfig,
  9511. "patientList": patientList,
  9512. "projectConfig": projectConfig,
  9513. })
  9514. }
  9515. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9516. patient_id, _ := c.GetInt64("patient_id")
  9517. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9518. c.ServeSuccessJSON(map[string]interface{}{
  9519. "recrods": recrods,
  9520. })
  9521. }
  9522. func (c *DialysisAPIController) ExMobileChangeSch() {
  9523. id_one, _ := c.GetInt64("id_one")
  9524. id_two, _ := c.GetInt64("id_two")
  9525. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9526. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9527. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9528. //if order2.ID > 0 {
  9529. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9530. // return
  9531. //}
  9532. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9533. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9534. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9535. if count > 0 {
  9536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9537. return
  9538. }
  9539. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9540. if count1 > 0 {
  9541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9542. return
  9543. }
  9544. }
  9545. err := service.UpdateScheduleThree(sch, sch_two)
  9546. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9547. if order.ID > 0 {
  9548. //查询该患者的排班机位
  9549. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9550. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9551. redis := service.RedisClient()
  9552. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9553. redis.Set(key, "", time.Second)
  9554. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9555. //清空key 值
  9556. redis.Set(keyOne, "", time.Second)
  9557. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9558. //return
  9559. }
  9560. if err == nil {
  9561. //去除当天患者排班中重复数据,保留最后一条数据
  9562. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9563. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9564. c.ServeSuccessJSON(map[string]interface{}{
  9565. "msg": "交换成功",
  9566. })
  9567. } else {
  9568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9569. return
  9570. }
  9571. }
  9572. func (c *DialysisAPIController) MobileCoverSch() {
  9573. id_one, _ := c.GetInt64("id_one")
  9574. id_two, _ := c.GetInt64("id_two")
  9575. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9576. //针对凤凰医院
  9577. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9578. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9579. if len(advice) > 0 {
  9580. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9581. }
  9582. }
  9583. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9584. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9585. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9586. if len(hisAdvice) > 0 {
  9587. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9588. }
  9589. if len(project) > 0 {
  9590. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9591. }
  9592. }
  9593. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9594. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9595. if order.ID > 0 {
  9596. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9597. redis := service.RedisClient()
  9598. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9599. redis.Set(key, "", time.Second)
  9600. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9601. //清空key 值
  9602. redis.Set(keyOne, "", time.Second)
  9603. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9604. //return
  9605. }
  9606. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9607. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9608. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9609. if count > 0 {
  9610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9611. return
  9612. }
  9613. }
  9614. var new_sch models.Schedule
  9615. new_sch = sch
  9616. new_sch.BedId = sch_two.BedId
  9617. new_sch.ScheduleDate = sch_two.ScheduleDate
  9618. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9619. new_sch.PartitionId = sch_two.PartitionId
  9620. new_sch.ScheduleType = sch_two.ScheduleType
  9621. new_sch.ID = 0
  9622. //删除原来的排班
  9623. err := service.SaveSchTwo(sch, sch_two)
  9624. //生成新的排班
  9625. if err == nil {
  9626. err2 := service.SaveSch(&new_sch)
  9627. if err2 == nil {
  9628. //去除当天患者排班中重复数据,保留最后一条数据
  9629. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9630. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9631. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9632. c.ServeSuccessJSON(map[string]interface{}{
  9633. "msg": "覆盖成功",
  9634. "new_sch": new_sch,
  9635. })
  9636. } else {
  9637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9638. return
  9639. }
  9640. } else {
  9641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9642. return
  9643. }
  9644. }
  9645. func (c *DialysisAPIController) BatchCheckAdvice() {
  9646. patient_id, _ := c.GetInt64("patient_id")
  9647. advice_date, _ := c.GetInt64("advice_date")
  9648. org_id := c.GetMobileAdminUserInfo().Org.Id
  9649. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9650. //查询是his系统还是血透系统
  9651. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9652. //his客户
  9653. if configs.IsOpen == 1 {
  9654. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9655. for _, item := range adviceList {
  9656. service.BatchCheckHisAdvice(item.ID, creater)
  9657. }
  9658. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9659. for _, item := range projectList {
  9660. service.BatchCheckProject(item.ID, creater)
  9661. }
  9662. c.ServeSuccessJSON(map[string]interface{}{
  9663. "adviceList": adviceList,
  9664. "projectList": projectList,
  9665. })
  9666. }
  9667. if configs.IsOpen != 1 {
  9668. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9669. for _, item := range adviceList {
  9670. service.BatchAdviceList(item.ID, creater)
  9671. }
  9672. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9673. for _, item := range projectList {
  9674. service.BatchCheckProject(item.ID, creater)
  9675. }
  9676. c.ServeSuccessJSON(map[string]interface{}{
  9677. "adviceList": adviceList,
  9678. "projectList": projectList,
  9679. })
  9680. }
  9681. return
  9682. }
  9683. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9684. org_id := c.GetMobileAdminUserInfo().Org.Id
  9685. drugList, _ := service.GetAllDrugList(org_id)
  9686. c.ServeSuccessJSON(map[string]interface{}{
  9687. "drugList": drugList,
  9688. })
  9689. }
  9690. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9691. org_id := c.GetMobileAdminUserInfo().Org.Id
  9692. dataBody := make(map[string]interface{}, 0)
  9693. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9694. if err != nil {
  9695. utils.ErrorLog(err.Error())
  9696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9697. return
  9698. }
  9699. timeLayout := "2006-01-02"
  9700. loc, _ := time.LoadLocation("Local")
  9701. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9702. utils.ErrorLog("advice_type")
  9703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9704. return
  9705. }
  9706. adviceType := int64(dataBody["advice_type"].(float64))
  9707. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9708. utils.ErrorLog("start_time")
  9709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9710. return
  9711. }
  9712. startTime2, _ := dataBody["start_time"].(string)
  9713. time_arr := strings.Split(startTime2, " ")
  9714. if len(time_arr) > 0 {
  9715. startTime2 = time_arr[0]
  9716. }
  9717. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9718. utils.ErrorLog("advice_date")
  9719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9720. return
  9721. }
  9722. advice_date, _ := dataBody["advice_date"].(string)
  9723. var advicedateunix int64
  9724. if len(advice_date) > 0 {
  9725. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9726. if err != nil {
  9727. fmt.Println(err)
  9728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9729. return
  9730. }
  9731. advicedateunix = theTime.Unix()
  9732. }
  9733. adviceDate := startTime2
  9734. if len(adviceDate) == 0 {
  9735. utils.ErrorLog("len(adviceDate) == 0")
  9736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9737. return
  9738. }
  9739. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9740. if err != nil {
  9741. utils.ErrorLog(err.Error())
  9742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9743. return
  9744. }
  9745. AdviceDate := advicedateunix
  9746. RecordDate := advicedateunix
  9747. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9748. utils.ErrorLog("start_time")
  9749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9750. return
  9751. }
  9752. startTime, _ := dataBody["start_time"].(string)
  9753. if len(startTime) == 0 {
  9754. utils.ErrorLog("len(start_time) == 0")
  9755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9756. return
  9757. }
  9758. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9759. if err != nil {
  9760. utils.ErrorLog(err.Error())
  9761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9762. return
  9763. }
  9764. StartTime := theTime.Unix()
  9765. advice_name, _ := dataBody["advice_name"].(string)
  9766. advice_desc, _ := dataBody["advice_desc"].(string)
  9767. delivery_way, _ := dataBody["delivery_way"].(string)
  9768. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9769. frequency_type := int64(dataBody["frequency_type"].(float64))
  9770. frequency_week, _ := dataBody["frequency_week"].(string)
  9771. prescribing_number := dataBody["prescribing_number"].(float64)
  9772. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9773. remark := dataBody["remark"].(string)
  9774. single_dose := dataBody["single_dose"].(float64)
  9775. single_dose_unit := dataBody["single_dose_unit"].(string)
  9776. patient_id := int64(dataBody["patient_id"].(float64))
  9777. day_count := int64(dataBody["day_count"].(float64))
  9778. groupNo := int64(dataBody["group_no"].(float64))
  9779. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9780. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9781. if groupNo <= 0 {
  9782. group := service.GetMaxAdviceGroupID(org_id)
  9783. groupNo = group + 1
  9784. }
  9785. var template_id = ""
  9786. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9787. template_id = "M" + adviceLastId
  9788. advice := models.DoctorAdvice{
  9789. UserOrgId: org_id,
  9790. PatientId: patient_id,
  9791. AdviceType: adviceType,
  9792. AdviceDate: AdviceDate,
  9793. StartTime: StartTime,
  9794. AdviceName: advice_name,
  9795. AdviceDesc: advice_desc,
  9796. ReminderDate: 0,
  9797. SingleDose: single_dose,
  9798. SingleDoseUnit: single_dose_unit,
  9799. DrugSpec: 0,
  9800. DrugSpecUnit: "",
  9801. PrescribingNumber: prescribing_number,
  9802. PrescribingNumberUnit: prescribing_number_unit,
  9803. DeliveryWay: delivery_way,
  9804. ExecutionFrequency: execution_frequency,
  9805. AdviceDoctor: advice_doctor,
  9806. Status: 1,
  9807. CreatedTime: time.Now().Unix(),
  9808. UpdatedTime: 0,
  9809. AdviceAffirm: "",
  9810. Remark: remark,
  9811. StopTime: 0,
  9812. StopReason: "",
  9813. StopDoctor: 0,
  9814. StopState: 0,
  9815. ParentId: 0,
  9816. ExecutionTime: 0,
  9817. ExecutionStaff: 0,
  9818. ExecutionState: 0,
  9819. Checker: 0,
  9820. RecordDate: RecordDate,
  9821. DialysisOrderId: 0,
  9822. CheckTime: 0,
  9823. CheckState: 0,
  9824. AdviceId: 0,
  9825. RemindType: 0,
  9826. FrequencyType: frequency_type,
  9827. DayCount: day_count,
  9828. WeekDay: frequency_week,
  9829. ChildDoctorAdvice: nil,
  9830. TemplateId: template_id,
  9831. Modifier: 0,
  9832. IsCheck: 0,
  9833. Way: 0,
  9834. DrugId: 0,
  9835. DrugNameId: 0,
  9836. IsMedicine: 0,
  9837. PushStartTime: 0,
  9838. IsSettle: 0,
  9839. IsPrescription: 0,
  9840. GroupNo: groupNo,
  9841. }
  9842. service.CreateMobileAdivce(advice)
  9843. c.ServeSuccessJSON(map[string]interface{}{
  9844. "msg": "保存成功!",
  9845. })
  9846. }
  9847. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9848. patient_id, _ := c.GetInt64("patient_id")
  9849. org_id := c.GetMobileAdminUserInfo().Org.Id
  9850. app_id := c.GetMobileAdminUserInfo().App.Id
  9851. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9852. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9853. c.ServeSuccessJSON(map[string]interface{}{
  9854. "adviceList": adviceList,
  9855. "adminRoles": adminRoles,
  9856. })
  9857. }
  9858. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9859. org_id := c.GetMobileAdminUserInfo().Org.Id
  9860. dataBody := make(map[string]interface{}, 0)
  9861. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9862. if err != nil {
  9863. utils.ErrorLog(err.Error())
  9864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9865. return
  9866. }
  9867. timeLayout := "2006-01-02"
  9868. loc, _ := time.LoadLocation("Local")
  9869. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9870. utils.ErrorLog("start_time")
  9871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9872. return
  9873. }
  9874. startTime2, _ := dataBody["start_time"].(string)
  9875. time_arr := strings.Split(startTime2, " ")
  9876. if len(time_arr) > 0 {
  9877. startTime2 = time_arr[0]
  9878. }
  9879. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9880. utils.ErrorLog("advice_date")
  9881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9882. return
  9883. }
  9884. advice_date, _ := dataBody["advice_date"].(string)
  9885. var advicedateunix int64
  9886. if len(advice_date) > 0 {
  9887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9888. if err != nil {
  9889. fmt.Println(err)
  9890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9891. return
  9892. }
  9893. advicedateunix = theTime.Unix()
  9894. }
  9895. adviceDate := startTime2
  9896. if len(adviceDate) == 0 {
  9897. utils.ErrorLog("len(adviceDate) == 0")
  9898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9899. return
  9900. }
  9901. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9902. if err != nil {
  9903. utils.ErrorLog(err.Error())
  9904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9905. return
  9906. }
  9907. AdviceDate := advicedateunix
  9908. RecordDate := advicedateunix
  9909. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9910. utils.ErrorLog("start_time")
  9911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9912. return
  9913. }
  9914. startTime, _ := dataBody["start_time"].(string)
  9915. if len(startTime) == 0 {
  9916. utils.ErrorLog("len(start_time) == 0")
  9917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9918. return
  9919. }
  9920. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9921. if err != nil {
  9922. utils.ErrorLog(err.Error())
  9923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9924. return
  9925. }
  9926. StartTime := theTime.Unix()
  9927. advice_name, _ := dataBody["advice_name"].(string)
  9928. advice_desc, _ := dataBody["advice_desc"].(string)
  9929. delivery_way, _ := dataBody["delivery_way"].(string)
  9930. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9931. prescribing_number := dataBody["prescribing_number"].(float64)
  9932. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9933. remark := dataBody["remark"].(string)
  9934. single_dose := dataBody["single_dose"].(float64)
  9935. single_dose_unit := dataBody["single_dose_unit"].(string)
  9936. patient_id := int64(dataBody["patient_id"].(float64))
  9937. groupNo := int64(dataBody["group_no"].(float64))
  9938. parent_id := int64(dataBody["parent_id"].(float64))
  9939. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9940. advice := models.XtDoctorAdviceOne{
  9941. UserOrgId: org_id,
  9942. PatientId: patient_id,
  9943. AdviceType: 1,
  9944. AdviceDate: AdviceDate,
  9945. StartTime: StartTime,
  9946. AdviceName: advice_name,
  9947. AdviceDesc: advice_desc,
  9948. ReminderDate: 0,
  9949. SingleDose: single_dose,
  9950. SingleDoseUnit: single_dose_unit,
  9951. PrescribingNumber: prescribing_number,
  9952. PrescribingNumberUnit: prescribing_number_unit,
  9953. DeliveryWay: delivery_way,
  9954. ExecutionFrequency: execution_frequency,
  9955. AdviceDoctor: advice_doctor,
  9956. Status: 1,
  9957. CreatedTime: time.Now().Unix(),
  9958. UpdatedTime: time.Now().Unix(),
  9959. AdviceAffirm: "",
  9960. Remark: remark,
  9961. StopTime: 0,
  9962. StopReason: "",
  9963. StopDoctor: 0,
  9964. StopState: 0,
  9965. ParentId: parent_id,
  9966. ExecutionTime: 0,
  9967. ExecutionStaff: 0,
  9968. ExecutionState: 0,
  9969. Checker: 0,
  9970. RecordDate: RecordDate,
  9971. DialysisOrderId: 0,
  9972. CheckTime: 0,
  9973. CheckState: 0,
  9974. DrugSpec: 0,
  9975. DrugSpecUnit: "",
  9976. Groupno: groupNo,
  9977. RemindType: 0,
  9978. FrequencyType: 0,
  9979. DayCount: 0,
  9980. WeekDay: "",
  9981. TemplateId: "",
  9982. Modifier: 0,
  9983. }
  9984. service.CreateMobileAdivceOne(advice)
  9985. c.ServeSuccessJSON(map[string]interface{}{
  9986. "msg": "保存成功!",
  9987. })
  9988. }
  9989. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9990. id, _ := c.GetInt64("id")
  9991. service.DeleteSelfAdviceSubAdvice(id)
  9992. c.ServeSuccessJSON(map[string]interface{}{
  9993. "msg": "保存成功!",
  9994. })
  9995. }
  9996. func (c *DialysisAPIController) GetEditAdviceAction() {
  9997. id, _ := c.GetInt64("id")
  9998. org_id := c.GetMobileAdminUserInfo().Org.Id
  9999. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10000. drugList, _ := service.GetAllDrugList(org_id)
  10001. c.ServeSuccessJSON(map[string]interface{}{
  10002. "advice": advice,
  10003. "drugList": drugList,
  10004. })
  10005. }
  10006. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10007. dataBody := make(map[string]interface{}, 0)
  10008. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10009. if err != nil {
  10010. utils.ErrorLog(err.Error())
  10011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10012. return
  10013. }
  10014. timeLayout := "2006-01-02"
  10015. loc, _ := time.LoadLocation("Local")
  10016. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10017. utils.ErrorLog("start_time")
  10018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10019. return
  10020. }
  10021. startTime2, _ := dataBody["start_time"].(string)
  10022. time_arr := strings.Split(startTime2, " ")
  10023. if len(time_arr) > 0 {
  10024. startTime2 = time_arr[0]
  10025. }
  10026. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10027. utils.ErrorLog("advice_date")
  10028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10029. return
  10030. }
  10031. advice_date, _ := dataBody["advice_date"].(string)
  10032. var advicedateunix int64
  10033. if len(advice_date) > 0 {
  10034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10035. if err != nil {
  10036. fmt.Println(err)
  10037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10038. return
  10039. }
  10040. advicedateunix = theTime.Unix()
  10041. }
  10042. adviceDate := startTime2
  10043. if len(adviceDate) == 0 {
  10044. utils.ErrorLog("len(adviceDate) == 0")
  10045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10046. return
  10047. }
  10048. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10049. if err != nil {
  10050. utils.ErrorLog(err.Error())
  10051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10052. return
  10053. }
  10054. AdviceDate := advicedateunix
  10055. RecordDate := advicedateunix
  10056. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10057. utils.ErrorLog("start_time")
  10058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10059. return
  10060. }
  10061. startTime, _ := dataBody["start_time"].(string)
  10062. if len(startTime) == 0 {
  10063. utils.ErrorLog("len(start_time) == 0")
  10064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10065. return
  10066. }
  10067. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10068. if err != nil {
  10069. utils.ErrorLog(err.Error())
  10070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10071. return
  10072. }
  10073. StartTime := theTime.Unix()
  10074. advice_name, _ := dataBody["advice_name"].(string)
  10075. advice_desc, _ := dataBody["advice_desc"].(string)
  10076. delivery_way, _ := dataBody["delivery_way"].(string)
  10077. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10078. prescribing_number := dataBody["prescribing_number"].(float64)
  10079. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10080. remark := dataBody["remark"].(string)
  10081. single_dose := dataBody["single_dose"].(float64)
  10082. single_dose_unit := dataBody["single_dose_unit"].(string)
  10083. id := int64(dataBody["id"].(float64))
  10084. frequency_type := int64(dataBody["frequency_type"].(float64))
  10085. frequency_week, _ := dataBody["frequency_week"].(string)
  10086. day_count := int64(dataBody["day_count"].(float64))
  10087. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10088. advice := models.XtDoctorAdviceOne{
  10089. AdviceDate: AdviceDate,
  10090. StartTime: StartTime,
  10091. AdviceName: advice_name,
  10092. AdviceDesc: advice_desc,
  10093. SingleDose: single_dose,
  10094. SingleDoseUnit: single_dose_unit,
  10095. PrescribingNumber: prescribing_number,
  10096. PrescribingNumberUnit: prescribing_number_unit,
  10097. DeliveryWay: delivery_way,
  10098. ExecutionFrequency: execution_frequency,
  10099. AdviceDoctor: advice_doctor,
  10100. Remark: remark,
  10101. RecordDate: RecordDate,
  10102. FrequencyType: frequency_type,
  10103. DayCount: day_count,
  10104. WeekDay: frequency_week,
  10105. }
  10106. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10107. c.ServeSuccessJSON(map[string]interface{}{
  10108. "advice": advice,
  10109. })
  10110. }
  10111. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10112. dataBody := make(map[string]interface{}, 0)
  10113. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10114. if err != nil {
  10115. utils.ErrorLog(err.Error())
  10116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10117. return
  10118. }
  10119. timeLayout := "2006-01-02"
  10120. loc, _ := time.LoadLocation("Local")
  10121. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10122. utils.ErrorLog("start_time")
  10123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10124. return
  10125. }
  10126. startTime2, _ := dataBody["start_time"].(string)
  10127. time_arr := strings.Split(startTime2, " ")
  10128. if len(time_arr) > 0 {
  10129. startTime2 = time_arr[0]
  10130. }
  10131. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10132. utils.ErrorLog("advice_date")
  10133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10134. return
  10135. }
  10136. advice_date, _ := dataBody["advice_date"].(string)
  10137. var advicedateunix int64
  10138. if len(advice_date) > 0 {
  10139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10140. if err != nil {
  10141. fmt.Println(err)
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. advicedateunix = theTime.Unix()
  10146. }
  10147. adviceDate := startTime2
  10148. if len(adviceDate) == 0 {
  10149. utils.ErrorLog("len(adviceDate) == 0")
  10150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10151. return
  10152. }
  10153. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10154. if err != nil {
  10155. utils.ErrorLog(err.Error())
  10156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10157. return
  10158. }
  10159. AdviceDate := advicedateunix
  10160. RecordDate := advicedateunix
  10161. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10162. utils.ErrorLog("start_time")
  10163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10164. return
  10165. }
  10166. startTime, _ := dataBody["start_time"].(string)
  10167. if len(startTime) == 0 {
  10168. utils.ErrorLog("len(start_time) == 0")
  10169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10170. return
  10171. }
  10172. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10173. if err != nil {
  10174. utils.ErrorLog(err.Error())
  10175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10176. return
  10177. }
  10178. StartTime := theTime.Unix()
  10179. advice_name, _ := dataBody["advice_name"].(string)
  10180. advice_desc, _ := dataBody["advice_desc"].(string)
  10181. delivery_way, _ := dataBody["delivery_way"].(string)
  10182. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10183. prescribing_number := dataBody["prescribing_number"].(float64)
  10184. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10185. remark := dataBody["remark"].(string)
  10186. single_dose := dataBody["single_dose"].(float64)
  10187. single_dose_unit := dataBody["single_dose_unit"].(string)
  10188. id := int64(dataBody["id"].(float64))
  10189. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10190. advice := models.XtDoctorAdviceOne{
  10191. AdviceDate: AdviceDate,
  10192. StartTime: StartTime,
  10193. AdviceName: advice_name,
  10194. AdviceDesc: advice_desc,
  10195. SingleDose: single_dose,
  10196. SingleDoseUnit: single_dose_unit,
  10197. PrescribingNumber: prescribing_number,
  10198. PrescribingNumberUnit: prescribing_number_unit,
  10199. DeliveryWay: delivery_way,
  10200. ExecutionFrequency: execution_frequency,
  10201. AdviceDoctor: advice_doctor,
  10202. Remark: remark,
  10203. RecordDate: RecordDate,
  10204. }
  10205. service.UpdateMobileDoctorAdviceById(id, advice)
  10206. c.ServeSuccessJSON(map[string]interface{}{
  10207. "advice": advice,
  10208. })
  10209. }
  10210. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10211. dataBody := make(map[string]interface{}, 0)
  10212. timeLayout := "2006-01-02"
  10213. loc, _ := time.LoadLocation("Local")
  10214. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10215. if err != nil {
  10216. utils.ErrorLog(err.Error())
  10217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10218. return
  10219. }
  10220. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10221. utils.ErrorLog("start_time")
  10222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10223. return
  10224. }
  10225. startTime2, _ := dataBody["start_time"].(string)
  10226. time_arr := strings.Split(startTime2, " ")
  10227. if len(time_arr) > 0 {
  10228. startTime2 = time_arr[0]
  10229. }
  10230. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10231. utils.ErrorLog("advice_date")
  10232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10233. return
  10234. }
  10235. advice_date, _ := dataBody["advice_date"].(string)
  10236. var advicedateunix int64
  10237. if len(advice_date) > 0 {
  10238. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10239. if err != nil {
  10240. fmt.Println(err)
  10241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10242. return
  10243. }
  10244. advicedateunix = theTime.Unix()
  10245. }
  10246. adviceDate := startTime2
  10247. if len(adviceDate) == 0 {
  10248. utils.ErrorLog("len(adviceDate) == 0")
  10249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10250. return
  10251. }
  10252. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10253. if err != nil {
  10254. utils.ErrorLog(err.Error())
  10255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10256. return
  10257. }
  10258. RecordDate := advicedateunix
  10259. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10260. utils.ErrorLog("start_time")
  10261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10262. return
  10263. }
  10264. startTime, _ := dataBody["start_time"].(string)
  10265. if len(startTime) == 0 {
  10266. utils.ErrorLog("len(start_time) == 0")
  10267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10268. return
  10269. }
  10270. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10271. if err != nil {
  10272. utils.ErrorLog(err.Error())
  10273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10274. return
  10275. }
  10276. StartTime := theTime.Unix()
  10277. patient_id := int64(dataBody["patient_id"].(float64))
  10278. group_no := int64(dataBody["group_no"].(float64))
  10279. org_id := c.GetMobileAdminUserInfo().Org.Id
  10280. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10281. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10282. utils.ErrorLog("advices")
  10283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10284. return
  10285. }
  10286. adviceNames := dataBody["advices"].([]interface{})
  10287. var advices []*models.GroupAdvice
  10288. for _, adviceNameMap := range adviceNames {
  10289. var advice models.GroupAdvice
  10290. adviceNameM := adviceNameMap.(map[string]interface{})
  10291. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10292. utils.ErrorLog("advice_name")
  10293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10294. return
  10295. }
  10296. adviceName, _ := adviceNameM["advice_name"].(string)
  10297. if len(adviceName) == 0 {
  10298. utils.ErrorLog("len(advice_name) == 0")
  10299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10300. return
  10301. }
  10302. advice.AdviceName = adviceName
  10303. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10304. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10305. advice.DrugSpec = drugSpec
  10306. }
  10307. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10308. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10309. advice.AdviceDesc = adviceDesc
  10310. }
  10311. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10312. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10313. advice.DrugSpecUnit = drugSpecUnit
  10314. }
  10315. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10316. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10317. advice.SingleDose = singleDose
  10318. }
  10319. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10320. singleDose := adviceNameM["single_dose"].(float64)
  10321. advice.SingleDose = singleDose
  10322. }
  10323. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10324. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10325. advice.SingleDoseUnit = singleDoseUnit
  10326. }
  10327. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10328. tmp := adviceNameM["single_dose_unit"].(float64)
  10329. singleDoseUnit := service.TypeConversion(tmp)
  10330. advice.SingleDoseUnit = singleDoseUnit
  10331. }
  10332. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10333. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10334. advice.PrescribingNumber = prescribingNumber
  10335. }
  10336. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10337. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10338. advice.PrescribingNumber = prescribingNumber
  10339. }
  10340. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10341. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10342. advice.PrescribingNumberUnit = prescribingNumberUnit
  10343. }
  10344. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10345. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10346. advice.DeliveryWay = deliveryWay
  10347. }
  10348. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10349. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10350. advice.ExecutionFrequency = executionFrequency
  10351. }
  10352. remark, _ := adviceNameM["remark"].(string)
  10353. advice.Remark = remark
  10354. advice.AdviceType = 1
  10355. advice.StartTime = StartTime
  10356. advice.RecordDate = RecordDate
  10357. advice.PatientId = patient_id
  10358. advice.UserOrgId = org_id
  10359. advice.AdviceDoctor = advice_doctor
  10360. advices = append(advices, &advice)
  10361. }
  10362. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10363. c.ServeSuccessJSON(map[string]interface{}{
  10364. "advice": newAdvices,
  10365. })
  10366. }