patient_api_controller.go 269KB

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