patient_api_controller.go 252KB

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