patient_api_controller.go 270KB

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