dialysis_api_controller.go 232KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. }
  78. func (c *DialysisApiController) GetQueueCall() {
  79. adminUserInfo := c.GetAdminUserInfo()
  80. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  81. if queueConfig.ID <= 0 {
  82. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  83. queueConfig.Qhsj = 10
  84. queueConfig.Jzdcbbcs = 3
  85. queueConfig.Jzbbsy = 1
  86. queueConfig.Jzjhyc = 0
  87. queueConfig.Sjdcbbcs = 3
  88. queueConfig.Sjbbsy = 0
  89. queueConfig.Sjjhyc = 0
  90. queueConfig.Txxqyxs = 0
  91. queueConfig.Txglsyxs = 0
  92. }
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "queue_config": queueConfig,
  95. })
  96. }
  97. func (c *DialysisApiController) UpdateQueueCall() {
  98. adminUserInfo := c.GetAdminUserInfo()
  99. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  100. if queueConfig.ID <= 0 {
  101. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  102. queueConfig.Qhsj = 10
  103. queueConfig.Jzdcbbcs = 3
  104. queueConfig.Jzbbsy = 1
  105. queueConfig.Jzjhyc = 0
  106. queueConfig.Sjdcbbcs = 3
  107. queueConfig.Sjbbsy = 0
  108. queueConfig.Sjjhyc = 0
  109. queueConfig.Txxqyxs = 0
  110. queueConfig.Txglsyxs = 0
  111. queueConfig.CreateTime = time.Now().Unix()
  112. queueConfig.UpdateTime = time.Now().Unix()
  113. }
  114. qhsj, _ := c.GetInt64("qhsj", 0)
  115. if qhsj > 0 {
  116. queueConfig.Qhsj = qhsj
  117. }
  118. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  119. if jzdcbbcs > 0 {
  120. queueConfig.Jzdcbbcs = jzdcbbcs
  121. }
  122. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  123. if jzbbsy > 0 {
  124. queueConfig.Jzbbsy = jzbbsy
  125. }
  126. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  127. queueConfig.Jzjhyc = jzjhyc
  128. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  129. if sjdcbbcs > 0 {
  130. queueConfig.Sjdcbbcs = sjdcbbcs
  131. }
  132. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  133. if sjbbsy > 0 {
  134. queueConfig.Sjbbsy = sjbbsy
  135. }
  136. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  137. queueConfig.Sjjhyc = sjjhyc
  138. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  139. queueConfig.Txxqyxs = txxqyxs
  140. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  141. queueConfig.Txglsyxs = txglsyxs
  142. queueConfig.UpdateTime = time.Now().Unix()
  143. service.UpDateQueueCallInfo(queueConfig)
  144. c.ServeSuccessJSON(map[string]interface{}{
  145. "queue_config": queueConfig,
  146. })
  147. }
  148. func (c *DialysisApiController) PostPrescription() {
  149. patient, _ := c.GetInt64("patient_id", 0)
  150. recordDateStr := c.GetString("record_date")
  151. if patient <= 0 {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. adminUserInfo := c.GetAdminUserInfo()
  156. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  157. if patientInfo.ID == 0 {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  159. return
  160. }
  161. if len(recordDateStr) == 0 {
  162. recordDateStr = time.Now().Format("2006-01-02")
  163. }
  164. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  165. if parseDateErr != nil {
  166. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. mode_id, _ := c.GetInt64("mode_id", 0)
  171. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  172. dialyzer, _ := c.GetInt64("dialyzer", 0)
  173. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  174. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  175. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  176. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  177. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  178. replacement_way, _ := c.GetInt64("replacement_way", 0)
  179. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  180. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  181. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  182. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  183. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  184. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  185. kalium, _ := c.GetFloat("kalium", 0)
  186. sodium, _ := c.GetFloat("sodium", 0)
  187. replacement_total, _ := c.GetFloat("replacement_total", 0)
  188. calcium, _ := c.GetFloat("calcium", 0)
  189. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  190. glucose, _ := c.GetFloat("glucose", 0)
  191. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  192. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  193. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  194. conductivity, _ := c.GetFloat("conductivity", 0)
  195. remark := c.GetString("remark")
  196. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  197. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  198. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  199. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  200. body_fluid, _ := c.GetInt64("body_fluid", 0)
  201. special_medicine, _ := c.GetInt64("special_medicine", 0)
  202. special_medicine_other := c.GetString("special_medicine_other")
  203. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  204. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  205. blood_access, _ := c.GetInt64("blood_access", 0)
  206. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  207. body_fluid_other := c.GetString("body_fluid_other")
  208. target_ktv, _ := c.GetFloat("target_ktv", 0)
  209. niprocart, _ := c.GetInt64("niprocart", 0)
  210. jms, _ := c.GetInt64("jms", 0)
  211. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  212. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  213. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  214. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  215. filtryzer, _ := c.GetInt64("filtryzer", 0)
  216. dialyzers, _ := c.GetInt64("dialyzers", 0)
  217. injector, _ := c.GetInt64("injector", 0)
  218. bloodlines, _ := c.GetInt64("bloodlines", 0)
  219. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  220. safe_package, _ := c.GetInt64("package", 0)
  221. a_liquid, _ := c.GetInt64("a_liquid", 0)
  222. preImpules, _ := c.GetFloat("pre_impulse", 0)
  223. fmt.Println("", preImpules)
  224. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  225. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  226. //heparin_sodium := c.GetString("heparin_sodium")
  227. //fmt.Println("肝素钠",heparin_sodium)
  228. //nucleoprotamine := c.GetString("nucleoprotamine")
  229. //fmt.Println("鱼精蛋白",nucleoprotamine)
  230. //push_the_protamine := c.GetString("push_the_protamine")
  231. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  232. // var prescription_doctor int64
  233. blood := c.GetString("blood")
  234. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  235. dialysis_irrigation := c.GetString("dialysis_irrigation")
  236. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  237. displace_speed := c.GetString("displace_speed")
  238. illness, _ := c.GetInt64("illness")
  239. amylaceum := c.GetString("amylaceum")
  240. single_time := c.GetString("single_time")
  241. single_water := c.GetString("single_water")
  242. replacement_flow := c.GetString("replacement_flow")
  243. plasma_separator := c.GetString("plasma_separator")
  244. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  245. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  246. oxygen_flow := c.GetString("oxygen_flow")
  247. oxygen_time := c.GetString("oxygen_time")
  248. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  249. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  250. puncture_needle := c.GetString("puncture_needle")
  251. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  252. epo := c.GetString("epo")
  253. epo_count, _ := c.GetFloat("epo_count", 0)
  254. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  255. admin_user_id, _ := c.GetInt64("admin_user_id")
  256. is_water, _ := c.GetInt64("is_water")
  257. drhy_water := c.GetString("drhy_water")
  258. dry_water_hour := c.GetString("dry_water_hour")
  259. water_machine := c.GetString("water_machine")
  260. add_amount, _ := c.GetFloat("add_amount")
  261. reduce_amount, _ := c.GetFloat("reduce_amount")
  262. dialysis_remark := c.GetString("dialysis_remark")
  263. prescribing_number, _ := c.GetFloat("prescribing_number")
  264. treatment_remark := c.GetString("treatment_remark")
  265. prescription_sodium := c.GetString("prescription_sodium")
  266. start_sodium := c.GetString("start_sodium")
  267. sodium_curve := c.GetString("sodium_curve")
  268. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  269. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  270. prescription_water, _ := c.GetFloat("prescription_water")
  271. dialysis_strainer := c.GetString("dialysis_strainer")
  272. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  273. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  274. //if template.TemplateId == 2 || template.TemplateId == 6 {
  275. // if appRole.UserType == 3 {
  276. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  277. // if getPermissionErr != nil {
  278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  279. // return
  280. // } else if headNursePermission == nil {
  281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  282. // return
  283. // }
  284. // }
  285. //}
  286. prescription := models.DialysisPrescription{
  287. UserOrgId: adminUserInfo.CurrentOrgId,
  288. PatientId: patient,
  289. RecordDate: recordDate.Unix(),
  290. ModeId: mode_id,
  291. DialysisDuration: dialysis_duration,
  292. Dialyzer: dialyzer,
  293. ReplacementTotal: replacement_total,
  294. PerfusionApparatus: perfusion_apparatus,
  295. BloodFlowVolume: blood_flow_volume,
  296. DewaterAmount: dewater_amount,
  297. DisplaceLiqui: displace_liqui,
  298. ReplacementWay: replacement_way,
  299. Anticoagulant: anticoagulant,
  300. AnticoagulantShouji: anticoagulant_shouji,
  301. AnticoagulantWeichi: anticoagulant_weichi,
  302. AnticoagulantZongliang: anticoagulant_zongliang,
  303. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  304. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  305. Kalium: kalium,
  306. Sodium: sodium,
  307. Calcium: calcium,
  308. Bicarbonate: bicarbonate,
  309. Glucose: glucose,
  310. // DryWeight: dry_weight,
  311. DialysateFlow: dialysate_flow,
  312. DialysateTemperature: dialysate_temperature,
  313. Conductivity: conductivity,
  314. Remark: remark,
  315. Status: 1,
  316. CreatedTime: time.Now().Unix(),
  317. UpdatedTime: time.Now().Unix(),
  318. DialysisDurationMinute: dialysisDurationMinute,
  319. DialysisDurationHour: dialysisDurationHour,
  320. TargetUltrafiltration: targetUltrafiltration,
  321. DialysateFormulation: dialysateFormulation,
  322. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  323. BodyFluid: body_fluid,
  324. SpecialMedicine: special_medicine,
  325. SpecialMedicineOther: special_medicine_other,
  326. DisplaceLiquiPart: displace_liqui_part,
  327. DisplaceLiquiValue: displace_liqui_value,
  328. BloodAccess: blood_access,
  329. Ultrafiltration: ultrafiltration,
  330. BodyFluidOther: body_fluid_other,
  331. TargetKtv: target_ktv,
  332. Niprocart: niprocart,
  333. Jms: jms,
  334. FistulaNeedleSet: fistula_needle_set,
  335. FistulaNeedleSet16: fistula_needle_set_16,
  336. Hemoperfusion: hemoperfusion,
  337. DialyserSterilised: dialyser_sterilised,
  338. Filtryzer: filtryzer,
  339. Dialyzers: dialyzers,
  340. Injector: injector,
  341. Bloodlines: bloodlines,
  342. TubingHemodialysis: tubing_hemodialysis,
  343. Package: safe_package,
  344. ALiquid: a_liquid,
  345. PreImpulse: preImpules,
  346. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  347. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  348. Blood: blood,
  349. DialysisDialyszers: dialysis_dialyszers,
  350. DialysisIrrigation: dialysis_irrigation,
  351. AntioxidantCommodityName: antioxidant_commodity_name,
  352. DisplaceSpeed: displace_speed,
  353. Illness: illness,
  354. Amylaceum: amylaceum,
  355. SingleTime: single_time,
  356. SingleWater: single_water,
  357. ReplacementFlow: replacement_flow,
  358. PlasmaSeparator: plasma_separator,
  359. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  360. OxygenFlow: oxygen_flow,
  361. OxygenUptake: oxygen_uptake,
  362. OxygenTime: oxygen_time,
  363. HemodialysisPipelines: hemodialysis_pipelines,
  364. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  365. PunctureNeedle: puncture_needle,
  366. PunctureNeedleCount: puncture_needle_count,
  367. Epo: epo,
  368. EpoCount: epo_count,
  369. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  370. AdminUserId: admin_user_id,
  371. IsWater: is_water,
  372. DrhyWater: drhy_water,
  373. DryWaterHour: dry_water_hour,
  374. WaterMachine: water_machine,
  375. AddAmount: add_amount,
  376. ReduceAmount: reduce_amount,
  377. DialysisRemark: dialysis_remark,
  378. PrescribingNumber: prescribing_number,
  379. TreatmentRemark: treatment_remark,
  380. PrescriptionSodium: prescription_sodium,
  381. StartSodium: start_sodium,
  382. SodiumCurve: sodium_curve,
  383. DialysisFluidFlow: dialysis_fluid_flow,
  384. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  385. PrescriptionWater: prescription_water,
  386. DialysisStrainer: dialysis_strainer,
  387. }
  388. //长沙南雅医院,自动生成抗凝剂的临时处方
  389. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  390. if prescribing_number == 0 {
  391. prescribing_number = 1
  392. }
  393. advice := models.DoctorAdvice{
  394. UserOrgId: adminUserInfo.CurrentOrgId,
  395. PatientId: patient,
  396. GroupNo: 0,
  397. AdviceType: 2,
  398. RecordDate: recordDate.Unix(),
  399. AdviceDate: recordDate.Unix(),
  400. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  401. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  402. AdviceDesc: "",
  403. ReminderDate: 0,
  404. SingleDose: anticoagulant_zongliang,
  405. SingleDoseUnit: "iu",
  406. DrugSpec: 0,
  407. DrugSpecUnit: "",
  408. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  409. PrescribingNumberUnit: "支",
  410. DeliveryWay: "静脉注射",
  411. ExecutionFrequency: "上机前",
  412. AdviceDoctor: 0,
  413. Status: 1,
  414. CreatedTime: time.Now().Unix(),
  415. UpdatedTime: time.Now().Unix(),
  416. IsPrescription: 1,
  417. ExecutionState: 2,
  418. StopState: 2,
  419. IsSettle: 2,
  420. }
  421. // 查询排班信息
  422. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  423. if schedulePatient.ID > 0 {
  424. if schedulePatient.ScheduleType == 1 {
  425. advice.StartTime = recordDate.Unix() + 6.5*60*60
  426. }
  427. if schedulePatient.ScheduleType == 2 {
  428. advice.StartTime = recordDate.Unix() + 11*60*60
  429. }
  430. }
  431. // 抗凝剂名称
  432. switch anticoagulant {
  433. case 1:
  434. advice.AdviceName = "无肝素"
  435. break
  436. case 2:
  437. advice.AdviceName = "普通肝素"
  438. break
  439. case 3:
  440. advice.AdviceName = "低分子肝素"
  441. break
  442. case 4:
  443. advice.AdviceName = "阿加曲班"
  444. break
  445. case 5:
  446. advice.AdviceName = "枸橼酸钠"
  447. break
  448. case 6:
  449. advice.AdviceName = "低分子肝素钙"
  450. break
  451. case 7:
  452. advice.AdviceName = "低分子肝素钠"
  453. break
  454. case 8:
  455. advice.AdviceName = "依诺肝素"
  456. break
  457. case 9:
  458. advice.AdviceName = "达肝素"
  459. break
  460. case 10:
  461. advice.AdviceName = "体外抗凝"
  462. break
  463. case 11:
  464. advice.AdviceName = "那曲肝素"
  465. break
  466. case 12:
  467. advice.AdviceName = "无抗凝剂"
  468. break
  469. }
  470. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  471. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  472. advice.AdviceDoctor = appRole.AdminUserId
  473. }
  474. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  475. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  476. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  477. advice.AdviceName = "低分子肝素钠注射液"
  478. // 修改患者临时医嘱里的抗凝剂医嘱
  479. advice.ID = advicePrescription.ID
  480. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  481. //service.UpdateDoctorAdvice(&advice)
  482. } else {
  483. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  484. advice.AdviceName = "低分子肝素钠注射液"
  485. // 新增患者临时医嘱里的抗凝剂医嘱
  486. service.CreateDoctorAdvice(&advice)
  487. }
  488. }
  489. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  490. redis := service.RedisClient()
  491. //清空key 值
  492. redis.Set(key, "", time.Second)
  493. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  494. redis.Set(keyOne, "", time.Second)
  495. }
  496. if appRole.UserType == 2 || appRole.UserType == 1 {
  497. prescription.PrescriptionDoctor = appRole.AdminUserId
  498. }
  499. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  500. if dialysisPrescription.ID == 0 { //新增
  501. if mode_id > 0 {
  502. var str string
  503. //查找该机构用的是什么透析器
  504. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  505. if filedConfig.ID > 0 {
  506. str = dialyzerPerfusionApparatus
  507. } else {
  508. str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
  509. }
  510. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  511. }
  512. prescription.Creater = adminUserInfo.AdminUser.Id
  513. //针对河间咸得
  514. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  515. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  516. prescription.DisplaceLiquiPart = 0
  517. prescription.DisplaceLiquiValue = 0
  518. }
  519. }
  520. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  521. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  522. }
  523. err := service.AddSigleRecord(&prescription)
  524. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  525. redis := service.RedisClient()
  526. //清空key 值
  527. redis.Set(key, "", time.Second)
  528. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  529. redis.Set(keyTwo, "", time.Second)
  530. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  531. redis.Set(keyThree, "", time.Second)
  532. defer redis.Close()
  533. if err == nil {
  534. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  535. if updateErr != nil {
  536. utils.ErrorLog("%v", updateErr)
  537. }
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "prescription": &prescription,
  540. })
  541. } else {
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  543. }
  544. } else { //修改
  545. if mode_id > 0 {
  546. var str string
  547. //查找该机构用的是什么透析器
  548. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  549. if filedConfig.ID > 0 {
  550. str = dialyzerPerfusionApparatus
  551. } else {
  552. str = dialysis_dialyszers + "/" + dialysis_irrigation
  553. }
  554. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  555. }
  556. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  557. //if template.TemplateId == 1 {
  558. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  559. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  560. // if getPermissionErr != nil {
  561. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  562. // return
  563. // } else if headNursePermission == nil {
  564. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  565. // return
  566. // }
  567. // }
  568. //}
  569. if appRole.UserType == 2 || appRole.UserType == 1 {
  570. prescription_doctor := adminUserInfo.AdminUser.Id
  571. prescription.PrescriptionDoctor = prescription_doctor
  572. }
  573. if dialysisPrescription.Creater == 0 { //体重称
  574. prescription.Creater = adminUserInfo.AdminUser.Id
  575. } else {
  576. prescription.Creater = dialysisPrescription.Creater
  577. }
  578. prescription.CreatedTime = dialysisPrescription.CreatedTime
  579. prescription.UpdatedTime = time.Now().Unix()
  580. prescription.Modifier = adminUserInfo.AdminUser.Id
  581. prescription.ID = dialysisPrescription.ID
  582. updateErr := service.UpDateDialysisPrescription(&prescription)
  583. //修改处方
  584. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  585. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  586. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  587. if advicePrescription.ID > 0 {
  588. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  589. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  590. redis := service.RedisClient()
  591. defer redis.Close()
  592. //清空key 值
  593. redis.Set(key, "", time.Second)
  594. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  595. redis.Set(keyOne, "", time.Second)
  596. }
  597. }
  598. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  599. redis := service.RedisClient()
  600. defer redis.Close()
  601. //清空key 值
  602. redis.Set(key, "", time.Second)
  603. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  604. redis.Set(keyOne, "", time.Second)
  605. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  606. redis.Set(keyThree, "", time.Second)
  607. if updateErr == nil {
  608. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  609. if updateErr != nil {
  610. utils.ErrorLog("%v", updateErr)
  611. }
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "prescription": &prescription,
  614. })
  615. } else {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  617. }
  618. }
  619. }
  620. func (c *DialysisApiController) PostSoulution() {
  621. patient, _ := c.GetInt64("patient", 0)
  622. recordDateStr := c.GetString("record_date")
  623. if patient <= 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  625. return
  626. }
  627. adminUserInfo := c.GetAdminUserInfo()
  628. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  629. if patientInfo.ID == 0 {
  630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  631. return
  632. }
  633. if len(recordDateStr) == 0 {
  634. recordDateStr = time.Now().Format("2006-01-02")
  635. }
  636. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  637. if parseDateErr != nil {
  638. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. mode_id, _ := c.GetInt64("mode_id", 0)
  643. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  644. dialyzer, _ := c.GetInt64("dialyzer", 0)
  645. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  646. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  647. replacement_total, _ := c.GetFloat("replacement_total", 0)
  648. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  649. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  650. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  651. replacement_way, _ := c.GetInt64("replacement_way", 0)
  652. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  653. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  654. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  655. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  656. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  657. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  658. kalium, _ := c.GetFloat("kalium", 0)
  659. sodium, _ := c.GetFloat("sodium", 0)
  660. calcium, _ := c.GetFloat("calcium", 0)
  661. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  662. glucose, _ := c.GetFloat("glucose", 0)
  663. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  664. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  665. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  666. conductivity, _ := c.GetFloat("conductivity", 0)
  667. remark := c.GetString("remark")
  668. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  669. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  670. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  671. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  672. body_fluid, _ := c.GetInt64("body_fluid", 0)
  673. special_medicine, _ := c.GetInt64("special_medicine", 0)
  674. special_medicine_other := c.GetString("special_medicine_other")
  675. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  676. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  677. blood_access, _ := c.GetInt64("blood_access", 0)
  678. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  679. body_fluid_other := c.GetString("body_fluid_other")
  680. target_ktv, _ := c.GetFloat("target_ktv", 0)
  681. niprocart, _ := c.GetInt64("niprocart", 0)
  682. jms, _ := c.GetInt64("jms", 0)
  683. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  684. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  685. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  686. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  687. filtryzer, _ := c.GetInt64("filtryzer", 0)
  688. dialyzers, _ := c.GetInt64("dialyzers", 0)
  689. injector, _ := c.GetInt64("injector", 0)
  690. bloodlines, _ := c.GetInt64("bloodlines", 0)
  691. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  692. safe_package, _ := c.GetInt64("package", 0)
  693. a_liquid, _ := c.GetInt64("a_liquid", 0)
  694. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  695. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  696. blood := c.GetString("blood")
  697. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  698. dialysis_irrigation := c.GetString("dialysis_irrigation")
  699. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  700. displace_speed := c.GetString("displace_speed")
  701. illness, _ := c.GetInt64("illness")
  702. amylaceum := c.GetString("amylaceum")
  703. single_time := c.GetString("single_time")
  704. single_water := c.GetString("single_water")
  705. replacement_flow := c.GetString("replacement_flow")
  706. plasma_separator := c.GetString("plasma_separator")
  707. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  708. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  709. oxygen_flow := c.GetString("oxygen_flow")
  710. oxygen_time := c.GetString("oxygen_time")
  711. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  712. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  713. puncture_needle := c.GetString("puncture_needle")
  714. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  715. epo := c.GetString("epo")
  716. epo_count, _ := c.GetFloat("epo_count", 0)
  717. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  718. impulse := c.GetString("impulse")
  719. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  720. admin_user_id, _ := c.GetInt64("admin_user_id")
  721. fmt.Println("", preImpules)
  722. is_water, _ := c.GetInt64("is_water")
  723. dry_water_hour := c.GetString("dry_water_hour")
  724. drhy_water := c.GetString("drhy_water")
  725. water_machine := c.GetString("water_machine")
  726. add_amount, _ := c.GetFloat("add_amount")
  727. reduce_amount, _ := c.GetFloat("reduce_amount")
  728. dialysis_remark := c.GetString("dialysis_remark")
  729. prescribing_number, _ := c.GetFloat("prescribing_number")
  730. treatment_remark := c.GetString("treatment_remark")
  731. prescription_sodium := c.GetString("prescription_sodium")
  732. start_sodium := c.GetString("start_sodium")
  733. sodium_curve := c.GetString("sodium_curve")
  734. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  735. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  736. prescription_water, _ := c.GetFloat("prescription_water")
  737. dialysis_strainer := c.GetString("dialysis_strainer")
  738. var prescription_doctor int64
  739. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  740. if appRole.UserType == 2 || appRole.UserType == 1 {
  741. prescription_doctor = appRole.AdminUserId
  742. }
  743. if mode_id > 0 {
  744. var str string
  745. //查找该机构用的是什么透析器
  746. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  747. if filedConfig.ID > 0 {
  748. str = dialyzerPerfusionApparatus
  749. } else {
  750. str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
  751. }
  752. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  753. }
  754. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  755. //
  756. //if template.TemplateId == 2 || template.TemplateId == 6 {
  757. // if appRole.UserType == 3 {
  758. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  759. // if getPermissionErr != nil {
  760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  761. // return
  762. // } else if headNursePermission == nil {
  763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  764. // return
  765. // }
  766. // }
  767. //}
  768. prescription := models.DialysisPrescription{
  769. UserOrgId: adminUserInfo.CurrentOrgId,
  770. PatientId: patient,
  771. RecordDate: recordDate.Unix(),
  772. ModeId: mode_id,
  773. DialysisDuration: dialysis_duration,
  774. Dialyzer: dialyzer,
  775. PerfusionApparatus: perfusion_apparatus,
  776. BloodFlowVolume: blood_flow_volume,
  777. DewaterAmount: dewater_amount,
  778. DisplaceLiqui: displace_liqui,
  779. ReplacementWay: replacement_way,
  780. Anticoagulant: anticoagulant,
  781. AnticoagulantShouji: anticoagulant_shouji,
  782. AnticoagulantWeichi: anticoagulant_weichi,
  783. AnticoagulantZongliang: anticoagulant_zongliang,
  784. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  785. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  786. Kalium: kalium,
  787. Sodium: sodium,
  788. Calcium: calcium,
  789. Bicarbonate: bicarbonate,
  790. Glucose: glucose,
  791. // DryWeight: dry_weight,
  792. DialysateFlow: dialysate_flow,
  793. DialysateTemperature: dialysate_temperature,
  794. Conductivity: conductivity,
  795. Remark: remark,
  796. PrescriptionDoctor: prescription_doctor,
  797. Status: 1,
  798. CreatedTime: time.Now().Unix(),
  799. UpdatedTime: time.Now().Unix(),
  800. DialysisDurationMinute: dialysisDurationMinute,
  801. DialysisDurationHour: dialysisDurationHour,
  802. TargetUltrafiltration: targetUltrafiltration,
  803. DialysateFormulation: dialysateFormulation,
  804. ReplacementTotal: replacement_total,
  805. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  806. BodyFluid: body_fluid,
  807. SpecialMedicine: special_medicine,
  808. SpecialMedicineOther: special_medicine_other,
  809. DisplaceLiquiPart: displace_liqui_part,
  810. DisplaceLiquiValue: displace_liqui_value,
  811. BloodAccess: blood_access,
  812. Ultrafiltration: ultrafiltration,
  813. BodyFluidOther: body_fluid_other,
  814. TargetKtv: target_ktv,
  815. Niprocart: niprocart,
  816. Jms: jms,
  817. FistulaNeedleSet: fistula_needle_set,
  818. FistulaNeedleSet16: fistula_needle_set_16,
  819. Hemoperfusion: hemoperfusion,
  820. DialyserSterilised: dialyser_sterilised,
  821. Filtryzer: filtryzer,
  822. Dialyzers: dialyzers,
  823. Injector: injector,
  824. Bloodlines: bloodlines,
  825. TubingHemodialysis: tubing_hemodialysis,
  826. Package: safe_package,
  827. ALiquid: a_liquid,
  828. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  829. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  830. Blood: blood,
  831. DialysisIrrigation: dialysis_irrigation,
  832. DialysisDialyszers: dialysis_dialyszers,
  833. AntioxidantCommodityName: antioxidant_commodity_name,
  834. DisplaceSpeed: displace_speed,
  835. Illness: illness,
  836. Amylaceum: amylaceum,
  837. SingleTime: single_time,
  838. SingleWater: single_water,
  839. ReplacementFlow: replacement_flow,
  840. PlasmaSeparator: plasma_separator,
  841. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  842. OxygenTime: oxygen_time,
  843. OxygenUptake: oxygen_uptake,
  844. OxygenFlow: oxygen_flow,
  845. HemodialysisPipelines: hemodialysis_pipelines,
  846. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  847. PunctureNeedle: puncture_needle,
  848. PunctureNeedleCount: puncture_needle_count,
  849. Epo: epo,
  850. EpoCount: epo_count,
  851. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  852. PreImpulse: preImpules,
  853. AdminUserId: admin_user_id,
  854. IsWater: is_water,
  855. DryWaterHour: dry_water_hour,
  856. DrhyWater: drhy_water,
  857. WaterMachine: water_machine,
  858. AddAmount: add_amount,
  859. ReduceAmount: reduce_amount,
  860. DialysisRemark: dialysis_remark,
  861. PrescribingNumber: prescribing_number,
  862. StartSodium: start_sodium,
  863. PrescriptionSodium: prescription_sodium,
  864. SodiumCurve: sodium_curve,
  865. TreatmentRemark: treatment_remark,
  866. DialysisFluidFlow: dialysis_fluid_flow,
  867. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  868. PrescriptionWater: prescription_water,
  869. DialysisStrainer: dialysis_strainer,
  870. }
  871. //查询最近透析准备表里是否存在 透析器 灌流器
  872. //splitStr := strings.Split(dialysis_dialyszers, ",")
  873. //
  874. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  875. //
  876. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  877. //if len(mation)>0{
  878. // for _, item := range splitStr {
  879. // for _,it := range mation{
  880. // if(item == it.SpecificationName){
  881. //
  882. // //查询最近一次的透析器
  883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  884. //
  885. // if errcode == gorm.ErrRecordNotFound{
  886. // //插入数据
  887. // prepare := models.DialysisBeforePrepare{
  888. // UserOrgId: adminUserInfo.CurrentOrgId,
  889. // PatientId: patient,
  890. // RecordDate: recordDate.Unix(),
  891. // GoodTypeId: it.GoodTypeId,
  892. // GoodId: it.ID,
  893. // Count: 1,
  894. // Ctime: time.Now().Unix(),
  895. // Creater: adminUserInfo.AdminUser.Id,
  896. // Status:1,
  897. //
  898. // }
  899. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  900. // fmt.Println("",errcode)
  901. // }
  902. // }
  903. // }
  904. //
  905. // }
  906. //
  907. // for _, item := range splitIrrigation {
  908. // for _,it := range mation{
  909. // if(item == it.SpecificationName){
  910. // //查询最近一次的透析器
  911. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  912. // if errcode == gorm.ErrRecordNotFound{
  913. // //插入数据
  914. // prepare := models.DialysisBeforePrepare{
  915. // UserOrgId: adminUserInfo.CurrentOrgId,
  916. // PatientId: patient,
  917. // RecordDate: recordDate.Unix(),
  918. // GoodTypeId: it.GoodTypeId,
  919. // GoodId: it.ID,
  920. // Count: 1,
  921. // Ctime: time.Now().Unix(),
  922. // Creater: adminUserInfo.AdminUser.Id,
  923. // Status:1,
  924. //
  925. // }
  926. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  927. // fmt.Println(errcode)
  928. // }
  929. // }
  930. // }
  931. // }
  932. //}
  933. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  934. if dialysisPrescription.ID == 0 { //新增
  935. if appRole.UserType == 2 || appRole.UserType == 1 {
  936. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  937. }
  938. prescription.Creater = adminUserInfo.AdminUser.Id
  939. } else { //修改
  940. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  941. //if template.TemplateId == 1 {
  942. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  943. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  944. // if getPermissionErr != nil {
  945. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  946. // return
  947. // } else if headNursePermission == nil {
  948. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  949. // return
  950. // }
  951. // }
  952. //}
  953. if appRole.UserType == 2 || appRole.UserType == 1 {
  954. prescription_doctor := adminUserInfo.AdminUser.Id
  955. prescription.PrescriptionDoctor = prescription_doctor
  956. } else {
  957. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  958. }
  959. if dialysisPrescription.Creater == 0 {
  960. prescription.Creater = adminUserInfo.AdminUser.Id
  961. } else {
  962. prescription.Creater = dialysisPrescription.Creater
  963. }
  964. prescription.CreatedTime = dialysisPrescription.CreatedTime
  965. prescription.UpdatedTime = time.Now().Unix()
  966. prescription.Modifier = adminUserInfo.AdminUser.Id
  967. prescription.ID = dialysisPrescription.ID
  968. }
  969. solution := models.DialysisSolution{
  970. RegistrarsId: adminUserInfo.AdminUser.Id,
  971. UserOrgId: adminUserInfo.CurrentOrgId,
  972. Doctor: prescription_doctor,
  973. PatientId: patient,
  974. ModeId: mode_id,
  975. DialysisDuration: dialysis_duration,
  976. PerfusionApparatus: perfusion_apparatus,
  977. BloodFlowVolume: blood_flow_volume,
  978. Dewater: dewater_amount,
  979. DisplaceLiqui: displace_liqui,
  980. ReplacementWay: replacement_way,
  981. Anticoagulant: anticoagulant,
  982. AnticoagulantShouji: anticoagulant_shouji,
  983. AnticoagulantWeichi: anticoagulant_weichi,
  984. AnticoagulantZongliang: anticoagulant_zongliang,
  985. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  986. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  987. Kalium: kalium,
  988. Sodium: sodium,
  989. Calcium: calcium,
  990. Bicarbonate: bicarbonate,
  991. Glucose: glucose,
  992. // DryWeight: dry_weight,
  993. DialysateFlow: dialysate_flow,
  994. DialysateTemperature: dialysate_temperature,
  995. Conductivity: conductivity,
  996. Remark: remark,
  997. Status: 1,
  998. CreatedTime: time.Now().Unix(),
  999. UpdatedTime: time.Now().Unix(),
  1000. DialysisDurationMinute: dialysisDurationMinute,
  1001. DialysisDurationHour: dialysisDurationHour,
  1002. TargetUltrafiltration: targetUltrafiltration,
  1003. DialysateFormulation: dialysateFormulation,
  1004. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1005. BodyFluid: body_fluid,
  1006. SpecialMedicine: special_medicine,
  1007. SpecialMedicineOther: special_medicine_other,
  1008. DisplaceLiquiPart: displace_liqui_part,
  1009. DisplaceLiquiValue: displace_liqui_value,
  1010. BloodAccess: blood_access,
  1011. Ultrafiltration: ultrafiltration,
  1012. BodyFluidOther: body_fluid_other,
  1013. ReplacementTotal: replacement_total,
  1014. TargetKtv: target_ktv,
  1015. DialysisIrrigation: dialysis_irrigation,
  1016. DialysisDialyszers: dialysis_dialyszers,
  1017. HemodialysisPipelines: hemodialysis_pipelines,
  1018. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1019. PunctureNeedle: puncture_needle,
  1020. PunctureNeedleCount: puncture_needle_count,
  1021. Epo: epo,
  1022. EpoCount: epo_count,
  1023. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1024. OxygenUptake: oxygen_uptake,
  1025. OxygenFlow: oxygen_flow,
  1026. OxygenTime: oxygen_time,
  1027. PreImpulse: preImpules,
  1028. SolutionStatus: 1,
  1029. DialysisRemark: dialysis_remark,
  1030. PrescribingNumber: prescribing_number,
  1031. StartSodium: start_sodium,
  1032. PrescriptionSodium: prescription_sodium,
  1033. SodiumCurve: sodium_curve,
  1034. TreatmentRemark: treatment_remark,
  1035. DialysisFluidFlow: dialysis_fluid_flow,
  1036. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1037. PrescriptionWater: prescribing_number,
  1038. DialysisStrainer: dialysis_strainer,
  1039. }
  1040. //针对河间咸得
  1041. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1042. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1043. prescription.DisplaceLiquiPart = 0
  1044. prescription.DisplaceLiquiValue = 0
  1045. }
  1046. }
  1047. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1048. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1049. solution.DisplaceLiquiPart = 0
  1050. solution.DisplaceLiquiValue = 0
  1051. }
  1052. }
  1053. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1054. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1055. }
  1056. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1057. //获取最新1条
  1058. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1059. //更新状态
  1060. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1061. //长沙南雅医院,自动生成抗凝剂的临时处方
  1062. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1063. if prescribing_number == 0 {
  1064. prescribing_number = 1
  1065. }
  1066. advice := models.DoctorAdvice{
  1067. UserOrgId: adminUserInfo.CurrentOrgId,
  1068. PatientId: patient,
  1069. GroupNo: 0,
  1070. AdviceType: 2,
  1071. RecordDate: recordDate.Unix(),
  1072. AdviceDate: recordDate.Unix(),
  1073. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1074. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1075. AdviceDesc: "",
  1076. ReminderDate: 0,
  1077. SingleDose: anticoagulant_zongliang,
  1078. SingleDoseUnit: "iu",
  1079. DrugSpec: 0,
  1080. DrugSpecUnit: "",
  1081. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1082. PrescribingNumberUnit: "支",
  1083. DeliveryWay: "静脉注射",
  1084. ExecutionFrequency: "上机前",
  1085. AdviceDoctor: 0,
  1086. Status: 1,
  1087. CreatedTime: time.Now().Unix(),
  1088. UpdatedTime: time.Now().Unix(),
  1089. IsPrescription: 1,
  1090. ExecutionState: 2,
  1091. StopState: 2,
  1092. IsSettle: 2,
  1093. }
  1094. // 查询排班信息
  1095. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1096. if schedulePatient.ID > 0 {
  1097. if schedulePatient.ScheduleType == 1 {
  1098. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1099. }
  1100. if schedulePatient.ScheduleType == 2 {
  1101. advice.StartTime = recordDate.Unix() + 11*60*60
  1102. }
  1103. }
  1104. // 抗凝剂名称
  1105. switch anticoagulant {
  1106. case 1:
  1107. advice.AdviceName = "无肝素"
  1108. break
  1109. case 2:
  1110. advice.AdviceName = "普通肝素"
  1111. break
  1112. case 3:
  1113. advice.AdviceName = "低分子肝素"
  1114. break
  1115. case 4:
  1116. advice.AdviceName = "阿加曲班"
  1117. break
  1118. case 5:
  1119. advice.AdviceName = "枸橼酸钠"
  1120. break
  1121. case 6:
  1122. advice.AdviceName = "低分子肝素钙"
  1123. break
  1124. case 7:
  1125. advice.AdviceName = "低分子肝素钠"
  1126. break
  1127. case 8:
  1128. advice.AdviceName = "依诺肝素"
  1129. break
  1130. case 9:
  1131. advice.AdviceName = "达肝素"
  1132. break
  1133. case 10:
  1134. advice.AdviceName = "体外抗凝"
  1135. break
  1136. case 11:
  1137. advice.AdviceName = "那曲肝素"
  1138. break
  1139. case 12:
  1140. advice.AdviceName = "无抗凝剂"
  1141. break
  1142. }
  1143. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1144. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1145. advice.AdviceDoctor = appRole.AdminUserId
  1146. }
  1147. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1148. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1149. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1150. advice.AdviceName = "低分子肝素钠注射液"
  1151. // 修改患者临时医嘱里的抗凝剂医嘱
  1152. advice.ID = advicePrescription.ID
  1153. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1154. } else {
  1155. // 新增患者临时医嘱里的抗凝剂医嘱
  1156. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1157. advice.AdviceName = "低分子肝素钠注射液"
  1158. service.CreateDoctorAdvice(&advice)
  1159. }
  1160. }
  1161. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1162. redis := service.RedisClient()
  1163. //清空key 值
  1164. redis.Set(key, "", time.Second)
  1165. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1166. redis.Set(keyOne, "", time.Second)
  1167. }
  1168. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1169. redis := service.RedisClient()
  1170. //清空key 值
  1171. redis.Set(key, "", time.Second)
  1172. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1173. //清空key 值
  1174. redis.Set(keyOne, "", time.Second)
  1175. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1176. redis.Set(keyTwo, "", time.Second)
  1177. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1178. redis.Set(keyThree, "", time.Second)
  1179. defer redis.Close()
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "solution": &solution,
  1183. "prescription": &prescription,
  1184. })
  1185. } else {
  1186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1187. }
  1188. }
  1189. func (c *DialysisApiController) PostDouleCheck() {
  1190. id, _ := c.GetInt64("patient", 0)
  1191. recordDateStr := c.GetString("record_date")
  1192. checkTimeStr := c.GetString("check_time")
  1193. firstCheckTimeStr := c.GetString("first_check_time")
  1194. creater, _ := c.GetInt64("creater", 0)
  1195. modifier, _ := c.GetInt64("modifier", 0)
  1196. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1197. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1198. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1199. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1200. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1201. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1202. vascular_access_desc := c.GetString("vascular_access_desc")
  1203. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1204. collator, _ := c.GetInt64("collator", 0)
  1205. employee_number := c.GetString("employee_number")
  1206. if id <= 0 {
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. adminUserInfo := c.GetAdminUserInfo()
  1211. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1212. if patient.ID == 0 {
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1214. return
  1215. }
  1216. if len(recordDateStr) == 0 {
  1217. recordDateStr = time.Now().Format("2006-01-02")
  1218. }
  1219. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1220. if parseDateErr != nil {
  1221. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1223. return
  1224. }
  1225. var checkDate int64
  1226. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1227. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1228. if employee_number != list.JobNumber {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1230. return
  1231. }
  1232. }
  1233. if len(checkTimeStr) == 0 {
  1234. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1235. checkDate = 0
  1236. } else {
  1237. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1238. checkDate = checkDateUnix.Unix()
  1239. }
  1240. var firstCheckTimeDate int64
  1241. if len(firstCheckTimeStr) == 0 {
  1242. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1243. firstCheckTimeDate = 0
  1244. } else {
  1245. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1246. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1247. }
  1248. doubleCheck := models.DoubleCheck{
  1249. UserOrgId: adminUserInfo.CurrentOrgId,
  1250. PatientId: id,
  1251. DialysisItemCheck: dialysis_item_check,
  1252. DialysisParameterCheck: dialysis_parameter_check,
  1253. VascularAccessVerification: vascular_access_verification,
  1254. PipelineConnectionCheck: pipeline_connection_check,
  1255. DialysisItemDesc: dialysis_item_desc,
  1256. DialysisParameterDesc: dialysis_parameter_desc,
  1257. VascularAccessDesc: vascular_access_desc,
  1258. PipelineConnectionDesc: pipeline_connection_desc,
  1259. Collator: collator,
  1260. Status: 1,
  1261. CreatedTime: time.Now().Unix(),
  1262. UpdatedTime: time.Now().Unix(),
  1263. CheckDate: recordDate.Unix(),
  1264. EmployeeNumber: employee_number,
  1265. }
  1266. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1267. if check.ID == 0 { //新增
  1268. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1269. doubleCheck.CheckTime = checkDate
  1270. doubleCheck.Creater = creater
  1271. doubleCheck.Modifier = modifier
  1272. err := service.AddSigleDoubleCheck(&doubleCheck)
  1273. redis := service.RedisClient()
  1274. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1275. //清空key 值
  1276. redis.Set(key, "", time.Second)
  1277. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1278. redis.Set(keyTwo, "", time.Second)
  1279. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1280. redis.Set(keyThree, "", time.Second)
  1281. defer redis.Close()
  1282. if err == nil {
  1283. c.ServeSuccessJSON(map[string]interface{}{
  1284. "doubleCheck": doubleCheck,
  1285. })
  1286. } else {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1288. }
  1289. } else { //修改
  1290. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1291. doubleCheck.CheckTime = checkDate
  1292. doubleCheck.Creater = creater
  1293. doubleCheck.Modifier = modifier
  1294. doubleCheck.CreatedTime = check.CreatedTime
  1295. doubleCheck.UpdatedTime = time.Now().Unix()
  1296. doubleCheck.ID = check.ID
  1297. redis := service.RedisClient()
  1298. err := service.UpdateDoubleCheck(&doubleCheck)
  1299. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1300. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1301. redis.Set(keyTwo, "", time.Second)
  1302. //清空key 值
  1303. redis.Set(key, "", time.Second)
  1304. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1305. redis.Set(keyThree, "", time.Second)
  1306. defer redis.Close()
  1307. if err == nil {
  1308. c.ServeSuccessJSON(map[string]interface{}{
  1309. "doubleCheck": doubleCheck,
  1310. })
  1311. } else {
  1312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1313. }
  1314. }
  1315. }
  1316. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1317. id, _ := c.GetInt64("patient", 0)
  1318. recordDateStr := c.GetString("record_date")
  1319. way, _ := c.GetInt64("way", 0)
  1320. consciousness, _ := c.GetInt64("consciousness", 0)
  1321. appetite, _ := c.GetInt64("appetite", 0)
  1322. condition, _ := c.GetInt64("condition", 0)
  1323. posture, _ := c.GetInt64("posture")
  1324. score := c.GetString("score")
  1325. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1326. danger_level, _ := c.GetInt64("danger_level", 0)
  1327. intake, _ := c.GetInt64("intake", 0)
  1328. nutrition, _ := c.GetInt64("nutrition", 0)
  1329. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1330. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1331. sick_condition_other := c.GetString("sick_condition_other")
  1332. //precaution, _ := c.GetInt64("precaution", 0)
  1333. precaution := c.GetString("precaution")
  1334. precaution_other := c.GetString("precaution_other")
  1335. psychological_other := c.GetString("psychological_other")
  1336. admission_number := c.GetString("admission_number")
  1337. tumble, _ := c.GetInt64("tumble")
  1338. his_department := c.GetString("his_department")
  1339. his_bed := c.GetString("his_bed")
  1340. diacrisis := c.GetString("diacrisis")
  1341. if id <= 0 {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1343. return
  1344. }
  1345. adminUserInfo := c.GetAdminUserInfo()
  1346. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1347. if patient.ID == 0 {
  1348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1349. return
  1350. }
  1351. if len(recordDateStr) == 0 {
  1352. recordDateStr = time.Now().Format("2006-01-02")
  1353. }
  1354. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1355. if parseDateErr != nil {
  1356. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1358. return
  1359. }
  1360. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1361. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1362. UserOrgId: adminUserInfo.CurrentOrgId,
  1363. PatientId: id,
  1364. RecordDate: recordDate.Unix(),
  1365. Way: way,
  1366. Consciousness: consciousness,
  1367. Appetite: appetite,
  1368. Condition: condition,
  1369. SickCondition: sick_condition,
  1370. DangerLevel: danger_level,
  1371. Intake: intake,
  1372. Nutrition: nutrition,
  1373. PsychologicalAssessment: psychological_assessment,
  1374. PsychologicalAssessmentOther: psychological_assessment_other,
  1375. SickConditionOther: sick_condition_other,
  1376. Posture: posture,
  1377. CreatedTime: time.Now().Unix(),
  1378. UpdateTime: time.Now().Unix(),
  1379. Status: 1,
  1380. Score: score,
  1381. Precaution: precaution,
  1382. PrecautionOther: precaution_other,
  1383. PsychologicalOther: psychological_other,
  1384. AdmissionNumber: admission_number,
  1385. Tumble: tumble,
  1386. HisDepartment: his_department,
  1387. HisBed: his_bed,
  1388. Diacrisis: diacrisis,
  1389. }
  1390. if receiveTreatment.ID == 0 { //新增
  1391. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1392. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1393. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1394. redis := service.RedisClient()
  1395. //清空key 值
  1396. redis.Set(key, "", time.Second)
  1397. defer redis.Close()
  1398. if err == nil {
  1399. c.ServeSuccessJSON(map[string]interface{}{
  1400. "receiveTreatmentAsses": receiveTreatmentAsses,
  1401. })
  1402. } else {
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1404. }
  1405. } else { //修改
  1406. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1407. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1408. // if getPermissionErr != nil {
  1409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1410. // return
  1411. // } else if headNursePermission == nil {
  1412. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1413. // return
  1414. // }
  1415. //}
  1416. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1417. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1418. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1419. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1420. receiveTreatmentAsses.ID = receiveTreatment.ID
  1421. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1422. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1423. redis := service.RedisClient()
  1424. defer redis.Close()
  1425. redis.Set(keyOne, "", time.Second*60*60*18)
  1426. if err == nil {
  1427. c.ServeSuccessJSON(map[string]interface{}{
  1428. "receiveTreatmentAsses": receiveTreatmentAsses,
  1429. })
  1430. } else {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1432. }
  1433. }
  1434. }
  1435. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1436. patient, _ := c.GetInt64("patient", 0)
  1437. recordDateStr := c.GetString("record_date")
  1438. fmt.Println(recordDateStr)
  1439. if patient <= 0 {
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1441. return
  1442. }
  1443. adminUserInfo := c.GetAdminUserInfo()
  1444. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1445. if patientInfo.ID == 0 {
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1447. return
  1448. }
  1449. if len(recordDateStr) == 0 {
  1450. recordDateStr = time.Now().Format("2006-01-02")
  1451. }
  1452. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1453. if parseDateErr != nil {
  1454. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1456. return
  1457. }
  1458. // data := make(map[string]interface{}, 0)
  1459. var data models.AssessmentAfterDislysis
  1460. var err error
  1461. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1462. fmt.Println(err)
  1463. if err != nil {
  1464. c.ErrorLog("数据解析错误:%v", err)
  1465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1469. assessment.DialysisOrderId = data.DialysisOrderId
  1470. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1471. assessment.Status = 1
  1472. assessment.WeightAfter = data.WeightAfter
  1473. assessment.WeightLoss = data.WeightLoss
  1474. assessment.Temperature = data.Temperature
  1475. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1476. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1477. assessment.PulseFrequency = data.PulseFrequency
  1478. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1479. assessment.ActualDisplacement = data.ActualDisplacement
  1480. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1481. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1482. assessment.Cruor = data.Cruor
  1483. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1484. assessment.DialysisIntakes = data.DialysisIntakes
  1485. assessment.InternalFistula = data.InternalFistula
  1486. assessment.BloodAccessPartId = data.BloodAccessPartId
  1487. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1488. assessment.Catheter = data.Catheter
  1489. assessment.Complication = data.Complication
  1490. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1491. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1492. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1493. assessment.PatientGose = data.PatientGose
  1494. assessment.InpatientDepartment = data.InpatientDepartment
  1495. assessment.ObservationContent = data.ObservationContent
  1496. assessment.ObservationContentOther = data.ObservationContentOther
  1497. assessment.Remark = data.Remark
  1498. assessment.BreathingRate = data.BreathingRate
  1499. assessment.DialysisProcess = data.DialysisProcess
  1500. assessment.InAdvanceMinute = data.InAdvanceMinute
  1501. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1502. assessment.InAdvanceReason = data.InAdvanceReason
  1503. assessment.HemostasisOpera = data.HemostasisOpera
  1504. assessment.HemostasisMinute = data.HemostasisMinute
  1505. assessment.TremorNoise = data.TremorNoise
  1506. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1507. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1508. assessment.ArterialTube = data.ArterialTube
  1509. assessment.IntravenousTube = data.IntravenousTube
  1510. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1511. assessment.Dialyzer = data.Dialyzer
  1512. assessment.IsEat = data.IsEat
  1513. assessment.CvcA = data.CvcA
  1514. assessment.CvcV = data.CvcV
  1515. assessment.Channel = data.Channel
  1516. assessment.ReturnBlood = data.ReturnBlood
  1517. assessment.RehydrationVolume = data.RehydrationVolume
  1518. assessment.DialysisDuring = data.DialysisDuring
  1519. assessment.StrokeVolume = data.StrokeVolume
  1520. assessment.BloodFlow = data.BloodFlow
  1521. assessment.SealingFluidDispose = data.SealingFluidDispose
  1522. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1523. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1524. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1525. assessment.SettingPressure = data.SettingPressure
  1526. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1527. assessment.DiastolicPressure = data.DiastolicPressure
  1528. assessment.AdditionalWeight = data.AdditionalWeight
  1529. assessment.OtherComplication = data.OtherComplication
  1530. assessment.Ktv = data.Ktv
  1531. assessment.Urr = data.Urr
  1532. assessment.Hypertenison = data.Hypertenison
  1533. assessment.Hypopiesia = data.Hypopiesia
  1534. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1535. assessment.Lapse = data.Lapse
  1536. assessment.Consciousness = data.Consciousness
  1537. assessment.Fallrisk = data.Fallrisk
  1538. assessment.MachineRun = data.MachineRun
  1539. assessment.AfterUrea = data.AfterUrea
  1540. assessment.PipCoagulation = data.PipCoagulation
  1541. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1542. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1543. if assessment.ID > 0 {
  1544. if appRole.UserType == 2 || appRole.UserType == 1 {
  1545. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1546. assessment.AssessmentTime = time.Now().Unix()
  1547. } else {
  1548. if assessment.Creater == 0 {
  1549. assessment.Modifier = adminUserInfo.AdminUser.Id
  1550. assessment.Creater = adminUserInfo.AdminUser.Id
  1551. } else {
  1552. assessment.Modifier = adminUserInfo.AdminUser.Id
  1553. }
  1554. }
  1555. assessment.UpdatedTime = time.Now().Unix()
  1556. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1557. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1558. redis := service.RedisClient()
  1559. //清空key 值
  1560. redis.Set(key, "", time.Second)
  1561. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1562. redis.Set(keyThree, "", time.Second)
  1563. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1564. redis.Set(keyTwo, "", time.Second)
  1565. defer redis.Close()
  1566. } else {
  1567. if appRole.UserType == 2 || appRole.UserType == 1 {
  1568. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1569. assessment.AssessmentTime = time.Now().Unix()
  1570. } else {
  1571. assessment.Creater = adminUserInfo.AdminUser.Id
  1572. }
  1573. assessment.CreatedTime = time.Now().Unix()
  1574. assessment.UpdatedTime = time.Now().Unix()
  1575. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1576. assessment.PatientId = patient
  1577. assessment.AssessmentDate = recordDate.Unix()
  1578. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1579. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1580. redis := service.RedisClient()
  1581. //清空key 值
  1582. redis.Set(key, "", time.Second)
  1583. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1584. redis.Set(keyThree, "", time.Second)
  1585. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1586. redis.Set(keyTwo, "", time.Second)
  1587. defer redis.Close()
  1588. }
  1589. if err != nil {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1591. return
  1592. }
  1593. c.ServeSuccessJSON(map[string]interface{}{
  1594. "AssessmentAfterDislysis": &assessment,
  1595. })
  1596. }
  1597. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1598. patient, _ := c.GetInt64("patient", 0)
  1599. recordDateStr := c.GetString("record_date")
  1600. if patient <= 0 {
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. adminUserInfo := c.GetAdminUserInfo()
  1605. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1606. if patientInfo.ID == 0 {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1608. return
  1609. }
  1610. if len(recordDateStr) == 0 {
  1611. recordDateStr = time.Now().Format("2006-01-02")
  1612. }
  1613. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1614. if parseDateErr != nil {
  1615. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1617. return
  1618. }
  1619. weight_before, _ := c.GetFloat("weight_before", 0)
  1620. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1621. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1622. temperature, _ := c.GetFloat("temperature", 0)
  1623. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1624. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1625. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1626. last_post_dialysis := c.GetString("last_post_dialysis")
  1627. dialysis_interphase := c.GetString("dialysis_interphase")
  1628. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1629. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1630. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1631. bloodAccessPartId := c.GetString("blood_access_part_id")
  1632. internalFistula := c.GetString("internal_fistula")
  1633. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1634. catheter := c.GetString("catheter")
  1635. catheter_bend, _ := c.GetInt("catheter_bend")
  1636. complication := c.GetString("complication")
  1637. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1638. hemorrhage := c.GetString("hemorrhage")
  1639. hemorrhage_other := c.GetString("hemorrhage_other")
  1640. remark := c.GetString("remark")
  1641. puncture_method := c.GetString("puncture_method")
  1642. dialysis_count := c.GetString("dialysis_count")
  1643. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1644. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1645. ductus_arantii := c.GetString("ductus_arantii")
  1646. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1647. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1648. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1649. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1650. puncture_way := c.GetString("puncture_way")
  1651. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1652. internal_fistula_other := c.GetString("internal_fistula_other")
  1653. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1654. breathing_rate := c.GetString("breathing_rate")
  1655. is_infect, _ := c.GetInt64("is_infect", 0)
  1656. exposed, _ := c.GetFloat("exposed", 0)
  1657. skin := c.GetString("skin")
  1658. skin_other := c.GetString("skin_other")
  1659. infect_other := c.GetString("infect_other")
  1660. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1661. machine_type := c.GetString("machine_type")
  1662. puncture_needle := c.GetString("puncture_needle")
  1663. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1664. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1665. phinholing := c.GetString("pinholing")
  1666. catheter_suture := c.GetString("catheter_suture")
  1667. catheter_suture_other := c.GetString("catheter_suture_other")
  1668. edema := c.GetString("edema")
  1669. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1670. special_treatment := c.GetString("special_treatment")
  1671. catheter_maintenance := c.GetString("catheter_maintenance")
  1672. thrombusType := c.GetString("thromubus_type")
  1673. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1674. thrombus_a := c.GetString("thromubus_a")
  1675. thrombus_av := c.GetString("thrombus_av")
  1676. thrombus_v := c.GetString("thromubus_v")
  1677. dehydration := c.GetString("dehydration")
  1678. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1679. period, _ := c.GetInt64("period")
  1680. estimated_food_intake := c.GetString("estimated_food_intake")
  1681. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1682. urea_befor := c.GetString("urea_befor")
  1683. suction := c.GetString("suction")
  1684. weight_befor_remake := c.GetString("weight_befor_remake")
  1685. height := c.GetString("height")
  1686. age := c.GetString("age")
  1687. his_department := c.GetString("his_department")
  1688. his_bed := c.GetString("his_bed")
  1689. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1690. DialysisCount: dialysis_count,
  1691. EmergencyTreatment: emergency_treatment,
  1692. EmergencyTreatmentOther: emergency_treatment_other,
  1693. DuctusArantii: ductus_arantii,
  1694. VenousCatheterization: venous_catheterization,
  1695. VenousCatheterizationPart: venous_catheterization_part,
  1696. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1697. PunctureWay: puncture_way,
  1698. BloodAccessInternalFistula: blood_access_internal_fistula,
  1699. BloodAccessNoise: blood_access_noise,
  1700. InternalFistulaOther: internal_fistula_other,
  1701. Evaluator: adminUserInfo.AdminUser.Id,
  1702. UserOrgId: adminUserInfo.CurrentOrgId,
  1703. PatientId: patient,
  1704. AssessmentDate: recordDate.Unix(),
  1705. Temperature: temperature,
  1706. PulseFrequency: pulse_frequency,
  1707. SystolicBloodPressure: systolic_blood_pressure,
  1708. DiastolicBloodPressure: diastolic_blood_pressure,
  1709. WeightBefore: weight_before,
  1710. DryWeight: dry_weight,
  1711. AdditionalWeight: additional_weight,
  1712. DialysisInterphase: dialysis_interphase,
  1713. LastPostDialysis: last_post_dialysis,
  1714. SymptomBeforeDialysis: symptom_before_dialysis,
  1715. InternalFistula: internalFistula,
  1716. InternalFistulaSkin: internal_fistula_skin,
  1717. Catheter: catheter,
  1718. CatheterBend: catheter_bend,
  1719. Complication: complication,
  1720. CreatedTime: time.Now().Unix(),
  1721. Status: 1,
  1722. Remark: remark,
  1723. IsHemorrhage: is_hemorrhage,
  1724. Hemorrhage: hemorrhage,
  1725. HemorrhageOther: hemorrhage_other,
  1726. BloodAccessPartId: bloodAccessPartId,
  1727. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1728. PunctureMethod: puncture_method,
  1729. BreathingRate: breathing_rate,
  1730. IsInfect: is_infect,
  1731. Exposed: exposed,
  1732. Skin: skin,
  1733. SkinOther: skin_other,
  1734. InfectOther: infect_other,
  1735. DuctusArantiiOther: ductus_arantii_other,
  1736. MachineType: machine_type,
  1737. PunctureNeedle: puncture_needle,
  1738. HumorExcessiveSymptom: humor_excessive_symptom,
  1739. Phinholing: phinholing,
  1740. CatheterSuture: catheter_suture,
  1741. CatheterSutureOther: catheter_suture_other,
  1742. Edema: edema,
  1743. UrineVolume: urine_volume,
  1744. SpecialTreatment: special_treatment,
  1745. CatheterMaintenance: catheter_maintenance,
  1746. ThromubusType: thrombusInt,
  1747. ThrombusAv: thrombus_av,
  1748. ThromubusA: thrombus_a,
  1749. ThromubusV: thrombus_v,
  1750. Dehydration: dehydration,
  1751. PreDialysisDrugs: pre_dialysis_drugs,
  1752. Period: period,
  1753. EstimatedFoodIntake: estimated_food_intake,
  1754. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1755. UreaBefor: urea_befor,
  1756. Suction: suction,
  1757. WeightBeforRemake: weight_befor_remake,
  1758. Height: height,
  1759. Age: age,
  1760. HisDepartment: his_department,
  1761. HisBed: his_bed,
  1762. }
  1763. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1764. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1765. if evaluation.ID == 0 { //新增
  1766. if appRole.UserType == 2 || appRole.UserType == 1 {
  1767. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1768. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1769. } else {
  1770. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1771. }
  1772. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1773. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1774. fmt.Println("进来--------------------------------------")
  1775. fmt.Println("evaluation.WeightBefore", weight_before)
  1776. fmt.Println(" evaluation.DryWeight", dry_weight)
  1777. var dewater_amount float64
  1778. dewater_amount = 0
  1779. if dry_weight > 0 {
  1780. dewater_amount = weight_before - dry_weight - additional_weight
  1781. dewater_amount = dewater_amount * 1000
  1782. if dewater_amount <= 0 {
  1783. dewater_amount = 0
  1784. }
  1785. } else {
  1786. dewater_amount = 0
  1787. }
  1788. // 计算透析处方的相关超滤量
  1789. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1790. var lastDialysisPrescribe *models.DialysisPrescription
  1791. var dialysisSolution *models.DialysisSolution
  1792. var dialysisPrescribe *models.DialysisPrescription
  1793. var mode_id int64
  1794. if schedual != nil {
  1795. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1796. if dialysisPrescribe == nil {
  1797. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1798. }
  1799. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1800. // 获取透析模版
  1801. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1802. mode_id = schedual.ModeId
  1803. } else {
  1804. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1805. // 获取透析模版
  1806. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1807. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1808. if dialysisPrescribe == nil && dialysisSolution != nil {
  1809. mode_id = dialysisSolution.ModeId
  1810. }
  1811. if dialysisPrescribe == nil && dialysisSolution == nil {
  1812. mode_id = 0
  1813. }
  1814. }
  1815. // 插入透析处方
  1816. if dialysisPrescribe == nil && dialysisSolution != nil {
  1817. var newprescribe models.DialysisPrescription
  1818. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1819. newprescribe.PatientId = dialysisSolution.PatientId
  1820. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1821. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1822. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1823. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1824. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1825. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1826. newprescribe.ModeId = dialysisSolution.ModeId
  1827. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1828. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1829. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1830. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1831. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1832. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1833. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1834. newprescribe.Glucose = dialysisSolution.Glucose
  1835. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1836. newprescribe.Kalium = dialysisSolution.Kalium
  1837. newprescribe.Sodium = dialysisSolution.Sodium
  1838. newprescribe.Calcium = dialysisSolution.Calcium
  1839. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1840. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1841. newprescribe.Conductivity = dialysisSolution.Conductivity
  1842. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1843. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1844. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1845. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1846. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1847. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1848. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1849. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1850. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1851. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1852. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1853. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1854. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1855. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1856. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1857. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1858. newprescribe.CreatedTime = time.Now().Unix()
  1859. newprescribe.UpdatedTime = time.Now().Unix()
  1860. newprescribe.RecordDate = recordDate.Unix()
  1861. newprescribe.DewaterAmount = dewater_amount
  1862. newprescribe.TargetUltrafiltration = dewater_amount
  1863. newprescribe.Status = 1
  1864. err := service.AddSigleRecord(&newprescribe)
  1865. if err != nil {
  1866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1867. }
  1868. }
  1869. if dialysisPrescribe == nil && dialysisSolution == nil {
  1870. if lastDialysisPrescribe != nil {
  1871. var newprescribe models.DialysisPrescription
  1872. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1873. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1874. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1875. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1876. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1877. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1878. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1879. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1880. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1881. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1882. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1883. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1884. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1885. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1886. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1887. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1888. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1889. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1890. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1891. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1892. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1893. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1894. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1895. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1896. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1897. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1898. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1899. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1900. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1901. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1902. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1903. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1904. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1905. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1906. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1907. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1908. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1909. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1910. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1911. newprescribe.CreatedTime = time.Now().Unix()
  1912. newprescribe.UpdatedTime = time.Now().Unix()
  1913. newprescribe.RecordDate = recordDate.Unix()
  1914. newprescribe.DewaterAmount = dewater_amount
  1915. newprescribe.TargetUltrafiltration = dewater_amount
  1916. newprescribe.Status = 1
  1917. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1918. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1919. err := service.AddSigleRecord(&newprescribe)
  1920. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1921. redis := service.RedisClient()
  1922. defer redis.Close()
  1923. //清空key 值
  1924. redis.Set(key, "", time.Second)
  1925. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1926. redis.Set(keyOne, "", time.Second)
  1927. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1928. redis.Set(keyThree, "", time.Second)
  1929. if err != nil {
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1931. }
  1932. } else {
  1933. var newprescribe models.DialysisPrescription
  1934. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1935. newprescribe.PatientId = patient
  1936. newprescribe.ModeId = mode_id
  1937. newprescribe.CreatedTime = time.Now().Unix()
  1938. newprescribe.UpdatedTime = time.Now().Unix()
  1939. newprescribe.RecordDate = recordDate.Unix()
  1940. newprescribe.DewaterAmount = dewater_amount
  1941. newprescribe.TargetUltrafiltration = dewater_amount
  1942. newprescribe.Status = 1
  1943. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1944. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1945. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  1946. err := service.AddSigleRecord(&newprescribe)
  1947. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1948. redis := service.RedisClient()
  1949. defer redis.Close()
  1950. //清空key 值
  1951. redis.Set(key, "", time.Second)
  1952. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1953. redis.Set(keyOne, "", time.Second)
  1954. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1955. redis.Set(keyThree, "", time.Second)
  1956. if err != nil {
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1958. }
  1959. }
  1960. }
  1961. }
  1962. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1963. redis := service.RedisClient()
  1964. //清空key 值
  1965. redis.Set(key, "", time.Second)
  1966. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1967. redis.Set(keyOne, "", time.Second)
  1968. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1969. redis.Set(keyTwo, "", time.Second)
  1970. defer redis.Close()
  1971. if err == nil {
  1972. c.ServeSuccessJSON(map[string]interface{}{
  1973. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1974. })
  1975. } else {
  1976. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1978. }
  1979. } else { //修改
  1980. //if appRole.UserType == 3 {
  1981. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1982. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1983. // if getPermissionErr != nil {
  1984. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1985. // return
  1986. // } else if headNursePermission == nil {
  1987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1988. // return
  1989. // }
  1990. // }
  1991. //}
  1992. if appRole.UserType == 2 || appRole.UserType == 1 {
  1993. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1994. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1995. } else {
  1996. if evaluation.Creater == 0 {
  1997. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1998. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1999. } else {
  2000. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2001. }
  2002. }
  2003. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2004. assessmentBeforeDislysis.ID = evaluation.ID
  2005. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2006. //
  2007. //新增逻辑
  2008. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2009. var dewater_amount float64
  2010. dewater_amount = 0
  2011. if evaluation.DryWeight > 0 {
  2012. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2013. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2014. dewater_amount = dewater_amount * 1000
  2015. }
  2016. if dewater_amount <= 0 {
  2017. dewater_amount = 0
  2018. }
  2019. } else {
  2020. dewater_amount = 0
  2021. }
  2022. // 计算透析处方的相关超滤量
  2023. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2024. var lastDialysisPrescribe *models.DialysisPrescription
  2025. var dialysisSolution *models.DialysisSolution
  2026. var dialysisPrescribe *models.DialysisPrescription
  2027. var mode_id int64
  2028. if schedual != nil {
  2029. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2030. if dialysisPrescribe == nil {
  2031. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2032. }
  2033. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2034. // 获取透析模版
  2035. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2036. mode_id = schedual.ModeId
  2037. } else {
  2038. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2039. // 获取透析模版
  2040. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2041. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2042. if dialysisPrescribe == nil && dialysisSolution != nil {
  2043. mode_id = dialysisSolution.ModeId
  2044. }
  2045. if dialysisPrescribe == nil && dialysisSolution == nil {
  2046. mode_id = 0
  2047. }
  2048. }
  2049. // 插入透析处方
  2050. if dialysisPrescribe == nil && dialysisSolution != nil {
  2051. var newprescribe models.DialysisPrescription
  2052. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2053. newprescribe.PatientId = dialysisSolution.PatientId
  2054. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2055. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2056. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2057. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2058. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2059. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2060. newprescribe.ModeId = dialysisSolution.ModeId
  2061. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2062. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2063. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2064. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2065. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2066. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2067. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2068. newprescribe.Glucose = dialysisSolution.Glucose
  2069. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2070. newprescribe.Kalium = dialysisSolution.Kalium
  2071. newprescribe.Sodium = dialysisSolution.Sodium
  2072. newprescribe.Calcium = dialysisSolution.Calcium
  2073. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2074. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2075. newprescribe.Conductivity = dialysisSolution.Conductivity
  2076. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2077. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2078. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2079. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2080. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2081. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2082. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2083. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2084. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2085. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2086. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2087. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2088. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2089. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2090. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2091. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2092. newprescribe.CreatedTime = time.Now().Unix()
  2093. newprescribe.UpdatedTime = time.Now().Unix()
  2094. newprescribe.RecordDate = recordDate.Unix()
  2095. newprescribe.DewaterAmount = dewater_amount
  2096. newprescribe.TargetUltrafiltration = dewater_amount
  2097. newprescribe.Status = 1
  2098. err := service.AddSigleRecord(&newprescribe)
  2099. if err != nil {
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2101. }
  2102. }
  2103. if dialysisPrescribe == nil && dialysisSolution == nil {
  2104. if lastDialysisPrescribe != nil {
  2105. var newprescribe models.DialysisPrescription
  2106. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2107. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2108. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2109. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2110. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2111. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2112. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2113. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2114. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2115. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2116. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2117. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2118. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2119. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2120. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2121. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2122. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2123. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2124. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2125. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2126. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2127. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2128. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2129. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2130. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2131. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2132. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2133. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2134. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2135. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2136. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2137. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2138. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2139. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2140. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2141. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2142. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2143. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2144. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2145. newprescribe.CreatedTime = time.Now().Unix()
  2146. newprescribe.UpdatedTime = time.Now().Unix()
  2147. newprescribe.RecordDate = recordDate.Unix()
  2148. newprescribe.DewaterAmount = dewater_amount
  2149. newprescribe.TargetUltrafiltration = dewater_amount
  2150. newprescribe.Status = 1
  2151. err := service.AddSigleRecord(&newprescribe)
  2152. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2153. redis := service.RedisClient()
  2154. defer redis.Close()
  2155. //清空key 值
  2156. redis.Set(key, "", time.Second)
  2157. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2158. redis.Set(keyOne, "", time.Second)
  2159. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2160. redis.Set(keyThree, "", time.Second)
  2161. if err != nil {
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2163. }
  2164. } else {
  2165. var newprescribe models.DialysisPrescription
  2166. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2167. newprescribe.PatientId = patient
  2168. newprescribe.ModeId = mode_id
  2169. newprescribe.CreatedTime = time.Now().Unix()
  2170. newprescribe.UpdatedTime = time.Now().Unix()
  2171. newprescribe.RecordDate = recordDate.Unix()
  2172. newprescribe.DewaterAmount = dewater_amount
  2173. newprescribe.TargetUltrafiltration = dewater_amount
  2174. newprescribe.Status = 1
  2175. err := service.AddSigleRecord(&newprescribe)
  2176. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2177. redis := service.RedisClient()
  2178. defer redis.Close()
  2179. //清空key 值
  2180. redis.Set(key, "", time.Second)
  2181. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2182. redis.Set(keyOne, "", time.Second)
  2183. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2184. redis.Set(keyThree, "", time.Second)
  2185. if err != nil {
  2186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2187. }
  2188. }
  2189. }
  2190. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2191. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2192. redis := service.RedisClient()
  2193. //清空key 值
  2194. redis.Set(key, "", time.Second)
  2195. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2196. redis.Set(keyOne, "", time.Second)
  2197. defer redis.Close()
  2198. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2199. redis.Set(keyTwo, "", time.Second)
  2200. if err == nil {
  2201. c.ServeSuccessJSON(map[string]interface{}{
  2202. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2203. })
  2204. } else {
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2206. }
  2207. }
  2208. }
  2209. func (c *DialysisApiController) PostTreatmentSummary() {
  2210. patient, _ := c.GetInt64("patient", 0)
  2211. recordDateStr := c.GetString("record_date")
  2212. if patient <= 0 {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2214. return
  2215. }
  2216. adminUserInfo := c.GetAdminUserInfo()
  2217. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2218. if patientInfo.ID == 0 {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2220. return
  2221. }
  2222. if len(recordDateStr) == 0 {
  2223. recordDateStr = time.Now().Format("2006-01-02")
  2224. }
  2225. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2226. if parseDateErr != nil {
  2227. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2229. return
  2230. }
  2231. mission := c.GetString("mission")
  2232. dialysis_summary := c.GetString("dialysis_summary")
  2233. nursingRecord := c.GetString("nursing_record")
  2234. specialRecord := c.GetString("special_record")
  2235. sj_nurse := adminUserInfo.AdminUser.Id
  2236. zl_nurse := adminUserInfo.AdminUser.Id
  2237. hd_nurse := adminUserInfo.AdminUser.Id
  2238. xj_nurse := adminUserInfo.AdminUser.Id
  2239. zl_doctor := adminUserInfo.AdminUser.Id
  2240. treatmentSummary := models.TreatmentSummary{
  2241. UserOrgId: adminUserInfo.CurrentOrgId,
  2242. PatientId: patient,
  2243. AssessmentDate: recordDate.Unix(),
  2244. Mission: mission,
  2245. DialysisSummary: dialysis_summary,
  2246. SjNurse: sj_nurse,
  2247. ZlNurse: zl_nurse,
  2248. HdNurse: hd_nurse,
  2249. XjNurse: xj_nurse,
  2250. ZlDoctor: zl_doctor,
  2251. Status: 1,
  2252. CreatedTime: time.Now().Unix(),
  2253. NursingRecord: nursingRecord,
  2254. SpecialRecord: specialRecord,
  2255. }
  2256. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2257. if tempTreatmentSummary.ID == 0 { //新增
  2258. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2259. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2260. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2261. redis := service.RedisClient()
  2262. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2263. redis.Set(keyOne, "", time.Second)
  2264. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2265. redis.Set(keyThree, "", time.Second)
  2266. defer redis.Close()
  2267. //清空key 值
  2268. redis.Set(key, "", time.Second)
  2269. if err == nil {
  2270. c.ServeSuccessJSON(map[string]interface{}{
  2271. "summary": treatmentSummary,
  2272. })
  2273. } else {
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2275. }
  2276. } else { //修改
  2277. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2278. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2279. // if getPermissionErr != nil {
  2280. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2281. // return
  2282. // } else if headNursePermission == nil {
  2283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2284. // return
  2285. // }
  2286. //}
  2287. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2288. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2289. treatmentSummary.UpdatedTime = time.Now().Unix()
  2290. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2291. treatmentSummary.ID = tempTreatmentSummary.ID
  2292. err := service.UpdateSummeRecord(&treatmentSummary)
  2293. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2294. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2295. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2296. //清空key 值
  2297. redis := service.RedisClient()
  2298. redis.Set(key, "", time.Second)
  2299. redis.Set(keyOne, "", time.Second)
  2300. redis.Set(keyThree, "", time.Second)
  2301. defer redis.Close()
  2302. if err == nil {
  2303. c.ServeSuccessJSON(map[string]interface{}{
  2304. "summary": treatmentSummary,
  2305. })
  2306. } else {
  2307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2308. }
  2309. }
  2310. }
  2311. func (c *DialysisApiController) GetDeviceList() {
  2312. adminUserInfo := c.GetAdminUserInfo()
  2313. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2314. c.ServeSuccessJSON(map[string]interface{}{
  2315. "device": device,
  2316. })
  2317. }
  2318. func (c *DialysisApiController) GetAllDeviceZone() {
  2319. adminUserInfo := c.GetAdminUserInfo()
  2320. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2321. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2322. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2323. if err == nil {
  2324. c.ServeSuccessJSON(map[string]interface{}{
  2325. "zone": zone,
  2326. "dics": dics,
  2327. "efs": efs,
  2328. })
  2329. }
  2330. }
  2331. func (c *DialysisApiController) GetDialysisWatch() {
  2332. page, _ := c.GetInt64("page", 1)
  2333. limit, _ := c.GetInt64("limit", 10)
  2334. schedulType, _ := c.GetInt64("schedul_type", 0)
  2335. startTime, _ := c.GetInt64("schedul_time", 0)
  2336. partitionType, _ := c.GetInt64("partition_type", 0)
  2337. keywords := c.GetString("keywords")
  2338. start_time, _ := c.GetInt64("start_time")
  2339. end_time, _ := c.GetInt64("end_time")
  2340. adminUserInfo := c.GetAdminUserInfo()
  2341. if len(keywords) > 0 {
  2342. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2343. if err == nil {
  2344. c.ServeSuccessJSON(map[string]interface{}{
  2345. "schedule": dialysisSchedule,
  2346. "total": total,
  2347. })
  2348. } else {
  2349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2350. }
  2351. } else {
  2352. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2353. if err == nil {
  2354. c.ServeSuccessJSON(map[string]interface{}{
  2355. "schedule": dialysisSchedule,
  2356. "total": total,
  2357. })
  2358. } else {
  2359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2360. }
  2361. }
  2362. }
  2363. //func (c *DialysisApiController) GetDialysisWatch() {
  2364. // page, _ := c.GetInt64("page", 1)
  2365. // limit, _ := c.GetInt64("limit", 10)
  2366. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2367. // startTime, _ := c.GetInt64("schedul_time", 0)
  2368. // partitionType, _ := c.GetInt64("partition_type", 0)
  2369. // keywords := c.GetString("keywords")
  2370. //
  2371. // adminUserInfo := c.GetAdminUserInfo()
  2372. // if len(keywords) > 0 {
  2373. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2374. //
  2375. // //获取所有床位号
  2376. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2377. //
  2378. // //获取透析处方
  2379. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2380. // //获取透前评估
  2381. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2382. // //获取上机
  2383. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2384. // //获取透后
  2385. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2386. //
  2387. // //获取透后监测
  2388. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2389. //
  2390. // //获取所有的患者
  2391. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2392. //
  2393. // //获取所有透析模式
  2394. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2395. //
  2396. // for key, scheduals := range dialysisSchedule {
  2397. // // 获取患者信息
  2398. // for _, patient := range patients {
  2399. // if scheduals.PatientId == patient.ID {
  2400. // dialysisSchedule[key].MonitorPatients = patient
  2401. // break
  2402. // }
  2403. // }
  2404. // // 床位信息
  2405. // for _, device := range numberList {
  2406. // if scheduals.BedId == device.ID {
  2407. // dialysisSchedule[key].DeviceNumber = device
  2408. // break
  2409. // }
  2410. // }
  2411. //
  2412. // // 医嘱信息
  2413. // for _, prescription := range prescriptions {
  2414. // if scheduals.PatientId == prescription.PatientId {
  2415. // dialysisSchedule[key].Prescription = prescription
  2416. // break
  2417. // }
  2418. // }
  2419. //
  2420. // // 透前评估
  2421. // for _, assessmentBefore := range assessmentBefores {
  2422. // if scheduals.PatientId == assessmentBefore.PatientId {
  2423. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2424. // break
  2425. // }
  2426. // }
  2427. //
  2428. // // 透析上下机
  2429. // for _, dialysisOrder := range dialysisOrders {
  2430. // if scheduals.PatientId == dialysisOrder.PatientId {
  2431. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2432. // break
  2433. // }
  2434. // }
  2435. //
  2436. // records := make([]*models.MonitoringRecord, 0)
  2437. // // 透析监测
  2438. // for _, it := range monitorlist {
  2439. // records := append(records, it)
  2440. // if scheduals.PatientId == it.PatientId {
  2441. // dialysisSchedule[key].MonitoringRecord = records
  2442. // }
  2443. // }
  2444. //
  2445. // // 透后评估
  2446. // for _, afterDislysis := range AssessmentAfterDislysis {
  2447. // if scheduals.PatientId == afterDislysis.PatientId {
  2448. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2449. // break
  2450. // }
  2451. // }
  2452. //
  2453. // //透析模式
  2454. // for _, treatment := range treatments {
  2455. // if scheduals.ModeId == treatment.ID {
  2456. // dialysisSchedule[key].TreatmentMode = treatment
  2457. // break
  2458. // }
  2459. // }
  2460. // }
  2461. // //获取所有床位号
  2462. // if err == nil {
  2463. // c.ServeSuccessJSON(map[string]interface{}{
  2464. // "schedule": dialysisSchedule,
  2465. // "total": total,
  2466. // })
  2467. // } else {
  2468. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2469. // }
  2470. //
  2471. // } else {
  2472. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2473. // if err == nil {
  2474. // c.ServeSuccessJSON(map[string]interface{}{
  2475. // "schedule": dialysisSchedule,
  2476. // "total": total,
  2477. // })
  2478. // } else {
  2479. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. // }
  2481. // }
  2482. //}
  2483. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2484. patientId, _ := c.GetInt64("id", 0)
  2485. record_date, _ := c.GetInt64("record_date", 0)
  2486. adminUserInfo := c.GetAdminUserInfo()
  2487. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2488. var dialysisStatus int64
  2489. if dialysisOrder == nil { //没有透析记录
  2490. dialysisStatus = 0 //未透析
  2491. } else {
  2492. dialysisStatus = dialysisOrder.Stage
  2493. }
  2494. //用户基本信息
  2495. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2496. //接诊评估
  2497. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2498. //透前评估
  2499. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2500. //临时医嘱
  2501. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2502. //双人核对
  2503. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2504. //透析监测
  2505. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2506. //透后评估
  2507. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2508. //透析小结
  2509. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2510. //透析处方
  2511. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2512. if dialysisPrescription.ID == 0 {
  2513. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2514. c.ServeSuccessJSON(map[string]interface{}{
  2515. "patientInfo": schedualPatientInfo,
  2516. "dialysisPrescription": solution,
  2517. "receiverTreatmentAccess": receiverTreatmentAccess,
  2518. "predialysisEvaluation": PredialysisEvaluation,
  2519. "doctorAdvice": DoctorAdvice,
  2520. "doubleCheck": DoubleCheck,
  2521. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2522. "treatmentSummary": TreatmentSummary,
  2523. "monitorRecord": Record,
  2524. "dialysisStatus": dialysisStatus,
  2525. "dialysisOrder": dialysisOrder,
  2526. "isSolution": 1,
  2527. })
  2528. } else {
  2529. c.ServeSuccessJSON(map[string]interface{}{
  2530. "patientInfo": schedualPatientInfo,
  2531. "dialysisPrescription": dialysisPrescription,
  2532. "receiverTreatmentAccess": receiverTreatmentAccess,
  2533. "predialysisEvaluation": PredialysisEvaluation,
  2534. "doctorAdvice": DoctorAdvice,
  2535. "doubleCheck": DoubleCheck,
  2536. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2537. "treatmentSummary": TreatmentSummary,
  2538. "monitorRecord": Record,
  2539. "dialysisStatus": dialysisStatus,
  2540. "dialysisOrder": dialysisOrder,
  2541. "isSolution": 2,
  2542. })
  2543. }
  2544. }
  2545. func (c *DialysisApiController) CreateDoctorAdvice() {
  2546. patient, _ := c.GetInt64("id", 0)
  2547. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2548. record_date, _ := c.GetInt64("record_date", 0)
  2549. if patient <= 0 {
  2550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2551. return
  2552. }
  2553. adminUserInfo := c.GetAdminUserInfo()
  2554. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2555. if patientInfo.ID == 0 {
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2557. return
  2558. }
  2559. var advice models.DoctorAdvice
  2560. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2561. if code > 0 {
  2562. c.ServeFailJSONWithSGJErrorCode(code)
  2563. return
  2564. }
  2565. if advice.ParentId > 0 {
  2566. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2567. if old.ID == 0 || old.PatientId != patient {
  2568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2569. return
  2570. }
  2571. if old.StopState == 1 || old.ExecutionState == 1 {
  2572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2573. return
  2574. }
  2575. if old.ParentId > 0 {
  2576. advice.ParentId = old.ParentId
  2577. }
  2578. advice.StartTime = old.StartTime
  2579. advice.AdviceDoctor = old.AdviceDoctor
  2580. advice.DeliveryWay = old.DeliveryWay
  2581. advice.ExecutionFrequency = old.ExecutionFrequency
  2582. }
  2583. advice.RecordDate = record_date
  2584. advice.DialysisOrderId = dialysis_id
  2585. advice.Status = 1
  2586. advice.CreatedTime = time.Now().Unix()
  2587. advice.UpdatedTime = time.Now().Unix()
  2588. advice.StopState = 2
  2589. advice.ExecutionState = 2
  2590. advice.AdviceType = 2
  2591. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2592. advice.PatientId = patient
  2593. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2594. err := service.CreateDoctorAdvice(&advice)
  2595. if err != nil {
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2597. return
  2598. }
  2599. for _, subAdvice := range subAdivice {
  2600. subAdvice.ParentId = advice.ID
  2601. subAdvice.PatientId = patient
  2602. subAdvice.RecordDate = record_date
  2603. subAdvice.CreatedTime = time.Now().Unix()
  2604. subAdvice.UpdatedTime = time.Now().Unix()
  2605. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2606. }
  2607. service.CreateSubDoctorAdvice(subAdivice)
  2608. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2609. c.ServeSuccessJSON(map[string]interface{}{
  2610. "msg": "ok",
  2611. "advice": advice,
  2612. "subAdvice": subAdivices,
  2613. })
  2614. return
  2615. }
  2616. func (c *DialysisApiController) EditDoctorAdvice() {
  2617. patient, _ := c.GetInt64("patient", 0)
  2618. id, _ := c.GetInt64("id", 0)
  2619. parent_id, _ := c.GetInt64("parent_id", 0)
  2620. execution_time := c.GetString("execution_time")
  2621. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2622. // checker, _ := c.GetInt64("checker", 0)
  2623. if id <= 0 || patient <= 0 {
  2624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2625. return
  2626. }
  2627. adminUserInfo := c.GetAdminUserInfo()
  2628. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2629. if advice.ID == 0 || advice.PatientId != patient {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2631. return
  2632. }
  2633. if len(execution_time) <= 0 {
  2634. utils.ErrorLog("execution_time")
  2635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2636. return
  2637. }
  2638. execution_staff := adminUserInfo.AdminUser.Id
  2639. checker := adminUserInfo.AdminUser.Id
  2640. timeLayout2 := "2006-01-02 15:04"
  2641. loc, _ := time.LoadLocation("Local")
  2642. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2643. if errs != nil {
  2644. utils.ErrorLog(errs.Error())
  2645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2646. return
  2647. }
  2648. advices := models.DoctorAdvice{
  2649. ExecutionStaff: execution_staff,
  2650. ExecutionTime: theTime.Unix(),
  2651. Checker: checker,
  2652. UpdatedTime: time.Now().Unix(),
  2653. }
  2654. var err error
  2655. if parent_id > 0 {
  2656. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2657. } else {
  2658. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2659. }
  2660. if err != nil {
  2661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2662. return
  2663. }
  2664. c.ServeSuccessJSON(map[string]interface{}{
  2665. "msg": "ok",
  2666. "advice": advice,
  2667. })
  2668. return
  2669. }
  2670. func (c *DialysisApiController) GetDoctorAdvice() {
  2671. patient, _ := c.GetInt64("patient_id", 0)
  2672. parent_id, _ := c.GetInt64("parent_id", 0)
  2673. adviceId, _ := c.GetInt64("id", 0)
  2674. if patient <= 0 {
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2676. return
  2677. }
  2678. dminUserInfo := c.GetAdminUserInfo()
  2679. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2680. if patientInfo.ID == 0 {
  2681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2682. return
  2683. }
  2684. var subAdvice []*models.DoctorAdvice
  2685. var advice models.DoctorAdvice
  2686. if parent_id > 0 {
  2687. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2688. if advice.ID == 0 || advice.PatientId != patient {
  2689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2690. return
  2691. }
  2692. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2693. } else {
  2694. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2695. if advice.ID == 0 || advice.PatientId != patient {
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2697. return
  2698. }
  2699. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2700. }
  2701. c.ServeSuccessJSON(map[string]interface{}{
  2702. "msg": "ok",
  2703. "advice": advice,
  2704. "subAdvice": subAdvice,
  2705. })
  2706. }
  2707. func (this *DialysisApiController) DelMonitor() {
  2708. recordID, _ := this.GetInt64("record_id")
  2709. patientID, _ := this.GetInt64("patient_id")
  2710. if recordID <= 0 || patientID <= 0 {
  2711. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2712. return
  2713. }
  2714. adminInfo := this.GetAdminUserInfo()
  2715. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2716. if getPatientErr != nil {
  2717. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2719. return
  2720. } else if patient == nil {
  2721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2722. return
  2723. }
  2724. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2725. if getMonitorErr != nil {
  2726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2727. return
  2728. }
  2729. //if monitor != nil {
  2730. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2731. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2732. // if getPermissionErr != nil {
  2733. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. // return
  2735. // } else if headNursePermission == nil {
  2736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2737. // return
  2738. // }
  2739. // }
  2740. //}
  2741. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2742. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2743. redis := service.RedisClient()
  2744. //清空key 值
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2747. redis.Set(keyOne, "", time.Second)
  2748. defer redis.Close()
  2749. if err != nil {
  2750. this.ErrorLog("删除透析监测记录失败:%v", err)
  2751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2752. return
  2753. }
  2754. this.ServeSuccessJSON(map[string]interface{}{
  2755. "record_id": monitor.ID,
  2756. })
  2757. }
  2758. func (c *DialysisApiController) CreateMonitor() {
  2759. patient, _ := c.GetInt64("id", 0)
  2760. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2761. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2762. operate_time, _ := c.GetInt64("operate_time", 0)
  2763. // monitoring_time := c.GetString("monitoring_time")
  2764. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2765. breathing_rated := c.GetString("breathing_rated")
  2766. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2767. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2768. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2769. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2770. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2771. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2772. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2773. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2774. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2775. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2776. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2777. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2778. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2779. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2780. temperature, _ := c.GetFloat("temperature", 0)
  2781. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2782. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2783. conductivity, _ := c.GetFloat("conductivity", 0)
  2784. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2785. heparin, _ := c.GetFloat("heparin", 0)
  2786. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2787. ktv, _ := c.GetFloat("ktv", 0)
  2788. symptom := c.GetString("symptom")
  2789. dispose := c.GetString("dispose")
  2790. result := c.GetString("results")
  2791. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2792. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2793. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2794. monitoring_date = monitoring_date / 1000
  2795. // operate_time = operate_time / 1000
  2796. if patient <= 0 {
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2798. return
  2799. }
  2800. adminUserInfo := c.GetAdminUserInfo()
  2801. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2802. if patientInfo.ID == 0 {
  2803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2804. return
  2805. }
  2806. monitorRecord := models.MonitoringRecord{
  2807. PatientId: patient,
  2808. MonitoringDate: monitoring_date,
  2809. DialysisOrderId: dialysis_order_id,
  2810. OperateTime: operate_time,
  2811. // MonitoringTime: monitoring_time,
  2812. PulseFrequency: pulse_frequency,
  2813. BreathingRate: breathing_rated,
  2814. SystolicBloodPressure: systolic_blood_pressure,
  2815. DiastolicBloodPressure: diastolic_blood_pressure,
  2816. BloodPressureType: blood_pressure_type,
  2817. BloodFlowVolume: blood_flow_volume,
  2818. VenousPressure: venous_pressure,
  2819. VenousPressureType: venous_pressure_type,
  2820. TransmembranePressure: transmembrane_pressure,
  2821. TransmembranePressureType: transmembrane_pressure_type,
  2822. UltrafiltrationRate: ultrafiltration_rate,
  2823. UltrafiltrationVolume: ultrafiltration_volume,
  2824. SodiumConcentration: sodium_concentration,
  2825. ArterialPressure: arterial_pressure,
  2826. ArterialPressureType: arterial_pressure_type,
  2827. DialysateTemperature: dialysate_temperature,
  2828. Temperature: temperature,
  2829. ReplacementRate: replacement_rate,
  2830. DisplacementQuantity: displacement_quantity,
  2831. Ktv: ktv,
  2832. Symptom: symptom,
  2833. Dispose: dispose,
  2834. Result: result,
  2835. MonitoringNurse: monitoring_nurse,
  2836. Status: 1,
  2837. CreatedTime: time.Now().Unix(),
  2838. UpdatedTime: time.Now().Unix(),
  2839. UserOrgId: adminUserInfo.CurrentOrgId,
  2840. Conductivity: conductivity,
  2841. DisplacementFlowQuantity: displacement_flow_quantity,
  2842. Heparin: heparin,
  2843. DialysateFlow: dialysate_flow,
  2844. MonitorAnticoagulant: monitor_anticoagulant,
  2845. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2846. }
  2847. err := service.CreateMonitor(&monitorRecord)
  2848. redis := service.RedisClient()
  2849. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2850. redis.Set(key, "", time.Second)
  2851. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2852. redis.Set(keyOne, "", time.Second)
  2853. redis.Close()
  2854. if err != nil {
  2855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2856. return
  2857. }
  2858. c.ServeSuccessJSON(map[string]interface{}{
  2859. "msg": "ok",
  2860. "monitor": monitorRecord,
  2861. })
  2862. return
  2863. }
  2864. // 已弃用
  2865. // func (c *DialysisApiController) CreateRecordData() {
  2866. // patient, _ := c.GetInt64("id", 0)
  2867. // status, _ := c.GetInt64("status", 0)
  2868. // now := time.Now()
  2869. // year, month, day := now.Date()
  2870. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2871. // todayTimeStamp := today_time.Unix()
  2872. // if patient <= 0 {
  2873. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2874. // return
  2875. // }
  2876. // adminUserInfo := c.GetAdminUserInfo()
  2877. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2878. // if patientInfo.ID == 0 {
  2879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2880. // return
  2881. // }
  2882. // record := &models.DialysisOrder{
  2883. // DialysisDate: todayTimeStamp,
  2884. // UserOrgId: adminUserInfo.CurrentOrgId,
  2885. // PatientId: patient,
  2886. // Stage: status,
  2887. // Status: 1,
  2888. // CreatedTime: time.Now().Unix(),
  2889. // UpdatedTime: time.Now().Unix(),
  2890. // }
  2891. // if status == 1 {
  2892. // //创建透析记录
  2893. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2894. // if err == nil {
  2895. // c.ServeSuccessJSON(map[string]interface{}{
  2896. // "dialysisOrder": record,
  2897. // })
  2898. // } else {
  2899. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2900. // }
  2901. // } else {
  2902. // record_id, _ := c.GetInt64("record_id", 0)
  2903. // //修改透析记录状态
  2904. // errs := service.ModifyDialysisRecord(record_id)
  2905. // //结束时候透析次数加1
  2906. // service.UpdateSolutionByPatientId(patient)
  2907. // if errs == nil {
  2908. // c.ServeSuccessJSON(map[string]interface{}{
  2909. // "dialysisOrder": record,
  2910. // })
  2911. // } else {
  2912. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2913. // }
  2914. // }
  2915. // }
  2916. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2917. dataBody := make(map[string]interface{}, 0)
  2918. err := json.Unmarshal(data, &dataBody)
  2919. if err != nil {
  2920. utils.ErrorLog(err.Error())
  2921. code = enums.ErrorCodeParamWrong
  2922. return
  2923. }
  2924. timeLayout := "2006-01-02 "
  2925. timeLayout2 := "2006-01-02 15:04"
  2926. loc, _ := time.LoadLocation("Local")
  2927. if action == "create" {
  2928. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2929. utils.ErrorLog("advice_type")
  2930. code = enums.ErrorCodeParamWrong
  2931. return
  2932. }
  2933. adviceType := int64(dataBody["advice_type"].(float64))
  2934. if adviceType != 1 && adviceType != 2 {
  2935. utils.ErrorLog("advice_type != 1&&2")
  2936. code = enums.ErrorCodeParamWrong
  2937. return
  2938. }
  2939. advice.AdviceType = adviceType
  2940. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2941. utils.ErrorLog("advice_date")
  2942. code = enums.ErrorCodeParamWrong
  2943. return
  2944. }
  2945. adviceDate, _ := dataBody["advice_date"].(string)
  2946. if len(adviceDate) == 0 {
  2947. utils.ErrorLog("len(adviceDate) == 0")
  2948. code = enums.ErrorCodeParamWrong
  2949. return
  2950. }
  2951. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2952. if err != nil {
  2953. utils.ErrorLog(err.Error())
  2954. code = enums.ErrorCodeParamWrong
  2955. return
  2956. }
  2957. advice.AdviceDate = theTime.Unix()
  2958. }
  2959. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2960. utils.ErrorLog("start_time")
  2961. code = enums.ErrorCodeParamWrong
  2962. return
  2963. }
  2964. startDate, _ := dataBody["start_time"].(string)
  2965. if len(startDate) == 0 {
  2966. utils.ErrorLog("len(startDate) == 0")
  2967. code = enums.ErrorCodeParamWrong
  2968. return
  2969. }
  2970. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2971. if err != nil {
  2972. utils.ErrorLog(err.Error())
  2973. code = enums.ErrorCodeParamWrong
  2974. return
  2975. }
  2976. advice.StartTime = theTime.Unix()
  2977. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2978. utils.ErrorLog("advice_name")
  2979. code = enums.ErrorCodeParamWrong
  2980. return
  2981. }
  2982. adviceName, _ := dataBody["advice_name"].(string)
  2983. if len(adviceName) == 0 {
  2984. utils.ErrorLog("len(advice_name) == 0")
  2985. code = enums.ErrorCodeParamWrong
  2986. return
  2987. }
  2988. advice.AdviceName = adviceName
  2989. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2990. utils.ErrorLog("delivery_way")
  2991. code = enums.ErrorCodeParamWrong
  2992. return
  2993. }
  2994. deliveryWay, _ := dataBody["delivery_way"].(string)
  2995. if len(deliveryWay) == 0 {
  2996. utils.ErrorLog("len(deliveryWay) == 0")
  2997. code = enums.ErrorCodeParamWrong
  2998. return
  2999. }
  3000. advice.DeliveryWay = deliveryWay
  3001. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3002. utils.ErrorLog("execution_frequency")
  3003. code = enums.ErrorCodeParamWrong
  3004. return
  3005. }
  3006. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3007. if len(execution_frequency) == 0 {
  3008. utils.ErrorLog("len(execution_frequency) == 0")
  3009. code = enums.ErrorCodeParamWrong
  3010. return
  3011. }
  3012. advice.ExecutionFrequency = execution_frequency
  3013. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3014. adviceDsc, _ := dataBody["advice_desc"].(string)
  3015. advice.AdviceDesc = adviceDsc
  3016. }
  3017. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3018. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3019. advice.DrugSpecUnit = drugSpecUnit
  3020. }
  3021. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3022. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3023. advice.SingleDose = singleDose
  3024. }
  3025. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3026. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3027. advice.SingleDoseUnit = singleDoseUnit
  3028. }
  3029. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3030. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3031. advice.PrescribingNumber = prescribingNumber
  3032. }
  3033. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3034. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3035. advice.PrescribingNumberUnit = prescribingNumberUnit
  3036. }
  3037. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3038. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3039. if len(thisContagions) > 0 {
  3040. for _, item := range thisContagions {
  3041. items := item.(map[string]interface{})
  3042. advice_name, _ := items["advice_name"].(string)
  3043. advice_desc, _ := items["advice_desc"].(string)
  3044. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3045. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3046. single_dose_unit, _ := items["single_dose_unit"].(string)
  3047. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3048. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3049. advice := &models.DoctorAdvice{
  3050. AdviceName: advice_name,
  3051. AdviceDesc: advice_desc,
  3052. SingleDose: single_dose,
  3053. SingleDoseUnit: single_dose_unit,
  3054. DrugSpecUnit: drug_spec_unit,
  3055. PrescribingNumber: prescribing_number,
  3056. PrescribingNumberUnit: prescribing_number_unit,
  3057. }
  3058. subAdvice = append(subAdvice, advice)
  3059. }
  3060. }
  3061. }
  3062. return
  3063. }
  3064. func (c *DialysisApiController) GetDialysisOrder() {
  3065. xtno := c.GetString("xtno")
  3066. xtdate := c.GetString("xtdate")
  3067. timeLayout := "2006-01-02"
  3068. loc, _ := time.LoadLocation("Local")
  3069. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3070. if err != nil {
  3071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3072. return
  3073. }
  3074. xttime := theTime.Unix()
  3075. operatorIDs := make([]int64, 0)
  3076. adminUserInfo := c.GetAdminUserInfo()
  3077. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3078. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3079. //透析单
  3080. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3081. if dialysisOrder != nil {
  3082. if dialysisOrder.FinishNurse > 0 {
  3083. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3084. }
  3085. if dialysisOrder.StartNurse > 0 {
  3086. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3087. }
  3088. }
  3089. //透前评估
  3090. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3091. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3092. //透后评估
  3093. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3094. if AssessmentAfterDislysis.Modifier > 0 {
  3095. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3096. }
  3097. //上次透前评估
  3098. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3099. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3100. //透析处方
  3101. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3102. if dialysisPrescription.PrescriptionDoctor > 0 {
  3103. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3104. }
  3105. //获取病人的透析模式
  3106. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3107. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3108. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3109. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3110. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3111. //获取透析处方
  3112. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3113. //获取临时医嘱
  3114. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3115. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3116. //获取医嘱内容
  3117. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3118. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3119. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3120. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3121. //获取上次的透后体重
  3122. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3123. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3124. //获取透析次数
  3125. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3126. if len(DoctorAdvice) > 0 {
  3127. for _, item := range DoctorAdvice {
  3128. if item.AdviceDoctor > 0 {
  3129. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3130. }
  3131. if item.ExecutionStaff > 0 {
  3132. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3133. }
  3134. if item.Checker > 0 {
  3135. operatorIDs = append(operatorIDs, item.Checker)
  3136. }
  3137. }
  3138. }
  3139. //透析监测
  3140. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3141. //透析检测
  3142. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3143. //透析小结
  3144. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3145. //接诊评估
  3146. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3147. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3148. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3149. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3150. patientInfo.TotalDialysis = dialysis_count
  3151. }
  3152. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3153. if xttime <= 1672416000 {
  3154. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3155. patientInfo.TotalDialysis = dialysis_count
  3156. }
  3157. if xttime >= 1672502400 {
  3158. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3159. patientInfo.TotalDialysis = dialysis_count
  3160. }
  3161. }
  3162. //相关操作对应的操作人
  3163. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3164. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3165. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3166. //获取当前日期月份的第一天
  3167. firstmonth := service.GetFirstDateOfMonth(theTime)
  3168. firstMonthDate := firstmonth.Unix()
  3169. //获取当前月份的病人透析次数
  3170. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3171. //获取his数据
  3172. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3173. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3174. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3175. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3176. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3177. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3178. // for _, item := range projects {
  3179. // var advice *models.HisDoctorAdviceInfo
  3180. // advice.ID = item.ID
  3181. // advice.Checker = item.Checker
  3182. // advice.CheckTime = item.CheckTime
  3183. // advice.CheckState = item.CheckState
  3184. // advice.ExecutionState = item.ExecutionState
  3185. // advice.ExecutionStaff = item.ExecutionStaff
  3186. // advice.PrescribingNumber = float64(item.Count)
  3187. // advice.PrescribingNumberUnit = item.Unit
  3188. // advice.AdviceDoctor = item.Doctor
  3189. // if item.Type == 3 {
  3190. // advice.AdviceName = item.GoodInfo.GoodName
  3191. // } else if item.Type == 2 {
  3192. // advice.AdviceName = item.HisProject.ProjectName
  3193. // }
  3194. // advice.StartTime = item.StartTime
  3195. // hisAdvice = append(hisAdvice, advice)
  3196. // }
  3197. //}
  3198. if config.IsOpen == 1 {
  3199. c.ServeSuccessJSON(map[string]interface{}{
  3200. "xtdate": xtdate,
  3201. "users": adminUser,
  3202. "patientInfo": patientInfo,
  3203. "PredialysisEvaluation": PredialysisEvaluation,
  3204. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3205. "dialysisPrescription": dialysisPrescription,
  3206. "advices": hisAdvice,
  3207. "monitors": Record,
  3208. "summary": TreatmentSummary,
  3209. "receiverTreatmentAccess": receiverTreatmentAccess,
  3210. "dialysisOrder": dialysisOrder,
  3211. "operators": operators,
  3212. "org_template_info": templateInfo,
  3213. "check": check,
  3214. "schedule": schedule,
  3215. "dialysisway": dialysisway,
  3216. "order": order,
  3217. "doctorAdvice": doctorAdvice,
  3218. "doctor": doctor,
  3219. "nurse": nurse,
  3220. "doctorAdevieInfo": doctorAdevieInfo,
  3221. "total": total,
  3222. "startNuse": startNuse,
  3223. "DoctorName": DoctorName,
  3224. "assessmentAfterDislysis": assessmentAfterDislysis,
  3225. "predialysName": predialysName,
  3226. "FinishNuse": FinishNuse,
  3227. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3228. "dialysiscount": dialysiscount,
  3229. "last_order": lastOrder,
  3230. "project_config": project_config,
  3231. "projects": projects,
  3232. })
  3233. }
  3234. if config.IsOpen == 0 || config.IsOpen == 2 {
  3235. c.ServeSuccessJSON(map[string]interface{}{
  3236. "xtdate": xtdate,
  3237. "users": adminUser,
  3238. "patientInfo": patientInfo,
  3239. "PredialysisEvaluation": PredialysisEvaluation,
  3240. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3241. "dialysisPrescription": dialysisPrescription,
  3242. "advices": DoctorAdvice,
  3243. "monitors": Record,
  3244. "summary": TreatmentSummary,
  3245. "receiverTreatmentAccess": receiverTreatmentAccess,
  3246. "dialysisOrder": dialysisOrder,
  3247. "operators": operators,
  3248. "org_template_info": templateInfo,
  3249. "check": check,
  3250. "schedule": schedule,
  3251. "dialysisway": dialysisway,
  3252. "order": order,
  3253. "doctorAdvice": doctorAdvice,
  3254. "doctor": doctor,
  3255. "nurse": nurse,
  3256. "doctorAdevieInfo": doctorAdevieInfo,
  3257. "total": total,
  3258. "startNuse": startNuse,
  3259. "DoctorName": DoctorName,
  3260. "assessmentAfterDislysis": assessmentAfterDislysis,
  3261. "predialysName": predialysName,
  3262. "FinishNuse": FinishNuse,
  3263. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3264. "dialysiscount": dialysiscount,
  3265. "last_order": lastOrder,
  3266. "project_config": project_config,
  3267. "projects": projects,
  3268. })
  3269. }
  3270. }
  3271. func (c *DialysisApiController) GetLongAdvice() {
  3272. patient_id, _ := c.GetInt64("patient_id")
  3273. adminUserInfo := c.GetAdminUserInfo()
  3274. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3275. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3276. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3277. c.ServeSuccessJSON(map[string]interface{}{
  3278. "status": "1",
  3279. })
  3280. return
  3281. } else { //开启推送提醒
  3282. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3283. var advice_three []*models.DoctorAdvice
  3284. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3285. recordDateStr := time.Now().Format("2006-01-02")
  3286. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3287. nowtime := recordDate.Unix()
  3288. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3289. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3290. for _, advice := range advices {
  3291. if advice.FrequencyType == 3 {
  3292. t := time.Now()
  3293. week := int(t.Weekday())
  3294. switch week {
  3295. case 1:
  3296. if strings.Index(advice.WeekDay, "周一") == -1 {
  3297. advice_three = append(advice_three, advice)
  3298. }
  3299. break
  3300. case 2:
  3301. if strings.Index(advice.WeekDay, "周二") == -1 {
  3302. advice_three = append(advice_three, advice)
  3303. }
  3304. break
  3305. case 3:
  3306. if strings.Index(advice.WeekDay, "周三") == -1 {
  3307. advice_three = append(advice_three, advice)
  3308. }
  3309. break
  3310. case 4:
  3311. if strings.Index(advice.WeekDay, "周四") == -1 {
  3312. advice_three = append(advice_three, advice)
  3313. }
  3314. break
  3315. case 5:
  3316. if strings.Index(advice.WeekDay, "周五") == -1 {
  3317. advice_three = append(advice_three, advice)
  3318. }
  3319. break
  3320. case 6:
  3321. if strings.Index(advice.WeekDay, "周六") == -1 {
  3322. advice_three = append(advice_three, advice)
  3323. }
  3324. break
  3325. case 0:
  3326. if strings.Index(advice.WeekDay, "周日") == -1 {
  3327. advice_three = append(advice_three, advice)
  3328. }
  3329. break
  3330. }
  3331. }
  3332. }
  3333. for _, advice := range advices_two {
  3334. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3335. now := p.Unix()
  3336. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3337. dayStr2 := "-" + dayStr
  3338. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3339. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3340. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3341. for _, ad := range advices {
  3342. advice_three = append(advice_three, ad)
  3343. }
  3344. }
  3345. if err == nil {
  3346. c.ServeSuccessJSON(map[string]interface{}{
  3347. "status": "2",
  3348. "advices": advices,
  3349. "advices_two": RemoveRepeatedElement(advice_three),
  3350. "is_open_remind": config.IsOpenRemind,
  3351. })
  3352. }
  3353. }
  3354. }
  3355. func (c *DialysisApiController) GetLongAdviceOne() {
  3356. patient_id, _ := c.GetInt64("patient_id")
  3357. schedule_date := c.GetString("schedule_date")
  3358. adminUserInfo := c.GetAdminUserInfo()
  3359. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3360. timeLayout := "2006-01-02"
  3361. loc, _ := time.LoadLocation("Local")
  3362. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3363. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3364. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3365. c.ServeSuccessJSON(map[string]interface{}{
  3366. "status": "1",
  3367. })
  3368. return
  3369. } else { //开启推送提醒
  3370. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3371. var advice_three []*models.DoctorAdvice
  3372. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3373. //recordDateStr := time.Now().Format("2006-01-02")
  3374. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3375. //
  3376. //nowtime := recordDate.Unix()
  3377. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3378. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3379. for _, advice := range advices {
  3380. if advice.FrequencyType == 3 {
  3381. t := time.Now()
  3382. week := int(t.Weekday())
  3383. switch week {
  3384. case 1:
  3385. if strings.Index(advice.WeekDay, "周一") == -1 {
  3386. advice_three = append(advice_three, advice)
  3387. }
  3388. break
  3389. case 2:
  3390. if strings.Index(advice.WeekDay, "周二") == -1 {
  3391. advice_three = append(advice_three, advice)
  3392. }
  3393. break
  3394. case 3:
  3395. if strings.Index(advice.WeekDay, "周三") == -1 {
  3396. advice_three = append(advice_three, advice)
  3397. }
  3398. break
  3399. case 4:
  3400. if strings.Index(advice.WeekDay, "周四") == -1 {
  3401. advice_three = append(advice_three, advice)
  3402. }
  3403. break
  3404. case 5:
  3405. if strings.Index(advice.WeekDay, "周五") == -1 {
  3406. advice_three = append(advice_three, advice)
  3407. }
  3408. break
  3409. case 6:
  3410. if strings.Index(advice.WeekDay, "周六") == -1 {
  3411. advice_three = append(advice_three, advice)
  3412. }
  3413. break
  3414. case 0:
  3415. if strings.Index(advice.WeekDay, "周日") == -1 {
  3416. advice_three = append(advice_three, advice)
  3417. }
  3418. break
  3419. }
  3420. }
  3421. }
  3422. for _, advice := range advices_two {
  3423. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3424. now := p.Unix()
  3425. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3426. dayStr2 := "-" + dayStr
  3427. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3428. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3429. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3430. for _, ad := range advices {
  3431. advice_three = append(advice_three, ad)
  3432. }
  3433. }
  3434. if err == nil {
  3435. c.ServeSuccessJSON(map[string]interface{}{
  3436. "status": "2",
  3437. "advices": advices,
  3438. "advices_two": RemoveRepeatedElement(advice_three),
  3439. "is_open_remind": config.IsOpenRemind,
  3440. })
  3441. }
  3442. }
  3443. }
  3444. func (c *DialysisApiController) GetLongAdviceTwo() {
  3445. patient_id, _ := c.GetInt64("patient_id")
  3446. schedule_date, _ := c.GetInt64("schedule_date")
  3447. adminUserInfo := c.GetAdminUserInfo()
  3448. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3449. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3450. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3451. c.ServeSuccessJSON(map[string]interface{}{
  3452. "status": "1",
  3453. })
  3454. return
  3455. } else { //开启推送提醒
  3456. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3457. var advice_three []*models.DoctorAdvice
  3458. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3459. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3460. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3461. for _, advice := range advices {
  3462. if advice.FrequencyType == 3 {
  3463. t := time.Now()
  3464. week := int(t.Weekday())
  3465. switch week {
  3466. case 1:
  3467. if strings.Index(advice.WeekDay, "周一") == -1 {
  3468. advice_three = append(advice_three, advice)
  3469. }
  3470. break
  3471. case 2:
  3472. if strings.Index(advice.WeekDay, "周二") == -1 {
  3473. advice_three = append(advice_three, advice)
  3474. }
  3475. break
  3476. case 3:
  3477. if strings.Index(advice.WeekDay, "周三") == -1 {
  3478. advice_three = append(advice_three, advice)
  3479. }
  3480. break
  3481. case 4:
  3482. if strings.Index(advice.WeekDay, "周四") == -1 {
  3483. advice_three = append(advice_three, advice)
  3484. }
  3485. break
  3486. case 5:
  3487. if strings.Index(advice.WeekDay, "周五") == -1 {
  3488. advice_three = append(advice_three, advice)
  3489. }
  3490. break
  3491. case 6:
  3492. if strings.Index(advice.WeekDay, "周六") == -1 {
  3493. advice_three = append(advice_three, advice)
  3494. }
  3495. break
  3496. case 0:
  3497. if strings.Index(advice.WeekDay, "周日") == -1 {
  3498. advice_three = append(advice_three, advice)
  3499. }
  3500. break
  3501. }
  3502. }
  3503. }
  3504. for _, advice := range advices_two {
  3505. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3506. now := p.Unix()
  3507. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3508. dayStr2 := "-" + dayStr
  3509. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3510. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3511. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3512. for _, ad := range advices {
  3513. advice_three = append(advice_three, ad)
  3514. }
  3515. }
  3516. if err == nil {
  3517. c.ServeSuccessJSON(map[string]interface{}{
  3518. "status": "2",
  3519. "advices": advices,
  3520. "advices_two": RemoveRepeatedElement(advice_three),
  3521. "is_open_remind": config.IsOpenRemind,
  3522. })
  3523. }
  3524. }
  3525. }
  3526. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3527. newArr = make([]*models.DoctorAdvice, 0)
  3528. for i := 0; i < len(arr); i++ {
  3529. repeat := false
  3530. for j := i + 1; j < len(arr); j++ {
  3531. if arr[i].ID == arr[j].ID {
  3532. repeat = true
  3533. break
  3534. }
  3535. }
  3536. if !repeat {
  3537. newArr = append(newArr, arr[i])
  3538. }
  3539. }
  3540. return
  3541. }
  3542. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3543. patient, _ := c.GetInt64("id", 0)
  3544. groupNo, _ := c.GetInt64("groupno", 0)
  3545. if patient <= 0 {
  3546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3547. return
  3548. }
  3549. adminUserInfo := c.GetAdminUserInfo()
  3550. dataBody := make(map[string]interface{}, 0)
  3551. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3552. if err != nil {
  3553. utils.ErrorLog(err.Error())
  3554. return
  3555. }
  3556. utils.ErrorLog("%v", dataBody)
  3557. timeLayout := "2006-01-02 15:04"
  3558. loc, _ := time.LoadLocation("Local")
  3559. timeLayout2 := "2006-01-02"
  3560. loc2, _ := time.LoadLocation("Local")
  3561. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3562. utils.ErrorLog("advice_type")
  3563. return
  3564. }
  3565. adviceType := int64(2)
  3566. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3567. utils.ErrorLog("advice_date")
  3568. return
  3569. }
  3570. adviceDate, _ := dataBody["advice_date"].(string)
  3571. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3572. AdviceDate := theTime.Unix()
  3573. RecordDate := theTime.Unix()
  3574. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3575. utils.ErrorLog("start_time")
  3576. return
  3577. }
  3578. startTime, _ := dataBody["start_time"].(string)
  3579. if len(startTime) == 0 {
  3580. utils.ErrorLog("len(start_time) == 0")
  3581. return
  3582. }
  3583. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3584. if err != nil {
  3585. utils.ErrorLog(err.Error())
  3586. return
  3587. }
  3588. StartTime := theTimeUnix.Unix()
  3589. fmt.Println("startTIME", StartTime)
  3590. Remark := ""
  3591. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3592. remark, _ := dataBody["remark"].(string)
  3593. Remark = remark
  3594. }
  3595. var advices []*models.GroupAdvice
  3596. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3597. utils.ErrorLog("advices")
  3598. return
  3599. }
  3600. adviceNames := dataBody["advices"].([]interface{})
  3601. for _, adviceNameMap := range adviceNames {
  3602. adviceNameM := adviceNameMap.(map[string]interface{})
  3603. var advice models.GroupAdvice
  3604. advice.Remark = Remark
  3605. advice.AdviceType = adviceType
  3606. advice.StartTime = StartTime
  3607. advice.AdviceDate = AdviceDate
  3608. advice.RecordDate = RecordDate
  3609. advice.Status = 1
  3610. advice.CreatedTime = time.Now().Unix()
  3611. advice.UpdatedTime = time.Now().Unix()
  3612. advice.StopState = 2
  3613. advice.ExecutionState = 2
  3614. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3615. advice.PatientId = patient
  3616. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3617. advice.IsSettle = 2
  3618. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3619. utils.ErrorLog("advice_name")
  3620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3621. return
  3622. }
  3623. adviceName, _ := adviceNameM["advice_name"].(string)
  3624. if len(adviceName) == 0 {
  3625. utils.ErrorLog("len(advice_name) == 0")
  3626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3627. return
  3628. }
  3629. advice.AdviceName = adviceName
  3630. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3631. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3632. advice.DrugSpec = drugSpec
  3633. }
  3634. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3635. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3636. advice.AdviceDesc = adviceDesc
  3637. }
  3638. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3639. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3640. advice.DrugSpecUnit = drugSpecUnit
  3641. }
  3642. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3643. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3644. // advice.SingleDose = singleDose
  3645. //}
  3646. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3647. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3648. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3649. }
  3650. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3651. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3652. advice.SingleDoseUnit = singleDoseUnit
  3653. }
  3654. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3655. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3656. // advice.PrescribingNumber = prescribingNumber
  3657. //}
  3658. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3659. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3660. }
  3661. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3662. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3663. advice.PrescribingNumberUnit = prescribingNumberUnit
  3664. }
  3665. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3666. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3667. advice.DeliveryWay = deliveryWay
  3668. }
  3669. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3670. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3671. advice.ExecutionFrequency = executionFrequency
  3672. }
  3673. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3674. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3675. advice.FrequencyType = frequency_type
  3676. }
  3677. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3678. day_count := int64(adviceNameM["day_count"].(float64))
  3679. advice.DayCount = day_count
  3680. }
  3681. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3682. way := int64(adviceNameM["way"].(float64))
  3683. advice.Way = way
  3684. }
  3685. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3686. drug_id := int64(adviceNameM["drug_id"].(float64))
  3687. advice.DrugId = drug_id
  3688. }
  3689. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3690. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3691. advice.DrugNameId = drug_name_id
  3692. }
  3693. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3694. week_day, _ := adviceNameM["week_day"].(string)
  3695. advice.WeekDay = week_day
  3696. }
  3697. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3698. template_id, _ := adviceNameM["template_id"].(string)
  3699. advice.TemplateId = template_id
  3700. }
  3701. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3702. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3703. advice.ExecutionFrequency = executionFrequency
  3704. }
  3705. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3706. children := adviceNameM["child"].([]interface{})
  3707. if len(children) > 0 {
  3708. for _, childrenMap := range children {
  3709. childMap := childrenMap.(map[string]interface{})
  3710. var child models.GroupAdvice
  3711. child.Remark = Remark
  3712. child.AdviceType = adviceType
  3713. child.StartTime = StartTime
  3714. child.AdviceDate = AdviceDate
  3715. child.RecordDate = RecordDate
  3716. child.Status = 1
  3717. child.CreatedTime = time.Now().Unix()
  3718. child.UpdatedTime = time.Now().Unix()
  3719. child.StopState = 2
  3720. child.ExecutionState = 2
  3721. child.UserOrgId = adminUserInfo.CurrentOrgId
  3722. child.PatientId = patient
  3723. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3724. child.IsSettle = 2
  3725. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3726. utils.ErrorLog("child advice_name")
  3727. return
  3728. }
  3729. childAdviceName, _ := childMap["advice_name"].(string)
  3730. if len(childAdviceName) == 0 {
  3731. utils.ErrorLog("len(child advice_name) == 0")
  3732. return
  3733. }
  3734. child.AdviceName = childAdviceName
  3735. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3736. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3737. child.AdviceDesc = childAdviceDesc
  3738. }
  3739. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3740. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3741. child.DrugSpec = childDrugSpec
  3742. }
  3743. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3744. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3745. child.DrugSpecUnit = childDrugSpecUnit
  3746. }
  3747. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3748. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3749. child.SingleDose = childSingleDose
  3750. }
  3751. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3752. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3753. child.SingleDose = childMap["single_dose"].(float64)
  3754. }
  3755. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3756. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3757. child.Remark = childMap["remark"].(string)
  3758. }
  3759. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3760. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3761. child.DrugId = int64(childMap["drug_id"].(float64))
  3762. }
  3763. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3764. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3765. child.SingleDoseUnit = childSingleDoseUnit
  3766. }
  3767. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3768. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3769. child.PrescribingNumber = childPrescribingNumber
  3770. }
  3771. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3772. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3773. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3774. }
  3775. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3776. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3777. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3778. }
  3779. child.DeliveryWay = advice.DeliveryWay
  3780. child.ExecutionFrequency = advice.ExecutionFrequency
  3781. advice.Children = append(advice.Children, &child)
  3782. }
  3783. }
  3784. }
  3785. advices = append(advices, &advice)
  3786. }
  3787. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3788. redis := service.RedisClient()
  3789. formatAdviceDate := theTime.Format("2006-01-02")
  3790. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3791. redis.Set(key, "", time.Second)
  3792. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3793. redis.Set(keyOne, "", time.Second)
  3794. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3795. redis.Set(keyFour, "", time.Second)
  3796. defer redis.Close()
  3797. if err != nil {
  3798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3799. return
  3800. }
  3801. c.ServeSuccessJSON(map[string]interface{}{
  3802. "msg": "ok",
  3803. "advices": list,
  3804. })
  3805. return
  3806. }
  3807. func (c *DialysisApiController) GetSolution() {
  3808. patient_id, _ := c.GetInt64("patient_id")
  3809. mode_id, _ := c.GetInt64("mode_id")
  3810. adminUserInfo := c.GetAdminUserInfo()
  3811. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3812. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3813. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3814. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  3815. if err != nil {
  3816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3817. return
  3818. }
  3819. c.ServeSuccessJSON(map[string]interface{}{
  3820. "solution": solution,
  3821. "prescription": prescription,
  3822. "system_prescription": system_prescription,
  3823. "dialysisPrescription": dialysisPrescription,
  3824. })
  3825. }
  3826. func (c *DialysisApiController) GetSchedule() {
  3827. schedual_type, _ := c.GetInt64("schedual_type")
  3828. adminUserInfo := c.GetAdminUserInfo()
  3829. //timeLayout := "2006-01-02 15:04:05"
  3830. //
  3831. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3832. //loc, _ := time.LoadLocation("Local")
  3833. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3834. //scheduleTime := theStartTime.Unix()
  3835. scheduleTime, _ := c.GetInt64("record_date")
  3836. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3837. c.ServeSuccessJSON(map[string]interface{}{
  3838. "number": deviceNumber,
  3839. })
  3840. }
  3841. func (this *DialysisApiController) GetTodayMonitor() {
  3842. thisTime := time.Now()
  3843. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3844. timeLayout := "2006-01-02 15:04:05"
  3845. loc, _ := time.LoadLocation("Local")
  3846. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3847. theAssessmentDateTime := theStartTime.Unix()
  3848. patientID, _ := this.GetInt64("patient_id")
  3849. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3850. adminInfo := this.GetAdminUserInfo()
  3851. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3852. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3853. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3854. var ultrafiltration_rate float64
  3855. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3856. //针对福建医师汇 获取透前评估预增脱水量
  3857. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3858. fmt.Println("透前评估数据", evaluation)
  3859. if prescription.ID > 0 {
  3860. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3861. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3862. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3863. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3864. record.UltrafiltrationRate = ultrafiltration_rate
  3865. }
  3866. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3867. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3868. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3869. record.UltrafiltrationRate = ultrafiltration_rate
  3870. }
  3871. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3872. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3873. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3874. record.UltrafiltrationRate = ultrafiltration_rate
  3875. }
  3876. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3877. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3878. record.UltrafiltrationRate = ultrafiltration_rate
  3879. }
  3880. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3881. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3882. record.UltrafiltrationRate = ultrafiltration_rate
  3883. }
  3884. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3885. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3886. record.UltrafiltrationRate = ultrafiltration_rate
  3887. }
  3888. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3890. record.UltrafiltrationRate = ultrafiltration_rate
  3891. }
  3892. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3893. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3894. record.UltrafiltrationRate = ultrafiltration_rate
  3895. }
  3896. // 只针对方济医院
  3897. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3898. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3899. ultrafiltration_rate = value
  3900. record.UltrafiltrationRate = ultrafiltration_rate
  3901. }
  3902. //长沙南雅
  3903. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 {
  3904. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3905. record.UltrafiltrationRate = ultrafiltration_rate
  3906. }
  3907. }
  3908. }
  3909. // record.UltrafiltrationRate = ultrafiltration_rate
  3910. record.UltrafiltrationVolume = 0
  3911. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3912. if ultrafiltration_rate > 0 {
  3913. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3914. record.UltrafiltrationVolume = value
  3915. }
  3916. }
  3917. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  3918. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3919. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3920. record.UltrafiltrationVolume = ultrafiltration_volume
  3921. }
  3922. }
  3923. //长沙南雅
  3924. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 {
  3925. if ultrafiltration_rate > 0 {
  3926. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3927. record.UltrafiltrationVolume = ultrafiltration_volume
  3928. }
  3929. }
  3930. if template.TemplateId == 47 || template.TemplateId == 54 {
  3931. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3932. }
  3933. this.ServeSuccessJSON(map[string]interface{}{
  3934. "monitor": record,
  3935. })
  3936. }
  3937. func (c *DialysisApiController) UploadDryWeight() {
  3938. patient_id, _ := c.GetInt64("id")
  3939. dry_weight, _ := c.GetFloat("dry_weight")
  3940. doctor_id, _ := c.GetInt64("doctor_id")
  3941. remark := c.GetString("remark")
  3942. adminUserInfo := c.GetAdminUserInfo()
  3943. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3944. fmt.Println(err)
  3945. if err == gorm.ErrRecordNotFound {
  3946. dryWeight := &models.SgjPatientDryweight{
  3947. PatientId: patient_id,
  3948. DryWeight: dry_weight,
  3949. Remakes: remark,
  3950. Ctime: time.Now().Unix(),
  3951. Mtime: time.Now().Unix(),
  3952. Creator: doctor_id,
  3953. Status: 1,
  3954. UserOrgId: adminUserInfo.CurrentOrgId,
  3955. AdjustedValue: "/",
  3956. UserId: adminUserInfo.AdminUser.Id,
  3957. }
  3958. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3959. loc, _ := time.LoadLocation("Local")
  3960. nowTime := time.Now()
  3961. nowDay := nowTime.Format("2006-01-02")
  3962. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3963. redis := service.RedisClient()
  3964. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3965. redis.Set(keyOne, "", time.Second)
  3966. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3967. redis.Set(key, "", time.Second)
  3968. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3969. redis.Set(keyTwo, "", time.Second)
  3970. redis.Close()
  3971. if createErr == nil {
  3972. c.ServeSuccessJSON(map[string]interface{}{
  3973. "msg": "提交成功",
  3974. "weight": dryWeight,
  3975. })
  3976. }
  3977. } else {
  3978. dryWeight := &models.SgjPatientDryweight{
  3979. PatientId: patient_id,
  3980. DryWeight: dry_weight,
  3981. Remakes: remark,
  3982. Ctime: time.Now().Unix(),
  3983. Mtime: time.Now().Unix(),
  3984. Creator: doctor_id,
  3985. Status: 1,
  3986. UserOrgId: adminUserInfo.CurrentOrgId,
  3987. AdjustedValue: "/",
  3988. UserId: adminUserInfo.AdminUser.Id,
  3989. }
  3990. var value float64
  3991. value = dry_weight - weightAdjust.DryWeight
  3992. fmt.Println(value)
  3993. if value < 0 {
  3994. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3995. } else if value == 0 {
  3996. dryWeight.AdjustedValue = "/"
  3997. } else if value > 0 {
  3998. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3999. }
  4000. fmt.Println(value)
  4001. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4002. loc, _ := time.LoadLocation("Local")
  4003. nowTime := time.Now()
  4004. nowDay := nowTime.Format("2006-01-02")
  4005. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4006. redis := service.RedisClient()
  4007. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4008. redis.Set(keyOne, "", time.Second)
  4009. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4010. redis.Set(key, "", time.Second)
  4011. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4012. redis.Set(keyTwo, "", time.Second)
  4013. redis.Close()
  4014. if createErr == nil {
  4015. c.ServeSuccessJSON(map[string]interface{}{
  4016. "msg": "提交成功",
  4017. "weight": dryWeight,
  4018. })
  4019. }
  4020. }
  4021. }
  4022. func (this *DialysisApiController) GetFuncPurview() {
  4023. adminUserInfo := this.GetAdminUserInfo()
  4024. user_id := adminUserInfo.AdminUser.Id
  4025. app_id := adminUserInfo.CurrentAppId
  4026. org_id := adminUserInfo.CurrentOrgId
  4027. create_url := this.GetString("create_url")
  4028. modify_url := this.GetString("modify_url")
  4029. modify_other_url := this.GetString("modify_other_url")
  4030. del_url := this.GetString("del_url")
  4031. del_other_url := this.GetString("del_other_url")
  4032. exce_url := this.GetString("exce_url")
  4033. check_url := this.GetString("check_url")
  4034. modify_exce_url := this.GetString("modify_exce_url")
  4035. module, _ := this.GetInt64("module", 0)
  4036. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4037. var is_has_create bool
  4038. var is_has_modify bool
  4039. var is_has_modify_other bool
  4040. var is_has_del bool
  4041. var is_has_del_other bool
  4042. var is_has_exce bool
  4043. var is_has_check bool
  4044. var is_has_modify_exce bool
  4045. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4046. if adminUserInfo.AdminUser.Id != org.Creator {
  4047. if app_role != nil {
  4048. if len(app_role.RoleIds) > 0 {
  4049. roles := strings.Split(app_role.RoleIds, ",")
  4050. var userRolePurviews string
  4051. for _, item := range roles {
  4052. role_id, _ := strconv.ParseInt(item, 10, 64)
  4053. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4054. if len(userRolePurviews) == 0 {
  4055. userRolePurviews = purviews
  4056. } else {
  4057. userRolePurviews = userRolePurviews + "," + purviews
  4058. }
  4059. }
  4060. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4061. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4062. for _, item := range funcPurviews {
  4063. //for _, url := range strings.Split(item.Urlfor,","){
  4064. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4065. is_has_create = true
  4066. }
  4067. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4068. is_has_modify = true
  4069. }
  4070. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4071. is_has_modify_other = true
  4072. }
  4073. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4074. is_has_del = true
  4075. }
  4076. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4077. is_has_del_other = true
  4078. }
  4079. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4080. is_has_exce = true
  4081. }
  4082. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4083. is_has_check = true
  4084. }
  4085. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4086. is_has_modify_exce = true
  4087. }
  4088. }
  4089. } else {
  4090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4091. return
  4092. }
  4093. this.ServeSuccessJSON(map[string]interface{}{
  4094. "is_has_create": is_has_create,
  4095. "is_has_modify": is_has_modify,
  4096. "is_has_modify_other": is_has_modify_other,
  4097. "is_has_del": is_has_del,
  4098. "is_has_del_other": is_has_del_other,
  4099. "is_has_exce": is_has_exce,
  4100. "is_has_check": is_has_check,
  4101. "is_has_modify_exce": is_has_modify_exce,
  4102. "module": module,
  4103. })
  4104. } else {
  4105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4106. return
  4107. }
  4108. } else {
  4109. this.ServeSuccessJSON(map[string]interface{}{
  4110. "is_has_create": true,
  4111. "is_has_modify": true,
  4112. "is_has_modify_other": true,
  4113. "is_has_del": true,
  4114. "is_has_del_other": true,
  4115. "is_has_exce": true,
  4116. "is_has_check": true,
  4117. "is_has_modify_exce": true,
  4118. "module": true,
  4119. })
  4120. }
  4121. }
  4122. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4123. patient_id, _ := this.GetInt64("patient_id", 0)
  4124. advice_date, _ := this.GetInt64("advice_date")
  4125. adminUserInfo := this.GetAdminUserInfo()
  4126. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4127. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4128. this.ServeSuccessJSON(map[string]interface{}{
  4129. "doctorAdvice": doctorAdvice,
  4130. "hisDoctorAdvice": hisDoctorAdvice,
  4131. })
  4132. }
  4133. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4134. change_type, _ := this.GetInt64("type", 0)
  4135. record_date := this.GetString("record_time")
  4136. patient_id, _ := this.GetInt64("patient_id", 0)
  4137. timeLayout := "2006-01-02"
  4138. loc, _ := time.LoadLocation("Local")
  4139. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4140. record_time := theAdviceRecordTime.Unix()
  4141. adminUserInfo := this.GetAdminUserInfo()
  4142. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4143. if err == nil {
  4144. if len(advices) == 0 {
  4145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4146. return
  4147. } else {
  4148. this.ServeSuccessJSON(map[string]interface{}{
  4149. "advices": advices,
  4150. "schedule": sch,
  4151. })
  4152. return
  4153. }
  4154. } else {
  4155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4156. return
  4157. }
  4158. }
  4159. func (c *DialysisApiController) GetDialysisGoods() {
  4160. schedualDate := c.GetString("schedule_date")
  4161. schedule_type, _ := c.GetInt64("schedule_type")
  4162. partition_id, _ := c.GetInt64("partition_id")
  4163. page, _ := c.GetInt("page")
  4164. limit, _ := c.GetInt("limit")
  4165. keywords := c.GetString("keywords")
  4166. patient_id, _ := c.GetInt64("patient_id")
  4167. good_type, _ := c.GetInt64("good_type")
  4168. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4169. if parseDateErr != nil && len(schedualDate) != 0 {
  4170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4171. return
  4172. }
  4173. schedualEndDate := int64(0)
  4174. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4175. if parseDateErr != nil && len(schedualDate) != 0 {
  4176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4177. return
  4178. }
  4179. schedualEndDate = endDate.Unix()
  4180. adminUser := c.GetAdminUserInfo()
  4181. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4182. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4183. if err == gorm.ErrRecordNotFound {
  4184. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4185. var ids []int64
  4186. for _, item := range list {
  4187. ids = append(ids, item.PatientId)
  4188. }
  4189. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4190. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4191. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4192. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4193. item.LastAutomaticReduceDetail = goodUser
  4194. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4195. }
  4196. c.ServeSuccessJSON(map[string]interface{}{
  4197. "dialysis_goods": dialysisGoods,
  4198. "good_type": goodTypes,
  4199. "total": total,
  4200. })
  4201. return
  4202. } else if err == nil {
  4203. //获取当天排班的每个患者的库存使用情况
  4204. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4205. var ids []int64
  4206. for _, item := range list {
  4207. ids = append(ids, item.PatientId)
  4208. }
  4209. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4210. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4211. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4212. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4213. fmt.Println(goodUser)
  4214. fmt.Println(lastGoodUserDetial)
  4215. item.LastAutomaticReduceDetail = goodUser
  4216. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4217. }
  4218. if err == nil {
  4219. c.ServeSuccessJSON(map[string]interface{}{
  4220. "dialysis_goods": dialysisGoods,
  4221. "good_type": goodTypes,
  4222. "total": total,
  4223. })
  4224. return
  4225. } else {
  4226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4227. return
  4228. }
  4229. } else if err != nil {
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4231. return
  4232. }
  4233. }
  4234. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4235. start_time := c.GetString("start_time")
  4236. end_time := c.GetString("end_time")
  4237. timeLayout := "2006-01-02"
  4238. loc, _ := time.LoadLocation("Local")
  4239. var theStartTime int64
  4240. if len(start_time) > 0 {
  4241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4242. if err != nil {
  4243. utils.ErrorLog(err.Error())
  4244. }
  4245. theStartTime = theTime.Unix()
  4246. }
  4247. var theEndtTime int64
  4248. if len(end_time) > 0 {
  4249. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4250. if err != nil {
  4251. utils.ErrorLog(err.Error())
  4252. }
  4253. theEndtTime = theTime.Unix()
  4254. }
  4255. adminUser := c.GetAdminUserInfo()
  4256. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4257. if err == nil {
  4258. c.ServeSuccessJSON(map[string]interface{}{
  4259. "stock_out": outInfo,
  4260. })
  4261. return
  4262. } else {
  4263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4264. return
  4265. }
  4266. }
  4267. func (c *DialysisApiController) GetRoleList() {
  4268. orgId := c.GetAdminUserInfo().CurrentOrgId
  4269. admin_user_id, _ := c.GetInt64("admin_user_id")
  4270. list, err := service.GetRoleList(orgId, admin_user_id)
  4271. if err == nil {
  4272. c.ServeSuccessJSON(map[string]interface{}{
  4273. "adminRole": list,
  4274. })
  4275. return
  4276. } else {
  4277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4278. return
  4279. }
  4280. }
  4281. func (c *DialysisApiController) GetInitPrintData() {
  4282. patient_id, _ := c.GetInt64("patient_id")
  4283. record_date, _ := c.GetInt64("record_date")
  4284. orgId := c.GetAdminUserInfo().CurrentOrgId
  4285. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4286. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4287. if err == nil {
  4288. c.ServeSuccessJSON(map[string]interface{}{
  4289. "list": list,
  4290. "assessmentAfterDislysis": assessmentAfterDislysis,
  4291. })
  4292. return
  4293. } else {
  4294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4295. return
  4296. }
  4297. }
  4298. func (c *DialysisApiController) GetInitPrintDataOne() {
  4299. patient_id, _ := c.GetInt64("patient_id")
  4300. start_time := c.GetString("record_date")
  4301. timeLayout := "2006-01-02"
  4302. loc, _ := time.LoadLocation("Local")
  4303. var theStartTime int64
  4304. if len(start_time) > 0 {
  4305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4306. if err != nil {
  4307. utils.ErrorLog(err.Error())
  4308. }
  4309. theStartTime = theTime.Unix()
  4310. }
  4311. orgId := c.GetAdminUserInfo().CurrentOrgId
  4312. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4313. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4314. if err == nil {
  4315. c.ServeSuccessJSON(map[string]interface{}{
  4316. "list": list,
  4317. "assessmentAfterDislysis": assessmentAfterDislysis,
  4318. })
  4319. return
  4320. } else {
  4321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4322. return
  4323. }
  4324. }
  4325. // 新接口
  4326. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4327. keyword := this.GetString("keywords")
  4328. limit, _ := this.GetInt64("limit")
  4329. page, _ := this.GetInt64("page")
  4330. partition_id, _ := this.GetInt64("partition_id")
  4331. schedule_type, _ := this.GetInt64("schedule_type")
  4332. start_time := this.GetString("schedule_date")
  4333. advice_ids := this.GetString("ids")
  4334. var ids []string
  4335. if advice_ids != "" {
  4336. ids = strings.Split(advice_ids, ",")
  4337. }
  4338. timeLayout := "2006-01-02"
  4339. loc, _ := time.LoadLocation("Local")
  4340. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4341. orgId := this.GetAdminUserInfo().CurrentOrgId
  4342. _, config := service.FindXTHisRecordByOrgId(orgId)
  4343. goodType, _ := service.GetAllGoodType(orgId)
  4344. if config.IsOpen != 1 {
  4345. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4346. fmt.Println("list2232323223332323232", list)
  4347. if err == nil {
  4348. this.ServeSuccessJSON(map[string]interface{}{
  4349. "list": list,
  4350. "total": total,
  4351. "config": config,
  4352. "goodType": goodType,
  4353. })
  4354. return
  4355. } else {
  4356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4357. return
  4358. }
  4359. }
  4360. if config.IsOpen == 1 {
  4361. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4362. if err == nil {
  4363. this.ServeSuccessJSON(map[string]interface{}{
  4364. "list": list,
  4365. "total": total,
  4366. "config": config,
  4367. "goodType": goodType,
  4368. })
  4369. return
  4370. }
  4371. }
  4372. }
  4373. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4374. keyword := this.GetString("keywords")
  4375. limit, _ := this.GetInt64("limit")
  4376. page, _ := this.GetInt64("page")
  4377. partition_id, _ := this.GetInt64("partition_id")
  4378. schedule_type, _ := this.GetInt64("schedule_type")
  4379. start_time := this.GetString("schedule_date")
  4380. ids := this.GetString("ids")
  4381. var idArray []string
  4382. if ids != "" {
  4383. idArray = strings.Split(ids, ",")
  4384. }
  4385. timeLayout := "2006-01-02"
  4386. loc, _ := time.LoadLocation("Local")
  4387. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4388. orgId := this.GetAdminUserInfo().CurrentOrgId
  4389. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4390. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4391. //获取长期医嘱
  4392. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4393. _, config := service.FindXTHisRecordByOrgId(orgId)
  4394. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4395. if err == nil {
  4396. this.ServeSuccessJSON(map[string]interface{}{
  4397. "list": list,
  4398. "total": total,
  4399. "adviceList": adviceList,
  4400. "config": config,
  4401. "drugList": drugList,
  4402. "tablelist": tablelist,
  4403. })
  4404. return
  4405. } else {
  4406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4407. return
  4408. }
  4409. }
  4410. func (this *DialysisApiController) SaveDialysisSetting() {
  4411. orgId := this.GetAdminUserInfo().CurrentOrgId
  4412. device_number_set, _ := this.GetInt64("device_number_set")
  4413. device_type_set, _ := this.GetInt64("device_type_set")
  4414. name_set, _ := this.GetInt64("name_set")
  4415. admission_number_set, _ := this.GetInt64("admission_number_set")
  4416. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4417. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4418. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4419. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4420. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4421. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4422. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4423. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4424. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4425. mode_id_set, _ := this.GetInt64("mode_id_set")
  4426. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4427. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4428. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4429. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4430. kalium_set, _ := this.GetInt64("kalium_set")
  4431. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4432. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4433. glucose_set, _ := this.GetInt64("glucose_set")
  4434. sodium_set, _ := this.GetInt64("sodium_set")
  4435. calcium_set, _ := this.GetInt64("calcium_set")
  4436. blood_access_set, _ := this.GetInt64("blood_access_set")
  4437. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4438. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4439. dialysisSetting := models.XtDialysisSetting{
  4440. Sodium: sodium_set,
  4441. Calcium: calcium_set,
  4442. BloodAccess: blood_access_set,
  4443. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4444. DisplaceLiquiPart: displace_liqui_part_set,
  4445. UserOrgId: orgId,
  4446. Status: 1,
  4447. DeviceNumber: device_number_set,
  4448. DeviceType: device_type_set,
  4449. Name: name_set,
  4450. AdmissionNumber: admission_number_set,
  4451. DialysisNo: dialysis_no_set,
  4452. WeightBefor: weight_befor_set,
  4453. DryWeight: dry_weight_set,
  4454. BloodPressure: blood_pressure_set,
  4455. UltrafiltrationVolume: ultrafiltration_volume_set,
  4456. InternalFistula: internal_fistula_set,
  4457. BloodFlowVolume: blood_flow_volume_set,
  4458. Anticoagulant: anticoagulant_set,
  4459. SealingFluidDispose: sealing_fluid_dispose_set,
  4460. ModeId: mode_id_set,
  4461. DialysisTime: dialysis_time_set,
  4462. DialysisDialyszers: dialysis_dialyszers_set,
  4463. DialysisIrrigation: dialysis_irrigation_set,
  4464. Gaijiliang: gaijiliang_set,
  4465. Kalium: kalium_set,
  4466. DisplaceLiquiValue: displace_liqui_value_set,
  4467. Bicarbonate: bicarbonate_set,
  4468. Glucose: glucose_set,
  4469. Ctime: time.Now().Unix(),
  4470. Mtime: time.Now().Unix(),
  4471. }
  4472. err := service.SaveDialysisSetting(dialysisSetting)
  4473. if err == nil {
  4474. this.ServeSuccessJSON(map[string]interface{}{
  4475. "dialysisSetting": dialysisSetting,
  4476. })
  4477. return
  4478. } else {
  4479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4480. return
  4481. }
  4482. }
  4483. func (this *DialysisApiController) GetDialysisSetting() {
  4484. orgId := this.GetAdminUserInfo().CurrentOrgId
  4485. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4486. this.ServeSuccessJSON(map[string]interface{}{
  4487. "dialysisSett": dialysisSett,
  4488. })
  4489. return
  4490. }
  4491. func (this *DialysisApiController) GetDialysisParameterList() {
  4492. keyword := this.GetString("keywords")
  4493. limit, _ := this.GetInt64("limit")
  4494. page, _ := this.GetInt64("page")
  4495. partition_id, _ := this.GetInt64("partition_id")
  4496. schedule_type, _ := this.GetInt64("schedule_type")
  4497. start_time := this.GetString("schedule_date")
  4498. timeLayout := "2006-01-02"
  4499. loc, _ := time.LoadLocation("Local")
  4500. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4501. orgId := this.GetAdminUserInfo().CurrentOrgId
  4502. scheduids := this.GetString("ids")
  4503. var ids []string
  4504. if scheduids != "" {
  4505. ids = strings.Split(scheduids, ",")
  4506. }
  4507. list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4508. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4509. if err == nil {
  4510. this.ServeSuccessJSON(map[string]interface{}{
  4511. "list": list,
  4512. "total": total,
  4513. "dialysisSett": dialysisSett,
  4514. })
  4515. return
  4516. } else {
  4517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4518. return
  4519. }
  4520. }
  4521. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4522. orgId := this.GetAdminUserInfo().CurrentOrgId
  4523. schedule_type, _ := this.GetInt64("schedule_type")
  4524. //partion_type, _ := this.GetInt64("partion_type")
  4525. start_time := this.GetString("selected_date")
  4526. partion_type := this.GetString("partion_type")
  4527. var ids []string
  4528. ids = strings.Split(partion_type, ",")
  4529. fmt.Println("ids------------------------", ids)
  4530. timeLayout := "2006-01-02"
  4531. loc, _ := time.LoadLocation("Local")
  4532. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4533. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4534. if err == nil {
  4535. this.ServeSuccessJSON(map[string]interface{}{
  4536. "list": list,
  4537. })
  4538. return
  4539. } else {
  4540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4541. return
  4542. }
  4543. }
  4544. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4545. orgId := this.GetAdminUserInfo().CurrentOrgId
  4546. schedule_type, _ := this.GetInt64("schedule_type")
  4547. //partion_type, _ := this.GetInt64("partion_type")
  4548. partion_type := this.GetString("partion_type")
  4549. var ids []string
  4550. ids = strings.Split(partion_type, ",")
  4551. start_time := this.GetString("selected_date")
  4552. timeLayout := "2006-01-02"
  4553. loc, _ := time.LoadLocation("Local")
  4554. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4555. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4556. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4557. //获取长期医嘱
  4558. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4559. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4560. _, config := service.FindXTHisRecordByOrgId(orgId)
  4561. if err == nil {
  4562. this.ServeSuccessJSON(map[string]interface{}{
  4563. "list": list,
  4564. "drug": drug,
  4565. "adviceList": adviceList,
  4566. "config": config,
  4567. "tablelist": tablelist,
  4568. })
  4569. return
  4570. } else {
  4571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4572. return
  4573. }
  4574. }
  4575. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4576. orgId := this.GetAdminUserInfo().CurrentOrgId
  4577. schedule_type, _ := this.GetInt64("schedule_type")
  4578. partion_type, _ := this.GetInt64("partion_type")
  4579. start_time := this.GetString("selected_date")
  4580. timeLayout := "2006-01-02"
  4581. loc, _ := time.LoadLocation("Local")
  4582. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4583. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4584. if err == nil {
  4585. this.ServeSuccessJSON(map[string]interface{}{
  4586. "list": list,
  4587. })
  4588. return
  4589. } else {
  4590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4591. return
  4592. }
  4593. }
  4594. func (this *DialysisApiController) SaveHisDialysis() {
  4595. var ids []string
  4596. advice_ids := this.GetString("ids")
  4597. ids = strings.Split(advice_ids, ",")
  4598. orgId := this.GetAdminUserInfo().CurrentOrgId
  4599. service.SaveHisDialysis(orgId, ids)
  4600. returnData := make(map[string]interface{}, 0)
  4601. returnData["msg"] = "ok"
  4602. this.ServeSuccessJSON(returnData)
  4603. return
  4604. }
  4605. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4606. orgId := this.GetAdminUserInfo().CurrentOrgId
  4607. schedule_type, _ := this.GetInt64("schedule_type")
  4608. //partion_type, _ := this.GetInt64("partion_type")
  4609. partion_type := this.GetString("partion_type")
  4610. var ids []string
  4611. ids = strings.Split(partion_type, ",")
  4612. start_time := this.GetString("selected_date")
  4613. timeLayout := "2006-01-02"
  4614. loc, _ := time.LoadLocation("Local")
  4615. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4616. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4617. this.ServeSuccessJSON(map[string]interface{}{
  4618. "list": list,
  4619. })
  4620. return
  4621. }
  4622. func (this *DialysisApiController) GetPatientSchedule() {
  4623. orgId := this.GetAdminUserInfo().CurrentOrgId
  4624. patient_id, _ := this.GetInt64("patient_id")
  4625. schedule_date, _ := this.GetInt64("schedule_date")
  4626. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4627. this.ServeSuccessJSON(map[string]interface{}{
  4628. "schedulePatient": schedulePatient,
  4629. })
  4630. }
  4631. func (c *DialysisApiController) GetSchedulePrintList() {
  4632. page, _ := c.GetInt64("page", 1)
  4633. limit, _ := c.GetInt64("limit", 10)
  4634. schedulType, _ := c.GetInt64("schedule_type", 0)
  4635. partitionType, _ := c.GetInt64("partition_type", 0)
  4636. keywords := c.GetString("keywords")
  4637. schedule_date := c.GetString("schedule_date")
  4638. timeLayout := "2006-01-02"
  4639. loc, _ := time.LoadLocation("Local")
  4640. var theStartTime int64
  4641. if len(schedule_date) > 0 {
  4642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4643. if err != nil {
  4644. utils.ErrorLog(err.Error())
  4645. }
  4646. theStartTime = theTime.Unix()
  4647. }
  4648. adminUserInfo := c.GetAdminUserInfo()
  4649. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4650. for _, item := range list {
  4651. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4652. item.DialysisOrderTwenty = order
  4653. }
  4654. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4655. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4656. c.ServeSuccessJSON(map[string]interface{}{
  4657. "list": list,
  4658. "total": total,
  4659. "numberList": numberList,
  4660. "listOne": listOne,
  4661. })
  4662. }
  4663. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4664. orgId := this.GetAdminUserInfo().CurrentOrgId
  4665. list, _ := service.GetSolutionListByOrgId(orgId)
  4666. for _, item := range list {
  4667. //获取该模式最新的1条数据
  4668. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4669. //更新状态值
  4670. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4671. }
  4672. this.ServeSuccessJSON(map[string]interface{}{
  4673. "list": list,
  4674. })
  4675. }
  4676. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4677. orgId := this.GetAdminUserInfo().CurrentOrgId
  4678. is_open, _ := this.GetInt64("is_open")
  4679. idsStr := this.GetString("str")
  4680. recordIDStrs := strings.Split(idsStr, ",")
  4681. start_time := this.GetString("advice_date")
  4682. exec_time, _ := this.GetInt64("exec_time")
  4683. timeLayout := "2006-01-02"
  4684. loc, _ := time.LoadLocation("Local")
  4685. var startTime int64
  4686. if len(start_time) > 0 {
  4687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4688. if err != nil {
  4689. //fmt.Println(err)
  4690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. return
  4692. }
  4693. startTime = theTime.Unix()
  4694. }
  4695. config, _ := service.GetDrugOpenConfigOne(orgId)
  4696. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4697. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4698. //his医嘱
  4699. if is_open == 1 {
  4700. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4701. //查找未执行医嘱
  4702. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4703. for _, item := range list {
  4704. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4705. this.ServeSuccessJSON(map[string]interface{}{
  4706. "msg": "3",
  4707. })
  4708. return
  4709. }
  4710. }
  4711. for _, item := range groupList {
  4712. for _, it := range list {
  4713. if item.DrugId == it.DrugId {
  4714. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4715. }
  4716. }
  4717. }
  4718. for _, item := range groupList {
  4719. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4720. var sum_out_count int64
  4721. for _, it := range item.ChildDoctorAdvice {
  4722. var prescribing_number int64
  4723. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4724. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4725. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4726. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4727. }
  4728. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4729. prescribing_number = parseIntPrescribingNumber
  4730. }
  4731. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4732. prescribing_number = parseIntPrescribingNumber
  4733. }
  4734. sum_out_count += prescribing_number
  4735. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4736. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4737. //库存不足
  4738. if sum_out_count > drugStockOut.FlushCount {
  4739. this.ServeSuccessJSON(map[string]interface{}{
  4740. "msg": "2",
  4741. "drug": medical,
  4742. })
  4743. return
  4744. }
  4745. }
  4746. }
  4747. creater := this.GetAdminUserInfo().AdminUser.Id
  4748. //执行出库逻辑
  4749. for _, item := range list {
  4750. hisadvice := &models.HisDoctorAdviceInfo{
  4751. ID: item.ID,
  4752. UserOrgId: item.UserOrgId,
  4753. PatientId: item.PatientId,
  4754. AdviceType: item.AdviceType,
  4755. AdviceDate: item.AdviceDate,
  4756. StartTime: item.StartTime,
  4757. AdviceName: item.AdviceName,
  4758. AdviceDesc: item.AdviceDesc,
  4759. ReminderDate: item.ReminderDate,
  4760. SingleDose: item.SingleDose,
  4761. SingleDoseUnit: item.SingleDoseUnit,
  4762. DrugSpec: item.DrugSpec,
  4763. DrugSpecUnit: item.DrugSpecUnit,
  4764. PrescribingNumber: item.PrescribingNumber,
  4765. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4766. DeliveryWay: item.DeliveryWay,
  4767. ExecutionFrequency: item.ExecutionFrequency,
  4768. AdviceDoctor: item.AdviceDoctor,
  4769. Status: 1,
  4770. CreatedTime: item.CreatedTime,
  4771. UpdatedTime: item.UpdatedTime,
  4772. AdviceAffirm: item.AdviceAffirm,
  4773. Remark: item.Remark,
  4774. StopTime: item.StopTime,
  4775. StopReason: item.StopReason,
  4776. StopDoctor: item.StopDoctor,
  4777. StopState: item.StopState,
  4778. ParentId: item.ParentId,
  4779. ExecutionTime: item.ExecutionTime,
  4780. ExecutionStaff: creater,
  4781. ExecutionState: item.ExecutionState,
  4782. Checker: item.Checker,
  4783. RecordDate: item.RecordDate,
  4784. DialysisOrderId: item.DialysisOrderId,
  4785. CheckTime: item.CheckTime,
  4786. CheckState: item.CheckState,
  4787. RemindType: item.RemindType,
  4788. FrequencyType: item.FrequencyType,
  4789. DayCount: item.DayCount,
  4790. WeekDay: item.WeekDay,
  4791. TemplateId: item.TemplateId,
  4792. Modifier: item.Modifier,
  4793. Way: item.Way,
  4794. DrugId: item.DrugId,
  4795. ExecutionFrequencyId: item.ExecutionFrequencyId,
  4796. }
  4797. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4798. if medical.IsUse == 2 {
  4799. if config.IsOpen != 1 {
  4800. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4801. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4802. }
  4803. //不通过药房发药
  4804. if pharmacyConfig.IsOpen != 1 {
  4805. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4806. }
  4807. //查询默认仓库
  4808. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4809. //查询默认仓库剩余多少库存
  4810. var sum_count int64
  4811. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4812. for _, its := range stockInfo {
  4813. if its.MaxUnit == medical.MaxUnit {
  4814. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4815. }
  4816. sum_count += its.StockMaxNumber + its.StockMinNumber
  4817. }
  4818. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4819. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4820. }
  4821. }
  4822. info := models.HisDoctorAdviceInfo{
  4823. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4824. ExecutionTime: exec_time,
  4825. ExecutionState: 1,
  4826. UpdatedTime: time.Now().Unix(),
  4827. }
  4828. //执行医嘱
  4829. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  4830. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  4831. redis := service.RedisClient()
  4832. //清空key 值
  4833. redis.Set(key, "", time.Second)
  4834. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  4835. redis.Set(keyTwo, "", time.Second)
  4836. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4837. redis.Set(keyThree, "", time.Second)
  4838. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4839. theTime := toTime.Format("2006-01-02")
  4840. fmt.Println("theTIME", theTime)
  4841. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  4842. redis.Set(keyFour, "", time.Second)
  4843. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4844. redis.Set(keyFive, "", time.Second)
  4845. }
  4846. } else {
  4847. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  4848. //查找未执行医嘱
  4849. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4850. for _, item := range groupList {
  4851. for _, it := range list {
  4852. if item.DrugId == it.DrugId {
  4853. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4854. }
  4855. }
  4856. }
  4857. for _, item := range groupList {
  4858. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4859. var sum_out_count int64
  4860. for _, it := range item.ChildDoctorAdvice {
  4861. var prescribing_number int64
  4862. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4863. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4864. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4865. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4866. }
  4867. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4868. prescribing_number = parseIntPrescribingNumber
  4869. }
  4870. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4871. prescribing_number = parseIntPrescribingNumber
  4872. }
  4873. sum_out_count += prescribing_number
  4874. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4875. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4876. //库存不足
  4877. if sum_out_count > drugStockOut.FlushCount {
  4878. this.ServeSuccessJSON(map[string]interface{}{
  4879. "msg": "2",
  4880. "drug": medical,
  4881. })
  4882. return
  4883. }
  4884. }
  4885. }
  4886. for _, item := range list {
  4887. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4888. dadvice := &models.DoctorAdvice{
  4889. ID: item.ID,
  4890. UserOrgId: item.UserOrgId,
  4891. PatientId: item.PatientId,
  4892. AdviceType: item.AdviceType,
  4893. AdviceDate: item.AdviceDate,
  4894. StartTime: item.StartTime,
  4895. AdviceName: item.AdviceName,
  4896. AdviceDesc: item.AdviceDesc,
  4897. ReminderDate: item.ReminderDate,
  4898. SingleDose: item.SingleDose,
  4899. SingleDoseUnit: item.SingleDoseUnit,
  4900. DrugSpec: item.DrugSpec,
  4901. DrugSpecUnit: item.DrugSpecUnit,
  4902. PrescribingNumber: item.PrescribingNumber,
  4903. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4904. DeliveryWay: item.DeliveryWay,
  4905. ExecutionFrequency: item.ExecutionFrequency,
  4906. AdviceDoctor: item.AdviceDoctor,
  4907. Status: 1,
  4908. CreatedTime: item.CreatedTime,
  4909. UpdatedTime: item.UpdatedTime,
  4910. AdviceAffirm: item.AdviceAffirm,
  4911. Remark: item.Remark,
  4912. StopTime: item.StopTime,
  4913. StopReason: item.StopReason,
  4914. StopDoctor: item.StopDoctor,
  4915. StopState: item.StopState,
  4916. ParentId: item.ParentId,
  4917. ExecutionTime: item.ExecutionTime,
  4918. ExecutionStaff: item.ExecutionStaff,
  4919. ExecutionState: item.ExecutionState,
  4920. Checker: item.Checker,
  4921. RecordDate: item.ReminderDate,
  4922. DialysisOrderId: item.DialysisOrderId,
  4923. CheckTime: item.CheckTime,
  4924. CheckState: item.CheckState,
  4925. RemindType: item.RemindType,
  4926. FrequencyType: item.FrequencyType,
  4927. DayCount: item.DayCount,
  4928. WeekDay: item.WeekDay,
  4929. TemplateId: item.TemplateId,
  4930. Modifier: item.Modifier,
  4931. Way: item.Way,
  4932. DrugId: item.DrugId,
  4933. }
  4934. if medical.IsUse == 2 {
  4935. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4936. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4937. }
  4938. if pharmacyConfig.IsOpen != 1 {
  4939. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4940. }
  4941. //更新字典里面的库存
  4942. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4943. var sum_count int64
  4944. for _, its := range stockInfo {
  4945. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4946. if its.MaxUnit == baseDrug.MaxUnit {
  4947. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4948. }
  4949. sum_count += its.StockMaxNumber + its.StockMinNumber
  4950. }
  4951. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4952. //剩余库存
  4953. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4954. }
  4955. info := models.DoctorAdvice{
  4956. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4957. ExecutionTime: exec_time,
  4958. ExecutionState: 1,
  4959. UpdatedTime: time.Now().Unix(),
  4960. }
  4961. //执行医嘱
  4962. service.UpdateDoctorAdviceExecution(info, item.ID)
  4963. }
  4964. }
  4965. this.ServeSuccessJSON(map[string]interface{}{
  4966. "msg": "1",
  4967. })
  4968. return
  4969. }
  4970. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  4971. orgId := this.GetAdminUserInfo().CurrentOrgId
  4972. idsStr := this.GetString("str")
  4973. recordIDStrs := strings.Split(idsStr, ",")
  4974. start_time := this.GetString("advice_date")
  4975. timeLayout := "2006-01-02"
  4976. loc, _ := time.LoadLocation("Local")
  4977. var startTime int64
  4978. if len(start_time) > 0 {
  4979. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4980. if err != nil {
  4981. //fmt.Println(err)
  4982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4983. return
  4984. }
  4985. startTime = theTime.Unix()
  4986. }
  4987. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  4988. if config.IsOpen == 1 {
  4989. creater := this.GetAdminUserInfo().AdminUser.Id
  4990. //查询未核对的医嘱
  4991. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  4992. for _, item := range advicelist {
  4993. if item.ExecutionStaff == creater {
  4994. this.ServeSuccessJSON(map[string]interface{}{
  4995. "msg": "2",
  4996. "advice": item,
  4997. })
  4998. return
  4999. }
  5000. service.CheckHisDoctorAdvice(item.ID, creater)
  5001. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5002. redis := service.RedisClient()
  5003. //清空key 值
  5004. redis.Set(key, "", time.Second)
  5005. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5006. redis.Set(keyTwo, "", time.Second)
  5007. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5008. redis.Set(keyThree, "", time.Second)
  5009. theTime := time.Now()
  5010. recordDate := theTime.Format("2006-01-02")
  5011. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5012. redis.Set(keyFour, "", time.Second)
  5013. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5014. redis.Set(keyFive, "", time.Second)
  5015. }
  5016. } else {
  5017. //查询未核对的医嘱
  5018. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5019. creater := this.GetAdminUserInfo().AdminUser.Id
  5020. for _, item := range advicelist {
  5021. if item.ExecutionStaff == creater {
  5022. this.ServeSuccessJSON(map[string]interface{}{
  5023. "msg": "2",
  5024. "advice": item,
  5025. })
  5026. return
  5027. }
  5028. service.CheckDoctorAdvice(item.ID, creater)
  5029. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5030. redis := service.RedisClient()
  5031. //清空key 值
  5032. redis.Set(key, "", time.Second)
  5033. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5034. redis.Set(keyTwo, "", time.Second)
  5035. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5036. redis.Set(keyThree, "", time.Second)
  5037. theTime := time.Now()
  5038. recordDate := theTime.Format("2006-01-02")
  5039. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5040. redis.Set(keyFour, "", time.Second)
  5041. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5042. redis.Set(keyFive, "", time.Second)
  5043. }
  5044. }
  5045. this.ServeSuccessJSON(map[string]interface{}{
  5046. "msg": "1",
  5047. })
  5048. return
  5049. }
  5050. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5051. orgId := this.GetAdminUserInfo().CurrentOrgId
  5052. is_open, _ := this.GetInt64("is_open")
  5053. idsStr := this.GetString("str")
  5054. recordIDStrs := strings.Split(idsStr, ",")
  5055. start_time := this.GetString("advice_date")
  5056. timeLayout := "2006-01-02"
  5057. loc, _ := time.LoadLocation("Local")
  5058. var startTime int64
  5059. if len(start_time) > 0 {
  5060. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5061. if err != nil {
  5062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5063. return
  5064. }
  5065. startTime = theTime.Unix()
  5066. }
  5067. if is_open == 1 {
  5068. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5069. } else {
  5070. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5071. }
  5072. this.ServeSuccessJSON(map[string]interface{}{
  5073. "msg": "1",
  5074. })
  5075. return
  5076. }
  5077. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5078. advice_id, _ := this.GetInt64("advice_id")
  5079. start_time := this.GetString("advice_date")
  5080. orgId := this.GetAdminUserInfo().CurrentOrgId
  5081. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5082. exec_time, _ := this.GetInt64("exec_time")
  5083. //his医嘱
  5084. if config.IsOpen == 1 {
  5085. //查询医嘱
  5086. advice, _ := service.GetHisDocById(advice_id, orgId)
  5087. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5088. this.ServeSuccessJSON(map[string]interface{}{
  5089. "msg": "3",
  5090. })
  5091. return
  5092. }
  5093. medical, _ := service.GetBaseDrugMedical(orgId)
  5094. var prescribing_number int64
  5095. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5096. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5097. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5098. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5099. }
  5100. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5101. prescribing_number = parseIntPrescribingNumber
  5102. }
  5103. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5104. prescribing_number = parseIntPrescribingNumber
  5105. }
  5106. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5107. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5108. //库存不足
  5109. if prescribing_number > drugStockOut.FlushCount {
  5110. this.ServeSuccessJSON(map[string]interface{}{
  5111. "msg": "2",
  5112. "drug": medical,
  5113. })
  5114. return
  5115. }
  5116. info := models.HisDoctorAdviceInfo{
  5117. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5118. ExecutionTime: exec_time,
  5119. ExecutionState: 1,
  5120. UpdatedTime: time.Now().Unix(),
  5121. }
  5122. //执行医嘱
  5123. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5124. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5125. redis := service.RedisClient()
  5126. //清空key 值
  5127. redis.Set(key, "", time.Second)
  5128. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5129. redis.Set(keyTwo, "", time.Second)
  5130. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5131. redis.Set(keyThree, "", time.Second)
  5132. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5133. theTime := toTime.Format("2006-01-02")
  5134. fmt.Println("theTIME", theTime)
  5135. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5136. redis.Set(keyFour, "", time.Second)
  5137. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5138. redis.Set(keyFive, "", time.Second)
  5139. //出库
  5140. if prescribing_number <= drugStockOut.FlushCount {
  5141. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5142. //执行出库逻辑
  5143. hisadvice := &models.HisDoctorAdviceInfo{
  5144. ID: advice.ID,
  5145. UserOrgId: advice.UserOrgId,
  5146. PatientId: advice.PatientId,
  5147. AdviceType: advice.AdviceType,
  5148. AdviceDate: advice.AdviceDate,
  5149. StartTime: advice.StartTime,
  5150. AdviceName: advice.AdviceName,
  5151. AdviceDesc: advice.AdviceDesc,
  5152. ReminderDate: advice.ReminderDate,
  5153. SingleDose: advice.SingleDose,
  5154. SingleDoseUnit: advice.SingleDoseUnit,
  5155. DrugSpec: advice.DrugSpec,
  5156. DrugSpecUnit: advice.DrugSpecUnit,
  5157. PrescribingNumber: advice.PrescribingNumber,
  5158. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5159. DeliveryWay: advice.DeliveryWay,
  5160. ExecutionFrequency: advice.ExecutionFrequency,
  5161. AdviceDoctor: advice.AdviceDoctor,
  5162. Status: 1,
  5163. CreatedTime: advice.CreatedTime,
  5164. UpdatedTime: advice.UpdatedTime,
  5165. AdviceAffirm: advice.AdviceAffirm,
  5166. Remark: advice.Remark,
  5167. StopTime: advice.StopTime,
  5168. StopReason: advice.StopReason,
  5169. StopDoctor: advice.StopDoctor,
  5170. StopState: advice.StopState,
  5171. ParentId: advice.ParentId,
  5172. ExecutionTime: advice.ExecutionTime,
  5173. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5174. ExecutionState: advice.ExecutionState,
  5175. Checker: advice.Checker,
  5176. RecordDate: advice.RecordDate,
  5177. DialysisOrderId: advice.DialysisOrderId,
  5178. CheckTime: advice.CheckTime,
  5179. CheckState: advice.CheckState,
  5180. RemindType: advice.RemindType,
  5181. FrequencyType: advice.FrequencyType,
  5182. DayCount: advice.DayCount,
  5183. WeekDay: advice.WeekDay,
  5184. TemplateId: advice.TemplateId,
  5185. Modifier: advice.Modifier,
  5186. Way: advice.Way,
  5187. DrugId: advice.DrugId,
  5188. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5189. }
  5190. if medical.IsUse == 2 {
  5191. if config.IsOpen != 1 {
  5192. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5193. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5194. }
  5195. //不通过药房发药
  5196. if pharmacyConfig.IsOpen != 1 {
  5197. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5198. }
  5199. //查询默认仓库
  5200. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5201. //查询默认仓库剩余多少库存
  5202. var sum_count int64
  5203. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5204. for _, its := range stockInfo {
  5205. if its.MaxUnit == medical.MaxUnit {
  5206. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5207. }
  5208. sum_count += its.StockMaxNumber + its.StockMinNumber
  5209. }
  5210. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5211. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5212. }
  5213. }
  5214. }
  5215. this.ServeSuccessJSON(map[string]interface{}{
  5216. "msg": "1",
  5217. })
  5218. return
  5219. }
  5220. if config.IsOpen == 2 || config.IsOpen == 0 {
  5221. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5222. medical, _ := service.GetBaseDrugMedical(orgId)
  5223. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5224. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5225. var prescribing_number int64
  5226. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5227. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5228. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5229. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5230. }
  5231. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5232. prescribing_number = parseIntPrescribingNumber
  5233. }
  5234. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5235. prescribing_number = parseIntPrescribingNumber
  5236. }
  5237. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5238. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5239. //库存不足
  5240. if prescribing_number > drugStockOut.FlushCount {
  5241. this.ServeSuccessJSON(map[string]interface{}{
  5242. "msg": "2",
  5243. "drug": medical,
  5244. })
  5245. return
  5246. }
  5247. info := models.DoctorAdvice{
  5248. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5249. ExecutionTime: exec_time,
  5250. ExecutionState: 1,
  5251. UpdatedTime: time.Now().Unix(),
  5252. }
  5253. //执行医嘱
  5254. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5255. dadvice := &models.DoctorAdvice{
  5256. ID: advice.ID,
  5257. UserOrgId: advice.UserOrgId,
  5258. PatientId: advice.PatientId,
  5259. AdviceType: advice.AdviceType,
  5260. AdviceDate: advice.AdviceDate,
  5261. StartTime: advice.StartTime,
  5262. AdviceName: advice.AdviceName,
  5263. AdviceDesc: advice.AdviceDesc,
  5264. ReminderDate: advice.ReminderDate,
  5265. SingleDose: advice.SingleDose,
  5266. SingleDoseUnit: advice.SingleDoseUnit,
  5267. DrugSpec: advice.DrugSpec,
  5268. DrugSpecUnit: advice.DrugSpecUnit,
  5269. PrescribingNumber: advice.PrescribingNumber,
  5270. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5271. DeliveryWay: advice.DeliveryWay,
  5272. ExecutionFrequency: advice.ExecutionFrequency,
  5273. AdviceDoctor: advice.AdviceDoctor,
  5274. Status: 1,
  5275. CreatedTime: advice.CreatedTime,
  5276. UpdatedTime: advice.UpdatedTime,
  5277. AdviceAffirm: advice.AdviceAffirm,
  5278. Remark: advice.Remark,
  5279. StopTime: advice.StopTime,
  5280. StopReason: advice.StopReason,
  5281. StopDoctor: advice.StopDoctor,
  5282. StopState: advice.StopState,
  5283. ParentId: advice.ParentId,
  5284. ExecutionTime: advice.ExecutionTime,
  5285. ExecutionStaff: advice.ExecutionStaff,
  5286. ExecutionState: advice.ExecutionState,
  5287. Checker: advice.Checker,
  5288. RecordDate: advice.ReminderDate,
  5289. DialysisOrderId: advice.DialysisOrderId,
  5290. CheckTime: advice.CheckTime,
  5291. CheckState: advice.CheckState,
  5292. RemindType: advice.RemindType,
  5293. FrequencyType: advice.FrequencyType,
  5294. DayCount: advice.DayCount,
  5295. WeekDay: advice.WeekDay,
  5296. TemplateId: advice.TemplateId,
  5297. Modifier: advice.Modifier,
  5298. Way: advice.Way,
  5299. DrugId: advice.DrugId,
  5300. }
  5301. if medical.IsUse == 2 {
  5302. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5303. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5304. }
  5305. if pharmacyConfig.IsOpen != 1 {
  5306. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5307. }
  5308. //更新字典里面的库存
  5309. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5310. var sum_count int64
  5311. for _, its := range stockInfo {
  5312. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5313. if its.MaxUnit == baseDrug.MaxUnit {
  5314. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5315. }
  5316. sum_count += its.StockMaxNumber + its.StockMinNumber
  5317. }
  5318. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5319. //剩余库存
  5320. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5321. }
  5322. }
  5323. this.ServeSuccessJSON(map[string]interface{}{
  5324. "msg": "1",
  5325. })
  5326. return
  5327. }
  5328. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5329. orgId := this.GetAdminUserInfo().CurrentOrgId
  5330. schedule_type, _ := this.GetInt64("schedule_type")
  5331. partion_type, _ := this.GetInt64("partion_type")
  5332. start_time := this.GetString("selected_date")
  5333. timeLayout := "2006-01-02"
  5334. loc, _ := time.LoadLocation("Local")
  5335. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5336. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, partion_type, startTime.Unix())
  5337. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5338. _, config := service.FindXTHisRecordByOrgId(orgId)
  5339. appId := this.GetAdminUserInfo().CurrentAppId
  5340. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5341. if err == nil {
  5342. this.ServeSuccessJSON(map[string]interface{}{
  5343. "list": list,
  5344. "drug": drug,
  5345. "config": config,
  5346. "doctorList": doctorList,
  5347. })
  5348. return
  5349. } else {
  5350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5351. return
  5352. }
  5353. }
  5354. func (this *DialysisApiController) GetMobileScheduleList() {
  5355. orgId := this.GetAdminUserInfo().CurrentOrgId
  5356. schedule, _ := service.GetMobileScheduleList(orgId)
  5357. if len(schedule) > 0 {
  5358. for _, its := range schedule {
  5359. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5360. //its.DialysisPrescription = prescription
  5361. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5362. //its.MonitoringRecord = monitor
  5363. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5364. //its.XtAssessmentAfterDislysis = after
  5365. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5366. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5367. }
  5368. }
  5369. this.ServeSuccessJSON(map[string]interface{}{
  5370. "schedule": schedule,
  5371. })
  5372. return
  5373. }