dialysis_api_controller.go 233KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098
  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. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1207. needle_batch_number := c.GetString("needle_batch_number")
  1208. if id <= 0 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. adminUserInfo := c.GetAdminUserInfo()
  1213. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1214. if patient.ID == 0 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1216. return
  1217. }
  1218. if len(recordDateStr) == 0 {
  1219. recordDateStr = time.Now().Format("2006-01-02")
  1220. }
  1221. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1222. if parseDateErr != nil {
  1223. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. var checkDate int64
  1228. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1229. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1230. if employee_number != list.JobNumber {
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1232. return
  1233. }
  1234. }
  1235. if len(checkTimeStr) == 0 {
  1236. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1237. checkDate = 0
  1238. } else {
  1239. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1240. checkDate = checkDateUnix.Unix()
  1241. }
  1242. var firstCheckTimeDate int64
  1243. if len(firstCheckTimeStr) == 0 {
  1244. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1245. firstCheckTimeDate = 0
  1246. } else {
  1247. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1248. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1249. }
  1250. doubleCheck := models.DoubleCheck{
  1251. UserOrgId: adminUserInfo.CurrentOrgId,
  1252. PatientId: id,
  1253. DialysisItemCheck: dialysis_item_check,
  1254. DialysisParameterCheck: dialysis_parameter_check,
  1255. VascularAccessVerification: vascular_access_verification,
  1256. PipelineConnectionCheck: pipeline_connection_check,
  1257. DialysisItemDesc: dialysis_item_desc,
  1258. DialysisParameterDesc: dialysis_parameter_desc,
  1259. VascularAccessDesc: vascular_access_desc,
  1260. PipelineConnectionDesc: pipeline_connection_desc,
  1261. Collator: collator,
  1262. Status: 1,
  1263. CreatedTime: time.Now().Unix(),
  1264. UpdatedTime: time.Now().Unix(),
  1265. CheckDate: recordDate.Unix(),
  1266. EmployeeNumber: employee_number,
  1267. DialyzerBatchNumber: dialyzer_batch_number,
  1268. NeedleBatchNumber: needle_batch_number,
  1269. }
  1270. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1271. if check.ID == 0 { //新增
  1272. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1273. doubleCheck.CheckTime = checkDate
  1274. doubleCheck.Creater = creater
  1275. doubleCheck.Modifier = modifier
  1276. err := service.AddSigleDoubleCheck(&doubleCheck)
  1277. redis := service.RedisClient()
  1278. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1279. //清空key 值
  1280. redis.Set(key, "", time.Second)
  1281. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1282. redis.Set(keyTwo, "", time.Second)
  1283. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1284. redis.Set(keyThree, "", time.Second)
  1285. defer redis.Close()
  1286. if err == nil {
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "doubleCheck": doubleCheck,
  1289. })
  1290. } else {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1292. }
  1293. } else { //修改
  1294. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1295. doubleCheck.CheckTime = checkDate
  1296. doubleCheck.Creater = creater
  1297. doubleCheck.Modifier = modifier
  1298. doubleCheck.CreatedTime = check.CreatedTime
  1299. doubleCheck.UpdatedTime = time.Now().Unix()
  1300. doubleCheck.ID = check.ID
  1301. redis := service.RedisClient()
  1302. err := service.UpdateDoubleCheck(&doubleCheck)
  1303. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1304. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1305. redis.Set(keyTwo, "", time.Second)
  1306. //清空key 值
  1307. redis.Set(key, "", time.Second)
  1308. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1309. redis.Set(keyThree, "", time.Second)
  1310. defer redis.Close()
  1311. if err == nil {
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "doubleCheck": doubleCheck,
  1314. })
  1315. } else {
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1317. }
  1318. }
  1319. }
  1320. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1321. id, _ := c.GetInt64("patient", 0)
  1322. recordDateStr := c.GetString("record_date")
  1323. way, _ := c.GetInt64("way", 0)
  1324. consciousness, _ := c.GetInt64("consciousness", 0)
  1325. appetite, _ := c.GetInt64("appetite", 0)
  1326. condition, _ := c.GetInt64("condition", 0)
  1327. posture, _ := c.GetInt64("posture")
  1328. score := c.GetString("score")
  1329. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1330. danger_level, _ := c.GetInt64("danger_level", 0)
  1331. intake, _ := c.GetInt64("intake", 0)
  1332. nutrition, _ := c.GetInt64("nutrition", 0)
  1333. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1334. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1335. sick_condition_other := c.GetString("sick_condition_other")
  1336. //precaution, _ := c.GetInt64("precaution", 0)
  1337. precaution := c.GetString("precaution")
  1338. precaution_other := c.GetString("precaution_other")
  1339. psychological_other := c.GetString("psychological_other")
  1340. admission_number := c.GetString("admission_number")
  1341. tumble, _ := c.GetInt64("tumble")
  1342. his_department := c.GetString("his_department")
  1343. his_bed := c.GetString("his_bed")
  1344. diacrisis := c.GetString("diacrisis")
  1345. if id <= 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. adminUserInfo := c.GetAdminUserInfo()
  1350. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1351. if patient.ID == 0 {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1353. return
  1354. }
  1355. if len(recordDateStr) == 0 {
  1356. recordDateStr = time.Now().Format("2006-01-02")
  1357. }
  1358. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1359. if parseDateErr != nil {
  1360. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1365. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1366. UserOrgId: adminUserInfo.CurrentOrgId,
  1367. PatientId: id,
  1368. RecordDate: recordDate.Unix(),
  1369. Way: way,
  1370. Consciousness: consciousness,
  1371. Appetite: appetite,
  1372. Condition: condition,
  1373. SickCondition: sick_condition,
  1374. DangerLevel: danger_level,
  1375. Intake: intake,
  1376. Nutrition: nutrition,
  1377. PsychologicalAssessment: psychological_assessment,
  1378. PsychologicalAssessmentOther: psychological_assessment_other,
  1379. SickConditionOther: sick_condition_other,
  1380. Posture: posture,
  1381. CreatedTime: time.Now().Unix(),
  1382. UpdateTime: time.Now().Unix(),
  1383. Status: 1,
  1384. Score: score,
  1385. Precaution: precaution,
  1386. PrecautionOther: precaution_other,
  1387. PsychologicalOther: psychological_other,
  1388. AdmissionNumber: admission_number,
  1389. Tumble: tumble,
  1390. HisDepartment: his_department,
  1391. HisBed: his_bed,
  1392. Diacrisis: diacrisis,
  1393. }
  1394. if receiveTreatment.ID == 0 { //新增
  1395. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1396. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1397. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1398. redis := service.RedisClient()
  1399. //清空key 值
  1400. redis.Set(key, "", time.Second)
  1401. defer redis.Close()
  1402. if err == nil {
  1403. c.ServeSuccessJSON(map[string]interface{}{
  1404. "receiveTreatmentAsses": receiveTreatmentAsses,
  1405. })
  1406. } else {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1408. }
  1409. } else { //修改
  1410. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1411. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1412. // if getPermissionErr != nil {
  1413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1414. // return
  1415. // } else if headNursePermission == nil {
  1416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1417. // return
  1418. // }
  1419. //}
  1420. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1421. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1422. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1423. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1424. receiveTreatmentAsses.ID = receiveTreatment.ID
  1425. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1426. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1427. redis := service.RedisClient()
  1428. defer redis.Close()
  1429. redis.Set(keyOne, "", time.Second*60*60*18)
  1430. if err == nil {
  1431. c.ServeSuccessJSON(map[string]interface{}{
  1432. "receiveTreatmentAsses": receiveTreatmentAsses,
  1433. })
  1434. } else {
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1436. }
  1437. }
  1438. }
  1439. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1440. patient, _ := c.GetInt64("patient", 0)
  1441. recordDateStr := c.GetString("record_date")
  1442. fmt.Println(recordDateStr)
  1443. if patient <= 0 {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1445. return
  1446. }
  1447. adminUserInfo := c.GetAdminUserInfo()
  1448. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1449. if patientInfo.ID == 0 {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1451. return
  1452. }
  1453. if len(recordDateStr) == 0 {
  1454. recordDateStr = time.Now().Format("2006-01-02")
  1455. }
  1456. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1457. if parseDateErr != nil {
  1458. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. // data := make(map[string]interface{}, 0)
  1463. var data models.AssessmentAfterDislysis
  1464. var err error
  1465. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1466. fmt.Println(err)
  1467. if err != nil {
  1468. c.ErrorLog("数据解析错误:%v", err)
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1473. assessment.DialysisOrderId = data.DialysisOrderId
  1474. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1475. assessment.Status = 1
  1476. assessment.WeightAfter = data.WeightAfter
  1477. assessment.WeightLoss = data.WeightLoss
  1478. assessment.Temperature = data.Temperature
  1479. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1480. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1481. assessment.PulseFrequency = data.PulseFrequency
  1482. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1483. assessment.ActualDisplacement = data.ActualDisplacement
  1484. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1485. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1486. assessment.Cruor = data.Cruor
  1487. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1488. assessment.DialysisIntakes = data.DialysisIntakes
  1489. assessment.InternalFistula = data.InternalFistula
  1490. assessment.BloodAccessPartId = data.BloodAccessPartId
  1491. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1492. assessment.Catheter = data.Catheter
  1493. assessment.Complication = data.Complication
  1494. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1495. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1496. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1497. assessment.PatientGose = data.PatientGose
  1498. assessment.InpatientDepartment = data.InpatientDepartment
  1499. assessment.ObservationContent = data.ObservationContent
  1500. assessment.ObservationContentOther = data.ObservationContentOther
  1501. assessment.Remark = data.Remark
  1502. assessment.BreathingRate = data.BreathingRate
  1503. assessment.DialysisProcess = data.DialysisProcess
  1504. assessment.InAdvanceMinute = data.InAdvanceMinute
  1505. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1506. assessment.InAdvanceReason = data.InAdvanceReason
  1507. assessment.HemostasisOpera = data.HemostasisOpera
  1508. assessment.HemostasisMinute = data.HemostasisMinute
  1509. assessment.TremorNoise = data.TremorNoise
  1510. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1511. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1512. assessment.ArterialTube = data.ArterialTube
  1513. assessment.IntravenousTube = data.IntravenousTube
  1514. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1515. assessment.Dialyzer = data.Dialyzer
  1516. assessment.IsEat = data.IsEat
  1517. assessment.CvcA = data.CvcA
  1518. assessment.CvcV = data.CvcV
  1519. assessment.Channel = data.Channel
  1520. assessment.ReturnBlood = data.ReturnBlood
  1521. assessment.RehydrationVolume = data.RehydrationVolume
  1522. assessment.DialysisDuring = data.DialysisDuring
  1523. assessment.StrokeVolume = data.StrokeVolume
  1524. assessment.BloodFlow = data.BloodFlow
  1525. assessment.SealingFluidDispose = data.SealingFluidDispose
  1526. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1527. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1528. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1529. assessment.SettingPressure = data.SettingPressure
  1530. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1531. assessment.DiastolicPressure = data.DiastolicPressure
  1532. assessment.AdditionalWeight = data.AdditionalWeight
  1533. assessment.OtherComplication = data.OtherComplication
  1534. assessment.Ktv = data.Ktv
  1535. assessment.Urr = data.Urr
  1536. assessment.Hypertenison = data.Hypertenison
  1537. assessment.Hypopiesia = data.Hypopiesia
  1538. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1539. assessment.Lapse = data.Lapse
  1540. assessment.Consciousness = data.Consciousness
  1541. assessment.Fallrisk = data.Fallrisk
  1542. assessment.MachineRun = data.MachineRun
  1543. assessment.AfterUrea = data.AfterUrea
  1544. assessment.PipCoagulation = data.PipCoagulation
  1545. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1546. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1547. if assessment.ID > 0 {
  1548. if appRole.UserType == 2 || appRole.UserType == 1 {
  1549. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1550. assessment.AssessmentTime = time.Now().Unix()
  1551. } else {
  1552. if assessment.Creater == 0 {
  1553. assessment.Modifier = adminUserInfo.AdminUser.Id
  1554. assessment.Creater = adminUserInfo.AdminUser.Id
  1555. } else {
  1556. assessment.Modifier = adminUserInfo.AdminUser.Id
  1557. }
  1558. }
  1559. assessment.UpdatedTime = time.Now().Unix()
  1560. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1561. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1562. redis := service.RedisClient()
  1563. //清空key 值
  1564. redis.Set(key, "", time.Second)
  1565. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1566. redis.Set(keyThree, "", time.Second)
  1567. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1568. redis.Set(keyTwo, "", time.Second)
  1569. defer redis.Close()
  1570. } else {
  1571. if appRole.UserType == 2 || appRole.UserType == 1 {
  1572. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1573. assessment.AssessmentTime = time.Now().Unix()
  1574. } else {
  1575. assessment.Creater = adminUserInfo.AdminUser.Id
  1576. }
  1577. assessment.CreatedTime = time.Now().Unix()
  1578. assessment.UpdatedTime = time.Now().Unix()
  1579. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1580. assessment.PatientId = patient
  1581. assessment.AssessmentDate = recordDate.Unix()
  1582. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1583. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1584. redis := service.RedisClient()
  1585. //清空key 值
  1586. redis.Set(key, "", time.Second)
  1587. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1588. redis.Set(keyThree, "", time.Second)
  1589. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1590. redis.Set(keyTwo, "", time.Second)
  1591. defer redis.Close()
  1592. }
  1593. if err != nil {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1595. return
  1596. }
  1597. c.ServeSuccessJSON(map[string]interface{}{
  1598. "AssessmentAfterDislysis": &assessment,
  1599. })
  1600. }
  1601. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1602. patient, _ := c.GetInt64("patient", 0)
  1603. recordDateStr := c.GetString("record_date")
  1604. if patient <= 0 {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1606. return
  1607. }
  1608. adminUserInfo := c.GetAdminUserInfo()
  1609. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1610. if patientInfo.ID == 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1612. return
  1613. }
  1614. if len(recordDateStr) == 0 {
  1615. recordDateStr = time.Now().Format("2006-01-02")
  1616. }
  1617. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1618. if parseDateErr != nil {
  1619. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. weight_before, _ := c.GetFloat("weight_before", 0)
  1624. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1625. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1626. temperature, _ := c.GetFloat("temperature", 0)
  1627. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1628. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1629. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1630. last_post_dialysis := c.GetString("last_post_dialysis")
  1631. dialysis_interphase := c.GetString("dialysis_interphase")
  1632. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1633. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1634. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1635. bloodAccessPartId := c.GetString("blood_access_part_id")
  1636. internalFistula := c.GetString("internal_fistula")
  1637. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1638. catheter := c.GetString("catheter")
  1639. catheter_bend, _ := c.GetInt("catheter_bend")
  1640. complication := c.GetString("complication")
  1641. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1642. hemorrhage := c.GetString("hemorrhage")
  1643. hemorrhage_other := c.GetString("hemorrhage_other")
  1644. remark := c.GetString("remark")
  1645. puncture_method := c.GetString("puncture_method")
  1646. dialysis_count := c.GetString("dialysis_count")
  1647. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1648. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1649. ductus_arantii := c.GetString("ductus_arantii")
  1650. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1651. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1652. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1653. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1654. puncture_way := c.GetString("puncture_way")
  1655. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1656. internal_fistula_other := c.GetString("internal_fistula_other")
  1657. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1658. breathing_rate := c.GetString("breathing_rate")
  1659. is_infect, _ := c.GetInt64("is_infect", 0)
  1660. exposed, _ := c.GetFloat("exposed", 0)
  1661. skin := c.GetString("skin")
  1662. skin_other := c.GetString("skin_other")
  1663. infect_other := c.GetString("infect_other")
  1664. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1665. machine_type := c.GetString("machine_type")
  1666. puncture_needle := c.GetString("puncture_needle")
  1667. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1668. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1669. phinholing := c.GetString("pinholing")
  1670. catheter_suture := c.GetString("catheter_suture")
  1671. catheter_suture_other := c.GetString("catheter_suture_other")
  1672. edema := c.GetString("edema")
  1673. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1674. special_treatment := c.GetString("special_treatment")
  1675. catheter_maintenance := c.GetString("catheter_maintenance")
  1676. thrombusType := c.GetString("thromubus_type")
  1677. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1678. thrombus_a := c.GetString("thromubus_a")
  1679. thrombus_av := c.GetString("thrombus_av")
  1680. thrombus_v := c.GetString("thromubus_v")
  1681. dehydration := c.GetString("dehydration")
  1682. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1683. period, _ := c.GetInt64("period")
  1684. estimated_food_intake := c.GetString("estimated_food_intake")
  1685. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1686. urea_befor := c.GetString("urea_befor")
  1687. suction := c.GetString("suction")
  1688. weight_befor_remake := c.GetString("weight_befor_remake")
  1689. height := c.GetString("height")
  1690. age := c.GetString("age")
  1691. his_department := c.GetString("his_department")
  1692. his_bed := c.GetString("his_bed")
  1693. point_puncture := c.GetString("point_puncture")
  1694. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1695. DialysisCount: dialysis_count,
  1696. EmergencyTreatment: emergency_treatment,
  1697. EmergencyTreatmentOther: emergency_treatment_other,
  1698. DuctusArantii: ductus_arantii,
  1699. VenousCatheterization: venous_catheterization,
  1700. VenousCatheterizationPart: venous_catheterization_part,
  1701. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1702. PunctureWay: puncture_way,
  1703. BloodAccessInternalFistula: blood_access_internal_fistula,
  1704. BloodAccessNoise: blood_access_noise,
  1705. InternalFistulaOther: internal_fistula_other,
  1706. Evaluator: adminUserInfo.AdminUser.Id,
  1707. UserOrgId: adminUserInfo.CurrentOrgId,
  1708. PatientId: patient,
  1709. AssessmentDate: recordDate.Unix(),
  1710. Temperature: temperature,
  1711. PulseFrequency: pulse_frequency,
  1712. SystolicBloodPressure: systolic_blood_pressure,
  1713. DiastolicBloodPressure: diastolic_blood_pressure,
  1714. WeightBefore: weight_before,
  1715. DryWeight: dry_weight,
  1716. AdditionalWeight: additional_weight,
  1717. DialysisInterphase: dialysis_interphase,
  1718. LastPostDialysis: last_post_dialysis,
  1719. SymptomBeforeDialysis: symptom_before_dialysis,
  1720. InternalFistula: internalFistula,
  1721. InternalFistulaSkin: internal_fistula_skin,
  1722. Catheter: catheter,
  1723. CatheterBend: catheter_bend,
  1724. Complication: complication,
  1725. CreatedTime: time.Now().Unix(),
  1726. Status: 1,
  1727. Remark: remark,
  1728. IsHemorrhage: is_hemorrhage,
  1729. Hemorrhage: hemorrhage,
  1730. HemorrhageOther: hemorrhage_other,
  1731. BloodAccessPartId: bloodAccessPartId,
  1732. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1733. PunctureMethod: puncture_method,
  1734. BreathingRate: breathing_rate,
  1735. IsInfect: is_infect,
  1736. Exposed: exposed,
  1737. Skin: skin,
  1738. SkinOther: skin_other,
  1739. InfectOther: infect_other,
  1740. DuctusArantiiOther: ductus_arantii_other,
  1741. MachineType: machine_type,
  1742. PunctureNeedle: puncture_needle,
  1743. HumorExcessiveSymptom: humor_excessive_symptom,
  1744. Phinholing: phinholing,
  1745. CatheterSuture: catheter_suture,
  1746. CatheterSutureOther: catheter_suture_other,
  1747. Edema: edema,
  1748. UrineVolume: urine_volume,
  1749. SpecialTreatment: special_treatment,
  1750. CatheterMaintenance: catheter_maintenance,
  1751. ThromubusType: thrombusInt,
  1752. ThrombusAv: thrombus_av,
  1753. ThromubusA: thrombus_a,
  1754. ThromubusV: thrombus_v,
  1755. Dehydration: dehydration,
  1756. PreDialysisDrugs: pre_dialysis_drugs,
  1757. Period: period,
  1758. EstimatedFoodIntake: estimated_food_intake,
  1759. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1760. UreaBefor: urea_befor,
  1761. Suction: suction,
  1762. WeightBeforRemake: weight_befor_remake,
  1763. Height: height,
  1764. Age: age,
  1765. HisDepartment: his_department,
  1766. HisBed: his_bed,
  1767. PointPuncture: point_puncture,
  1768. }
  1769. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1770. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1771. if evaluation.ID == 0 { //新增
  1772. if appRole.UserType == 2 || appRole.UserType == 1 {
  1773. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1774. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1775. } else {
  1776. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1777. }
  1778. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1779. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1780. var dewater_amount float64
  1781. dewater_amount = 0
  1782. if dry_weight > 0 {
  1783. dewater_amount = weight_before - dry_weight - additional_weight
  1784. dewater_amount = dewater_amount * 1000
  1785. if dewater_amount <= 0 {
  1786. dewater_amount = 0
  1787. }
  1788. } else {
  1789. dewater_amount = 0
  1790. }
  1791. // 计算透析处方的相关超滤量
  1792. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1793. var lastDialysisPrescribe *models.DialysisPrescription
  1794. var dialysisSolution *models.DialysisSolution
  1795. var dialysisPrescribe *models.DialysisPrescription
  1796. var mode_id int64
  1797. if schedual != nil {
  1798. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1799. if dialysisPrescribe == nil {
  1800. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1801. }
  1802. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1803. // 获取透析模版
  1804. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1805. mode_id = schedual.ModeId
  1806. } else {
  1807. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1808. // 获取透析模版
  1809. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1810. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1811. if dialysisPrescribe == nil && dialysisSolution != nil {
  1812. mode_id = dialysisSolution.ModeId
  1813. }
  1814. if dialysisPrescribe == nil && dialysisSolution == nil {
  1815. mode_id = 0
  1816. }
  1817. }
  1818. // 插入透析处方
  1819. if dialysisPrescribe == nil && dialysisSolution != nil {
  1820. var newprescribe models.DialysisPrescription
  1821. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1822. newprescribe.PatientId = dialysisSolution.PatientId
  1823. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1824. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1825. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1826. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1827. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1828. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1829. newprescribe.ModeId = dialysisSolution.ModeId
  1830. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1831. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1832. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1833. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1834. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1835. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1836. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1837. newprescribe.Glucose = dialysisSolution.Glucose
  1838. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1839. newprescribe.Kalium = dialysisSolution.Kalium
  1840. newprescribe.Sodium = dialysisSolution.Sodium
  1841. newprescribe.Calcium = dialysisSolution.Calcium
  1842. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1843. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1844. newprescribe.Conductivity = dialysisSolution.Conductivity
  1845. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1846. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1847. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1848. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1849. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1850. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1851. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1852. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1853. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1854. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1855. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1856. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1857. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1858. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1859. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1860. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1861. newprescribe.CreatedTime = time.Now().Unix()
  1862. newprescribe.UpdatedTime = time.Now().Unix()
  1863. newprescribe.RecordDate = recordDate.Unix()
  1864. newprescribe.DewaterAmount = dewater_amount
  1865. newprescribe.TargetUltrafiltration = dewater_amount
  1866. newprescribe.Status = 1
  1867. err := service.AddSigleRecord(&newprescribe)
  1868. if err != nil {
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1870. }
  1871. }
  1872. if dialysisPrescribe == nil && dialysisSolution == nil {
  1873. if lastDialysisPrescribe != nil {
  1874. var newprescribe models.DialysisPrescription
  1875. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1876. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1877. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1878. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1879. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1880. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1881. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1882. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1883. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1884. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1885. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1886. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1887. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1888. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1889. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1890. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1891. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1892. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1893. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1894. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1895. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1896. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1897. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1898. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1899. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1900. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1901. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1902. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1903. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1904. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1905. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1906. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1907. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1908. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1909. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1910. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1911. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1912. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1913. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1914. newprescribe.CreatedTime = time.Now().Unix()
  1915. newprescribe.UpdatedTime = time.Now().Unix()
  1916. newprescribe.RecordDate = recordDate.Unix()
  1917. newprescribe.DewaterAmount = dewater_amount
  1918. newprescribe.TargetUltrafiltration = dewater_amount
  1919. newprescribe.Status = 1
  1920. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1921. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1922. err := service.AddSigleRecord(&newprescribe)
  1923. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1924. redis := service.RedisClient()
  1925. defer redis.Close()
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1929. redis.Set(keyOne, "", time.Second)
  1930. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1931. redis.Set(keyThree, "", time.Second)
  1932. if err != nil {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1934. }
  1935. } else {
  1936. var newprescribe models.DialysisPrescription
  1937. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1938. newprescribe.PatientId = patient
  1939. newprescribe.ModeId = mode_id
  1940. newprescribe.CreatedTime = time.Now().Unix()
  1941. newprescribe.UpdatedTime = time.Now().Unix()
  1942. newprescribe.RecordDate = recordDate.Unix()
  1943. newprescribe.DewaterAmount = dewater_amount
  1944. newprescribe.TargetUltrafiltration = dewater_amount
  1945. newprescribe.Status = 1
  1946. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1947. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1948. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  1949. err := service.AddSigleRecord(&newprescribe)
  1950. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1951. redis := service.RedisClient()
  1952. defer redis.Close()
  1953. //清空key 值
  1954. redis.Set(key, "", time.Second)
  1955. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1956. redis.Set(keyOne, "", time.Second)
  1957. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1958. redis.Set(keyThree, "", time.Second)
  1959. if err != nil {
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1961. }
  1962. }
  1963. }
  1964. }
  1965. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1966. redis := service.RedisClient()
  1967. //清空key 值
  1968. redis.Set(key, "", time.Second)
  1969. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1970. redis.Set(keyOne, "", time.Second)
  1971. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1972. redis.Set(keyTwo, "", time.Second)
  1973. defer redis.Close()
  1974. if err == nil {
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1977. })
  1978. } else {
  1979. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1981. }
  1982. } else { //修改
  1983. //if appRole.UserType == 3 {
  1984. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1985. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1986. // if getPermissionErr != nil {
  1987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1988. // return
  1989. // } else if headNursePermission == nil {
  1990. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1991. // return
  1992. // }
  1993. // }
  1994. //}
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1997. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1998. } else {
  1999. if evaluation.Creater == 0 {
  2000. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2001. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2002. } else {
  2003. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2004. }
  2005. }
  2006. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2007. assessmentBeforeDislysis.ID = evaluation.ID
  2008. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2009. //
  2010. //新增逻辑
  2011. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2012. var dewater_amount float64
  2013. dewater_amount = 0
  2014. if evaluation.DryWeight > 0 {
  2015. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2016. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2017. dewater_amount = dewater_amount * 1000
  2018. }
  2019. if dewater_amount <= 0 {
  2020. dewater_amount = 0
  2021. }
  2022. } else {
  2023. dewater_amount = 0
  2024. }
  2025. // 计算透析处方的相关超滤量
  2026. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2027. var lastDialysisPrescribe *models.DialysisPrescription
  2028. var dialysisSolution *models.DialysisSolution
  2029. var dialysisPrescribe *models.DialysisPrescription
  2030. var mode_id int64
  2031. if schedual != nil {
  2032. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2033. if dialysisPrescribe == nil {
  2034. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2035. }
  2036. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2037. // 获取透析模版
  2038. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2039. mode_id = schedual.ModeId
  2040. } else {
  2041. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2042. // 获取透析模版
  2043. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2044. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2045. if dialysisPrescribe == nil && dialysisSolution != nil {
  2046. mode_id = dialysisSolution.ModeId
  2047. }
  2048. if dialysisPrescribe == nil && dialysisSolution == nil {
  2049. mode_id = 0
  2050. }
  2051. }
  2052. // 插入透析处方
  2053. if dialysisPrescribe == nil && dialysisSolution != nil {
  2054. var newprescribe models.DialysisPrescription
  2055. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2056. newprescribe.PatientId = dialysisSolution.PatientId
  2057. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2058. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2059. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2060. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2061. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2062. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2063. newprescribe.ModeId = dialysisSolution.ModeId
  2064. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2065. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2066. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2067. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2068. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2069. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2070. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2071. newprescribe.Glucose = dialysisSolution.Glucose
  2072. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2073. newprescribe.Kalium = dialysisSolution.Kalium
  2074. newprescribe.Sodium = dialysisSolution.Sodium
  2075. newprescribe.Calcium = dialysisSolution.Calcium
  2076. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2077. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2078. newprescribe.Conductivity = dialysisSolution.Conductivity
  2079. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2080. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2081. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2082. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2083. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2084. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2085. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2086. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2087. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2088. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2089. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2090. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2091. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2092. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2093. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2094. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2095. newprescribe.CreatedTime = time.Now().Unix()
  2096. newprescribe.UpdatedTime = time.Now().Unix()
  2097. newprescribe.RecordDate = recordDate.Unix()
  2098. newprescribe.DewaterAmount = dewater_amount
  2099. newprescribe.TargetUltrafiltration = dewater_amount
  2100. newprescribe.Status = 1
  2101. err := service.AddSigleRecord(&newprescribe)
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2104. }
  2105. }
  2106. if dialysisPrescribe == nil && dialysisSolution == nil {
  2107. if lastDialysisPrescribe != nil {
  2108. var newprescribe models.DialysisPrescription
  2109. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2110. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2111. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2112. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2113. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2114. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2115. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2116. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2117. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2118. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2119. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2120. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2121. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2122. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2123. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2124. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2125. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2126. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2127. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2128. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2129. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2130. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2131. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2132. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2133. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2134. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2135. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2136. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2137. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2138. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2139. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2140. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2141. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2142. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2143. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2144. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2145. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2146. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2147. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2148. newprescribe.CreatedTime = time.Now().Unix()
  2149. newprescribe.UpdatedTime = time.Now().Unix()
  2150. newprescribe.RecordDate = recordDate.Unix()
  2151. newprescribe.DewaterAmount = dewater_amount
  2152. newprescribe.TargetUltrafiltration = dewater_amount
  2153. newprescribe.Status = 1
  2154. err := service.AddSigleRecord(&newprescribe)
  2155. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2156. redis := service.RedisClient()
  2157. defer redis.Close()
  2158. //清空key 值
  2159. redis.Set(key, "", time.Second)
  2160. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2161. redis.Set(keyOne, "", time.Second)
  2162. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2163. redis.Set(keyThree, "", time.Second)
  2164. if err != nil {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2166. }
  2167. } else {
  2168. var newprescribe models.DialysisPrescription
  2169. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2170. newprescribe.PatientId = patient
  2171. newprescribe.ModeId = mode_id
  2172. newprescribe.CreatedTime = time.Now().Unix()
  2173. newprescribe.UpdatedTime = time.Now().Unix()
  2174. newprescribe.RecordDate = recordDate.Unix()
  2175. newprescribe.DewaterAmount = dewater_amount
  2176. newprescribe.TargetUltrafiltration = dewater_amount
  2177. newprescribe.Status = 1
  2178. err := service.AddSigleRecord(&newprescribe)
  2179. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2180. redis := service.RedisClient()
  2181. defer redis.Close()
  2182. //清空key 值
  2183. redis.Set(key, "", time.Second)
  2184. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2185. redis.Set(keyOne, "", time.Second)
  2186. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2187. redis.Set(keyThree, "", time.Second)
  2188. if err != nil {
  2189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2190. }
  2191. }
  2192. }
  2193. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2194. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2195. redis := service.RedisClient()
  2196. //清空key 值
  2197. redis.Set(key, "", time.Second)
  2198. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2199. redis.Set(keyOne, "", time.Second)
  2200. defer redis.Close()
  2201. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2202. redis.Set(keyTwo, "", time.Second)
  2203. if err == nil {
  2204. c.ServeSuccessJSON(map[string]interface{}{
  2205. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2206. })
  2207. } else {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2209. }
  2210. }
  2211. }
  2212. func (c *DialysisApiController) PostTreatmentSummary() {
  2213. patient, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. if patient <= 0 {
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2217. return
  2218. }
  2219. adminUserInfo := c.GetAdminUserInfo()
  2220. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2221. if patientInfo.ID == 0 {
  2222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2223. return
  2224. }
  2225. if len(recordDateStr) == 0 {
  2226. recordDateStr = time.Now().Format("2006-01-02")
  2227. }
  2228. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2229. if parseDateErr != nil {
  2230. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. mission := c.GetString("mission")
  2235. dialysis_summary := c.GetString("dialysis_summary")
  2236. nursingRecord := c.GetString("nursing_record")
  2237. specialRecord := c.GetString("special_record")
  2238. sj_nurse := adminUserInfo.AdminUser.Id
  2239. zl_nurse := adminUserInfo.AdminUser.Id
  2240. hd_nurse := adminUserInfo.AdminUser.Id
  2241. xj_nurse := adminUserInfo.AdminUser.Id
  2242. zl_doctor := adminUserInfo.AdminUser.Id
  2243. treatmentSummary := models.TreatmentSummary{
  2244. UserOrgId: adminUserInfo.CurrentOrgId,
  2245. PatientId: patient,
  2246. AssessmentDate: recordDate.Unix(),
  2247. Mission: mission,
  2248. DialysisSummary: dialysis_summary,
  2249. SjNurse: sj_nurse,
  2250. ZlNurse: zl_nurse,
  2251. HdNurse: hd_nurse,
  2252. XjNurse: xj_nurse,
  2253. ZlDoctor: zl_doctor,
  2254. Status: 1,
  2255. CreatedTime: time.Now().Unix(),
  2256. NursingRecord: nursingRecord,
  2257. SpecialRecord: specialRecord,
  2258. }
  2259. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2260. if tempTreatmentSummary.ID == 0 { //新增
  2261. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2262. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2263. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2264. redis := service.RedisClient()
  2265. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2266. redis.Set(keyOne, "", time.Second)
  2267. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2268. redis.Set(keyThree, "", time.Second)
  2269. defer redis.Close()
  2270. //清空key 值
  2271. redis.Set(key, "", time.Second)
  2272. if err == nil {
  2273. c.ServeSuccessJSON(map[string]interface{}{
  2274. "summary": treatmentSummary,
  2275. })
  2276. } else {
  2277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2278. }
  2279. } else { //修改
  2280. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2281. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2282. // if getPermissionErr != nil {
  2283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. // return
  2285. // } else if headNursePermission == nil {
  2286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2287. // return
  2288. // }
  2289. //}
  2290. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2291. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2292. treatmentSummary.UpdatedTime = time.Now().Unix()
  2293. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2294. treatmentSummary.ID = tempTreatmentSummary.ID
  2295. err := service.UpdateSummeRecord(&treatmentSummary)
  2296. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2297. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2298. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2299. //清空key 值
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. redis.Set(keyOne, "", time.Second)
  2303. redis.Set(keyThree, "", time.Second)
  2304. defer redis.Close()
  2305. if err == nil {
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "summary": treatmentSummary,
  2308. })
  2309. } else {
  2310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2311. }
  2312. }
  2313. }
  2314. func (c *DialysisApiController) GetDeviceList() {
  2315. adminUserInfo := c.GetAdminUserInfo()
  2316. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2317. c.ServeSuccessJSON(map[string]interface{}{
  2318. "device": device,
  2319. })
  2320. }
  2321. func (c *DialysisApiController) GetAllDeviceZone() {
  2322. adminUserInfo := c.GetAdminUserInfo()
  2323. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2324. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2325. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2326. if err == nil {
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "zone": zone,
  2329. "dics": dics,
  2330. "efs": efs,
  2331. })
  2332. }
  2333. }
  2334. func (c *DialysisApiController) GetDialysisWatch() {
  2335. page, _ := c.GetInt64("page", 1)
  2336. limit, _ := c.GetInt64("limit", 10)
  2337. schedulType, _ := c.GetInt64("schedul_type", 0)
  2338. startTime, _ := c.GetInt64("schedul_time", 0)
  2339. partitionType, _ := c.GetInt64("partition_type", 0)
  2340. keywords := c.GetString("keywords")
  2341. start_time, _ := c.GetInt64("start_time")
  2342. end_time, _ := c.GetInt64("end_time")
  2343. adminUserInfo := c.GetAdminUserInfo()
  2344. if len(keywords) > 0 {
  2345. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2346. if err == nil {
  2347. c.ServeSuccessJSON(map[string]interface{}{
  2348. "schedule": dialysisSchedule,
  2349. "total": total,
  2350. })
  2351. } else {
  2352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2353. }
  2354. } else {
  2355. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2356. if err == nil {
  2357. c.ServeSuccessJSON(map[string]interface{}{
  2358. "schedule": dialysisSchedule,
  2359. "total": total,
  2360. })
  2361. } else {
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2363. }
  2364. }
  2365. }
  2366. //func (c *DialysisApiController) GetDialysisWatch() {
  2367. // page, _ := c.GetInt64("page", 1)
  2368. // limit, _ := c.GetInt64("limit", 10)
  2369. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2370. // startTime, _ := c.GetInt64("schedul_time", 0)
  2371. // partitionType, _ := c.GetInt64("partition_type", 0)
  2372. // keywords := c.GetString("keywords")
  2373. //
  2374. // adminUserInfo := c.GetAdminUserInfo()
  2375. // if len(keywords) > 0 {
  2376. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2377. //
  2378. // //获取所有床位号
  2379. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2380. //
  2381. // //获取透析处方
  2382. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2383. // //获取透前评估
  2384. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2385. // //获取上机
  2386. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2387. // //获取透后
  2388. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2389. //
  2390. // //获取透后监测
  2391. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2392. //
  2393. // //获取所有的患者
  2394. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2395. //
  2396. // //获取所有透析模式
  2397. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2398. //
  2399. // for key, scheduals := range dialysisSchedule {
  2400. // // 获取患者信息
  2401. // for _, patient := range patients {
  2402. // if scheduals.PatientId == patient.ID {
  2403. // dialysisSchedule[key].MonitorPatients = patient
  2404. // break
  2405. // }
  2406. // }
  2407. // // 床位信息
  2408. // for _, device := range numberList {
  2409. // if scheduals.BedId == device.ID {
  2410. // dialysisSchedule[key].DeviceNumber = device
  2411. // break
  2412. // }
  2413. // }
  2414. //
  2415. // // 医嘱信息
  2416. // for _, prescription := range prescriptions {
  2417. // if scheduals.PatientId == prescription.PatientId {
  2418. // dialysisSchedule[key].Prescription = prescription
  2419. // break
  2420. // }
  2421. // }
  2422. //
  2423. // // 透前评估
  2424. // for _, assessmentBefore := range assessmentBefores {
  2425. // if scheduals.PatientId == assessmentBefore.PatientId {
  2426. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2427. // break
  2428. // }
  2429. // }
  2430. //
  2431. // // 透析上下机
  2432. // for _, dialysisOrder := range dialysisOrders {
  2433. // if scheduals.PatientId == dialysisOrder.PatientId {
  2434. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2435. // break
  2436. // }
  2437. // }
  2438. //
  2439. // records := make([]*models.MonitoringRecord, 0)
  2440. // // 透析监测
  2441. // for _, it := range monitorlist {
  2442. // records := append(records, it)
  2443. // if scheduals.PatientId == it.PatientId {
  2444. // dialysisSchedule[key].MonitoringRecord = records
  2445. // }
  2446. // }
  2447. //
  2448. // // 透后评估
  2449. // for _, afterDislysis := range AssessmentAfterDislysis {
  2450. // if scheduals.PatientId == afterDislysis.PatientId {
  2451. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2452. // break
  2453. // }
  2454. // }
  2455. //
  2456. // //透析模式
  2457. // for _, treatment := range treatments {
  2458. // if scheduals.ModeId == treatment.ID {
  2459. // dialysisSchedule[key].TreatmentMode = treatment
  2460. // break
  2461. // }
  2462. // }
  2463. // }
  2464. // //获取所有床位号
  2465. // if err == nil {
  2466. // c.ServeSuccessJSON(map[string]interface{}{
  2467. // "schedule": dialysisSchedule,
  2468. // "total": total,
  2469. // })
  2470. // } else {
  2471. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2472. // }
  2473. //
  2474. // } else {
  2475. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2476. // if err == nil {
  2477. // c.ServeSuccessJSON(map[string]interface{}{
  2478. // "schedule": dialysisSchedule,
  2479. // "total": total,
  2480. // })
  2481. // } else {
  2482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. // }
  2484. // }
  2485. //}
  2486. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2487. patientId, _ := c.GetInt64("id", 0)
  2488. record_date, _ := c.GetInt64("record_date", 0)
  2489. adminUserInfo := c.GetAdminUserInfo()
  2490. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2491. var dialysisStatus int64
  2492. if dialysisOrder == nil { //没有透析记录
  2493. dialysisStatus = 0 //未透析
  2494. } else {
  2495. dialysisStatus = dialysisOrder.Stage
  2496. }
  2497. //用户基本信息
  2498. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2499. //接诊评估
  2500. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2501. //透前评估
  2502. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2503. //临时医嘱
  2504. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2505. //双人核对
  2506. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2507. //透析监测
  2508. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2509. //透后评估
  2510. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2511. //透析小结
  2512. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2513. //透析处方
  2514. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2515. if dialysisPrescription.ID == 0 {
  2516. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2517. c.ServeSuccessJSON(map[string]interface{}{
  2518. "patientInfo": schedualPatientInfo,
  2519. "dialysisPrescription": solution,
  2520. "receiverTreatmentAccess": receiverTreatmentAccess,
  2521. "predialysisEvaluation": PredialysisEvaluation,
  2522. "doctorAdvice": DoctorAdvice,
  2523. "doubleCheck": DoubleCheck,
  2524. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2525. "treatmentSummary": TreatmentSummary,
  2526. "monitorRecord": Record,
  2527. "dialysisStatus": dialysisStatus,
  2528. "dialysisOrder": dialysisOrder,
  2529. "isSolution": 1,
  2530. })
  2531. } else {
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "patientInfo": schedualPatientInfo,
  2534. "dialysisPrescription": dialysisPrescription,
  2535. "receiverTreatmentAccess": receiverTreatmentAccess,
  2536. "predialysisEvaluation": PredialysisEvaluation,
  2537. "doctorAdvice": DoctorAdvice,
  2538. "doubleCheck": DoubleCheck,
  2539. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2540. "treatmentSummary": TreatmentSummary,
  2541. "monitorRecord": Record,
  2542. "dialysisStatus": dialysisStatus,
  2543. "dialysisOrder": dialysisOrder,
  2544. "isSolution": 2,
  2545. })
  2546. }
  2547. }
  2548. func (c *DialysisApiController) CreateDoctorAdvice() {
  2549. patient, _ := c.GetInt64("id", 0)
  2550. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2551. record_date, _ := c.GetInt64("record_date", 0)
  2552. if patient <= 0 {
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2554. return
  2555. }
  2556. adminUserInfo := c.GetAdminUserInfo()
  2557. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2558. if patientInfo.ID == 0 {
  2559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2560. return
  2561. }
  2562. var advice models.DoctorAdvice
  2563. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2564. if code > 0 {
  2565. c.ServeFailJSONWithSGJErrorCode(code)
  2566. return
  2567. }
  2568. if advice.ParentId > 0 {
  2569. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2570. if old.ID == 0 || old.PatientId != patient {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2572. return
  2573. }
  2574. if old.StopState == 1 || old.ExecutionState == 1 {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2576. return
  2577. }
  2578. if old.ParentId > 0 {
  2579. advice.ParentId = old.ParentId
  2580. }
  2581. advice.StartTime = old.StartTime
  2582. advice.AdviceDoctor = old.AdviceDoctor
  2583. advice.DeliveryWay = old.DeliveryWay
  2584. advice.ExecutionFrequency = old.ExecutionFrequency
  2585. }
  2586. advice.RecordDate = record_date
  2587. advice.DialysisOrderId = dialysis_id
  2588. advice.Status = 1
  2589. advice.CreatedTime = time.Now().Unix()
  2590. advice.UpdatedTime = time.Now().Unix()
  2591. advice.StopState = 2
  2592. advice.ExecutionState = 2
  2593. advice.AdviceType = 2
  2594. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2595. advice.PatientId = patient
  2596. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2597. err := service.CreateDoctorAdvice(&advice)
  2598. if err != nil {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2600. return
  2601. }
  2602. for _, subAdvice := range subAdivice {
  2603. subAdvice.ParentId = advice.ID
  2604. subAdvice.PatientId = patient
  2605. subAdvice.RecordDate = record_date
  2606. subAdvice.CreatedTime = time.Now().Unix()
  2607. subAdvice.UpdatedTime = time.Now().Unix()
  2608. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2609. }
  2610. service.CreateSubDoctorAdvice(subAdivice)
  2611. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2612. c.ServeSuccessJSON(map[string]interface{}{
  2613. "msg": "ok",
  2614. "advice": advice,
  2615. "subAdvice": subAdivices,
  2616. })
  2617. return
  2618. }
  2619. func (c *DialysisApiController) EditDoctorAdvice() {
  2620. patient, _ := c.GetInt64("patient", 0)
  2621. id, _ := c.GetInt64("id", 0)
  2622. parent_id, _ := c.GetInt64("parent_id", 0)
  2623. execution_time := c.GetString("execution_time")
  2624. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2625. // checker, _ := c.GetInt64("checker", 0)
  2626. if id <= 0 || patient <= 0 {
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2628. return
  2629. }
  2630. adminUserInfo := c.GetAdminUserInfo()
  2631. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2632. if advice.ID == 0 || advice.PatientId != patient {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2634. return
  2635. }
  2636. if len(execution_time) <= 0 {
  2637. utils.ErrorLog("execution_time")
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2639. return
  2640. }
  2641. execution_staff := adminUserInfo.AdminUser.Id
  2642. checker := adminUserInfo.AdminUser.Id
  2643. timeLayout2 := "2006-01-02 15:04"
  2644. loc, _ := time.LoadLocation("Local")
  2645. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2646. if errs != nil {
  2647. utils.ErrorLog(errs.Error())
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. advices := models.DoctorAdvice{
  2652. ExecutionStaff: execution_staff,
  2653. ExecutionTime: theTime.Unix(),
  2654. Checker: checker,
  2655. UpdatedTime: time.Now().Unix(),
  2656. }
  2657. var err error
  2658. if parent_id > 0 {
  2659. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2660. } else {
  2661. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2662. }
  2663. if err != nil {
  2664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2665. return
  2666. }
  2667. c.ServeSuccessJSON(map[string]interface{}{
  2668. "msg": "ok",
  2669. "advice": advice,
  2670. })
  2671. return
  2672. }
  2673. func (c *DialysisApiController) GetDoctorAdvice() {
  2674. patient, _ := c.GetInt64("patient_id", 0)
  2675. parent_id, _ := c.GetInt64("parent_id", 0)
  2676. adviceId, _ := c.GetInt64("id", 0)
  2677. if patient <= 0 {
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. dminUserInfo := c.GetAdminUserInfo()
  2682. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2683. if patientInfo.ID == 0 {
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2685. return
  2686. }
  2687. var subAdvice []*models.DoctorAdvice
  2688. var advice models.DoctorAdvice
  2689. if parent_id > 0 {
  2690. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2691. if advice.ID == 0 || advice.PatientId != patient {
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2693. return
  2694. }
  2695. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2696. } else {
  2697. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2698. if advice.ID == 0 || advice.PatientId != patient {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2700. return
  2701. }
  2702. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2703. }
  2704. c.ServeSuccessJSON(map[string]interface{}{
  2705. "msg": "ok",
  2706. "advice": advice,
  2707. "subAdvice": subAdvice,
  2708. })
  2709. }
  2710. func (this *DialysisApiController) DelMonitor() {
  2711. recordID, _ := this.GetInt64("record_id")
  2712. patientID, _ := this.GetInt64("patient_id")
  2713. if recordID <= 0 || patientID <= 0 {
  2714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2715. return
  2716. }
  2717. adminInfo := this.GetAdminUserInfo()
  2718. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2719. if getPatientErr != nil {
  2720. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. } else if patient == nil {
  2724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2725. return
  2726. }
  2727. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2728. if getMonitorErr != nil {
  2729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. //if monitor != nil {
  2733. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2734. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2735. // if getPermissionErr != nil {
  2736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. // return
  2738. // } else if headNursePermission == nil {
  2739. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2740. // return
  2741. // }
  2742. // }
  2743. //}
  2744. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2745. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2746. redis := service.RedisClient()
  2747. //清空key 值
  2748. redis.Set(key, "", time.Second)
  2749. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2750. redis.Set(keyOne, "", time.Second)
  2751. defer redis.Close()
  2752. if err != nil {
  2753. this.ErrorLog("删除透析监测记录失败:%v", err)
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2755. return
  2756. }
  2757. this.ServeSuccessJSON(map[string]interface{}{
  2758. "record_id": monitor.ID,
  2759. })
  2760. }
  2761. func (c *DialysisApiController) CreateMonitor() {
  2762. patient, _ := c.GetInt64("id", 0)
  2763. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2764. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2765. operate_time, _ := c.GetInt64("operate_time", 0)
  2766. // monitoring_time := c.GetString("monitoring_time")
  2767. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2768. breathing_rated := c.GetString("breathing_rated")
  2769. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2770. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2771. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2772. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2773. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2774. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2775. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2776. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2777. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2778. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2779. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2780. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2781. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2782. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2783. temperature, _ := c.GetFloat("temperature", 0)
  2784. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2785. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2786. conductivity, _ := c.GetFloat("conductivity", 0)
  2787. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2788. heparin, _ := c.GetFloat("heparin", 0)
  2789. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2790. ktv, _ := c.GetFloat("ktv", 0)
  2791. symptom := c.GetString("symptom")
  2792. dispose := c.GetString("dispose")
  2793. result := c.GetString("results")
  2794. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2795. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2796. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2797. monitoring_date = monitoring_date / 1000
  2798. // operate_time = operate_time / 1000
  2799. if patient <= 0 {
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. adminUserInfo := c.GetAdminUserInfo()
  2804. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2805. if patientInfo.ID == 0 {
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2807. return
  2808. }
  2809. monitorRecord := models.MonitoringRecord{
  2810. PatientId: patient,
  2811. MonitoringDate: monitoring_date,
  2812. DialysisOrderId: dialysis_order_id,
  2813. OperateTime: operate_time,
  2814. // MonitoringTime: monitoring_time,
  2815. PulseFrequency: pulse_frequency,
  2816. BreathingRate: breathing_rated,
  2817. SystolicBloodPressure: systolic_blood_pressure,
  2818. DiastolicBloodPressure: diastolic_blood_pressure,
  2819. BloodPressureType: blood_pressure_type,
  2820. BloodFlowVolume: blood_flow_volume,
  2821. VenousPressure: venous_pressure,
  2822. VenousPressureType: venous_pressure_type,
  2823. TransmembranePressure: transmembrane_pressure,
  2824. TransmembranePressureType: transmembrane_pressure_type,
  2825. UltrafiltrationRate: ultrafiltration_rate,
  2826. UltrafiltrationVolume: ultrafiltration_volume,
  2827. SodiumConcentration: sodium_concentration,
  2828. ArterialPressure: arterial_pressure,
  2829. ArterialPressureType: arterial_pressure_type,
  2830. DialysateTemperature: dialysate_temperature,
  2831. Temperature: temperature,
  2832. ReplacementRate: replacement_rate,
  2833. DisplacementQuantity: displacement_quantity,
  2834. Ktv: ktv,
  2835. Symptom: symptom,
  2836. Dispose: dispose,
  2837. Result: result,
  2838. MonitoringNurse: monitoring_nurse,
  2839. Status: 1,
  2840. CreatedTime: time.Now().Unix(),
  2841. UpdatedTime: time.Now().Unix(),
  2842. UserOrgId: adminUserInfo.CurrentOrgId,
  2843. Conductivity: conductivity,
  2844. DisplacementFlowQuantity: displacement_flow_quantity,
  2845. Heparin: heparin,
  2846. DialysateFlow: dialysate_flow,
  2847. MonitorAnticoagulant: monitor_anticoagulant,
  2848. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2849. }
  2850. err := service.CreateMonitor(&monitorRecord)
  2851. redis := service.RedisClient()
  2852. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2853. redis.Set(key, "", time.Second)
  2854. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2855. redis.Set(keyOne, "", time.Second)
  2856. redis.Close()
  2857. if err != nil {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2859. return
  2860. }
  2861. c.ServeSuccessJSON(map[string]interface{}{
  2862. "msg": "ok",
  2863. "monitor": monitorRecord,
  2864. })
  2865. return
  2866. }
  2867. // 已弃用
  2868. // func (c *DialysisApiController) CreateRecordData() {
  2869. // patient, _ := c.GetInt64("id", 0)
  2870. // status, _ := c.GetInt64("status", 0)
  2871. // now := time.Now()
  2872. // year, month, day := now.Date()
  2873. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2874. // todayTimeStamp := today_time.Unix()
  2875. // if patient <= 0 {
  2876. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2877. // return
  2878. // }
  2879. // adminUserInfo := c.GetAdminUserInfo()
  2880. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2881. // if patientInfo.ID == 0 {
  2882. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2883. // return
  2884. // }
  2885. // record := &models.DialysisOrder{
  2886. // DialysisDate: todayTimeStamp,
  2887. // UserOrgId: adminUserInfo.CurrentOrgId,
  2888. // PatientId: patient,
  2889. // Stage: status,
  2890. // Status: 1,
  2891. // CreatedTime: time.Now().Unix(),
  2892. // UpdatedTime: time.Now().Unix(),
  2893. // }
  2894. // if status == 1 {
  2895. // //创建透析记录
  2896. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2897. // if err == nil {
  2898. // c.ServeSuccessJSON(map[string]interface{}{
  2899. // "dialysisOrder": record,
  2900. // })
  2901. // } else {
  2902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2903. // }
  2904. // } else {
  2905. // record_id, _ := c.GetInt64("record_id", 0)
  2906. // //修改透析记录状态
  2907. // errs := service.ModifyDialysisRecord(record_id)
  2908. // //结束时候透析次数加1
  2909. // service.UpdateSolutionByPatientId(patient)
  2910. // if errs == nil {
  2911. // c.ServeSuccessJSON(map[string]interface{}{
  2912. // "dialysisOrder": record,
  2913. // })
  2914. // } else {
  2915. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2916. // }
  2917. // }
  2918. // }
  2919. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2920. dataBody := make(map[string]interface{}, 0)
  2921. err := json.Unmarshal(data, &dataBody)
  2922. if err != nil {
  2923. utils.ErrorLog(err.Error())
  2924. code = enums.ErrorCodeParamWrong
  2925. return
  2926. }
  2927. timeLayout := "2006-01-02 "
  2928. timeLayout2 := "2006-01-02 15:04"
  2929. loc, _ := time.LoadLocation("Local")
  2930. if action == "create" {
  2931. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2932. utils.ErrorLog("advice_type")
  2933. code = enums.ErrorCodeParamWrong
  2934. return
  2935. }
  2936. adviceType := int64(dataBody["advice_type"].(float64))
  2937. if adviceType != 1 && adviceType != 2 {
  2938. utils.ErrorLog("advice_type != 1&&2")
  2939. code = enums.ErrorCodeParamWrong
  2940. return
  2941. }
  2942. advice.AdviceType = adviceType
  2943. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2944. utils.ErrorLog("advice_date")
  2945. code = enums.ErrorCodeParamWrong
  2946. return
  2947. }
  2948. adviceDate, _ := dataBody["advice_date"].(string)
  2949. if len(adviceDate) == 0 {
  2950. utils.ErrorLog("len(adviceDate) == 0")
  2951. code = enums.ErrorCodeParamWrong
  2952. return
  2953. }
  2954. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2955. if err != nil {
  2956. utils.ErrorLog(err.Error())
  2957. code = enums.ErrorCodeParamWrong
  2958. return
  2959. }
  2960. advice.AdviceDate = theTime.Unix()
  2961. }
  2962. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2963. utils.ErrorLog("start_time")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. startDate, _ := dataBody["start_time"].(string)
  2968. if len(startDate) == 0 {
  2969. utils.ErrorLog("len(startDate) == 0")
  2970. code = enums.ErrorCodeParamWrong
  2971. return
  2972. }
  2973. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2974. if err != nil {
  2975. utils.ErrorLog(err.Error())
  2976. code = enums.ErrorCodeParamWrong
  2977. return
  2978. }
  2979. advice.StartTime = theTime.Unix()
  2980. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2981. utils.ErrorLog("advice_name")
  2982. code = enums.ErrorCodeParamWrong
  2983. return
  2984. }
  2985. adviceName, _ := dataBody["advice_name"].(string)
  2986. if len(adviceName) == 0 {
  2987. utils.ErrorLog("len(advice_name) == 0")
  2988. code = enums.ErrorCodeParamWrong
  2989. return
  2990. }
  2991. advice.AdviceName = adviceName
  2992. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2993. utils.ErrorLog("delivery_way")
  2994. code = enums.ErrorCodeParamWrong
  2995. return
  2996. }
  2997. deliveryWay, _ := dataBody["delivery_way"].(string)
  2998. if len(deliveryWay) == 0 {
  2999. utils.ErrorLog("len(deliveryWay) == 0")
  3000. code = enums.ErrorCodeParamWrong
  3001. return
  3002. }
  3003. advice.DeliveryWay = deliveryWay
  3004. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3005. utils.ErrorLog("execution_frequency")
  3006. code = enums.ErrorCodeParamWrong
  3007. return
  3008. }
  3009. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3010. if len(execution_frequency) == 0 {
  3011. utils.ErrorLog("len(execution_frequency) == 0")
  3012. code = enums.ErrorCodeParamWrong
  3013. return
  3014. }
  3015. advice.ExecutionFrequency = execution_frequency
  3016. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3017. adviceDsc, _ := dataBody["advice_desc"].(string)
  3018. advice.AdviceDesc = adviceDsc
  3019. }
  3020. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3021. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3022. advice.DrugSpecUnit = drugSpecUnit
  3023. }
  3024. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3025. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3026. advice.SingleDose = singleDose
  3027. }
  3028. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3029. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3030. advice.SingleDoseUnit = singleDoseUnit
  3031. }
  3032. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3033. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3034. advice.PrescribingNumber = prescribingNumber
  3035. }
  3036. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3037. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3038. advice.PrescribingNumberUnit = prescribingNumberUnit
  3039. }
  3040. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3041. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3042. if len(thisContagions) > 0 {
  3043. for _, item := range thisContagions {
  3044. items := item.(map[string]interface{})
  3045. advice_name, _ := items["advice_name"].(string)
  3046. advice_desc, _ := items["advice_desc"].(string)
  3047. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3048. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3049. single_dose_unit, _ := items["single_dose_unit"].(string)
  3050. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3051. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3052. advice := &models.DoctorAdvice{
  3053. AdviceName: advice_name,
  3054. AdviceDesc: advice_desc,
  3055. SingleDose: single_dose,
  3056. SingleDoseUnit: single_dose_unit,
  3057. DrugSpecUnit: drug_spec_unit,
  3058. PrescribingNumber: prescribing_number,
  3059. PrescribingNumberUnit: prescribing_number_unit,
  3060. }
  3061. subAdvice = append(subAdvice, advice)
  3062. }
  3063. }
  3064. }
  3065. return
  3066. }
  3067. func (c *DialysisApiController) GetDialysisOrder() {
  3068. xtno := c.GetString("xtno")
  3069. xtdate := c.GetString("xtdate")
  3070. timeLayout := "2006-01-02"
  3071. loc, _ := time.LoadLocation("Local")
  3072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3073. if err != nil {
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3075. return
  3076. }
  3077. xttime := theTime.Unix()
  3078. operatorIDs := make([]int64, 0)
  3079. adminUserInfo := c.GetAdminUserInfo()
  3080. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3081. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3082. //透析单
  3083. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3084. if dialysisOrder != nil {
  3085. if dialysisOrder.FinishNurse > 0 {
  3086. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3087. }
  3088. if dialysisOrder.StartNurse > 0 {
  3089. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3090. }
  3091. }
  3092. //透前评估
  3093. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3094. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3095. //透后评估
  3096. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3097. if AssessmentAfterDislysis.Modifier > 0 {
  3098. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3099. }
  3100. //上次透前评估
  3101. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3102. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3103. //透析处方
  3104. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3105. if dialysisPrescription.PrescriptionDoctor > 0 {
  3106. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3107. }
  3108. //获取病人的透析模式
  3109. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3110. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3111. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3112. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3113. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3114. //获取透析处方
  3115. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3116. //获取临时医嘱
  3117. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3118. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3119. //获取医嘱内容
  3120. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3121. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3122. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3123. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3124. //获取上次的透后体重
  3125. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3126. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3127. //获取透析次数
  3128. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3129. if len(DoctorAdvice) > 0 {
  3130. for _, item := range DoctorAdvice {
  3131. if item.AdviceDoctor > 0 {
  3132. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3133. }
  3134. if item.ExecutionStaff > 0 {
  3135. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3136. }
  3137. if item.Checker > 0 {
  3138. operatorIDs = append(operatorIDs, item.Checker)
  3139. }
  3140. }
  3141. }
  3142. //透析监测
  3143. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3144. //透析检测
  3145. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3146. //透析小结
  3147. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3148. //接诊评估
  3149. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3150. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3151. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3152. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3153. patientInfo.TotalDialysis = dialysis_count
  3154. }
  3155. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3156. if xttime <= 1672416000 {
  3157. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3158. patientInfo.TotalDialysis = dialysis_count
  3159. }
  3160. if xttime >= 1672502400 {
  3161. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3162. patientInfo.TotalDialysis = dialysis_count
  3163. }
  3164. }
  3165. //相关操作对应的操作人
  3166. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3167. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3168. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3169. //获取当前日期月份的第一天
  3170. firstmonth := service.GetFirstDateOfMonth(theTime)
  3171. firstMonthDate := firstmonth.Unix()
  3172. //获取当前月份的病人透析次数
  3173. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3174. //获取his数据
  3175. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3176. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3177. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3178. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3179. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3180. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3181. // for _, item := range projects {
  3182. // var advice *models.HisDoctorAdviceInfo
  3183. // advice.ID = item.ID
  3184. // advice.Checker = item.Checker
  3185. // advice.CheckTime = item.CheckTime
  3186. // advice.CheckState = item.CheckState
  3187. // advice.ExecutionState = item.ExecutionState
  3188. // advice.ExecutionStaff = item.ExecutionStaff
  3189. // advice.PrescribingNumber = float64(item.Count)
  3190. // advice.PrescribingNumberUnit = item.Unit
  3191. // advice.AdviceDoctor = item.Doctor
  3192. // if item.Type == 3 {
  3193. // advice.AdviceName = item.GoodInfo.GoodName
  3194. // } else if item.Type == 2 {
  3195. // advice.AdviceName = item.HisProject.ProjectName
  3196. // }
  3197. // advice.StartTime = item.StartTime
  3198. // hisAdvice = append(hisAdvice, advice)
  3199. // }
  3200. //}
  3201. if config.IsOpen == 1 {
  3202. c.ServeSuccessJSON(map[string]interface{}{
  3203. "xtdate": xtdate,
  3204. "users": adminUser,
  3205. "patientInfo": patientInfo,
  3206. "PredialysisEvaluation": PredialysisEvaluation,
  3207. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3208. "dialysisPrescription": dialysisPrescription,
  3209. "advices": hisAdvice,
  3210. "monitors": Record,
  3211. "summary": TreatmentSummary,
  3212. "receiverTreatmentAccess": receiverTreatmentAccess,
  3213. "dialysisOrder": dialysisOrder,
  3214. "operators": operators,
  3215. "org_template_info": templateInfo,
  3216. "check": check,
  3217. "schedule": schedule,
  3218. "dialysisway": dialysisway,
  3219. "order": order,
  3220. "doctorAdvice": doctorAdvice,
  3221. "doctor": doctor,
  3222. "nurse": nurse,
  3223. "doctorAdevieInfo": doctorAdevieInfo,
  3224. "total": total,
  3225. "startNuse": startNuse,
  3226. "DoctorName": DoctorName,
  3227. "assessmentAfterDislysis": assessmentAfterDislysis,
  3228. "predialysName": predialysName,
  3229. "FinishNuse": FinishNuse,
  3230. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3231. "dialysiscount": dialysiscount,
  3232. "last_order": lastOrder,
  3233. "project_config": project_config,
  3234. "projects": projects,
  3235. })
  3236. }
  3237. if config.IsOpen == 0 || config.IsOpen == 2 {
  3238. c.ServeSuccessJSON(map[string]interface{}{
  3239. "xtdate": xtdate,
  3240. "users": adminUser,
  3241. "patientInfo": patientInfo,
  3242. "PredialysisEvaluation": PredialysisEvaluation,
  3243. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3244. "dialysisPrescription": dialysisPrescription,
  3245. "advices": DoctorAdvice,
  3246. "monitors": Record,
  3247. "summary": TreatmentSummary,
  3248. "receiverTreatmentAccess": receiverTreatmentAccess,
  3249. "dialysisOrder": dialysisOrder,
  3250. "operators": operators,
  3251. "org_template_info": templateInfo,
  3252. "check": check,
  3253. "schedule": schedule,
  3254. "dialysisway": dialysisway,
  3255. "order": order,
  3256. "doctorAdvice": doctorAdvice,
  3257. "doctor": doctor,
  3258. "nurse": nurse,
  3259. "doctorAdevieInfo": doctorAdevieInfo,
  3260. "total": total,
  3261. "startNuse": startNuse,
  3262. "DoctorName": DoctorName,
  3263. "assessmentAfterDislysis": assessmentAfterDislysis,
  3264. "predialysName": predialysName,
  3265. "FinishNuse": FinishNuse,
  3266. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3267. "dialysiscount": dialysiscount,
  3268. "last_order": lastOrder,
  3269. "project_config": project_config,
  3270. "projects": projects,
  3271. })
  3272. }
  3273. }
  3274. func (c *DialysisApiController) GetLongAdvice() {
  3275. patient_id, _ := c.GetInt64("patient_id")
  3276. adminUserInfo := c.GetAdminUserInfo()
  3277. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3278. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3279. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3280. c.ServeSuccessJSON(map[string]interface{}{
  3281. "status": "1",
  3282. })
  3283. return
  3284. } else { //开启推送提醒
  3285. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3286. var advice_three []*models.DoctorAdvice
  3287. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3288. recordDateStr := time.Now().Format("2006-01-02")
  3289. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3290. nowtime := recordDate.Unix()
  3291. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3292. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3293. for _, advice := range advices {
  3294. if advice.FrequencyType == 3 {
  3295. t := time.Now()
  3296. week := int(t.Weekday())
  3297. switch week {
  3298. case 1:
  3299. if strings.Index(advice.WeekDay, "周一") == -1 {
  3300. advice_three = append(advice_three, advice)
  3301. }
  3302. break
  3303. case 2:
  3304. if strings.Index(advice.WeekDay, "周二") == -1 {
  3305. advice_three = append(advice_three, advice)
  3306. }
  3307. break
  3308. case 3:
  3309. if strings.Index(advice.WeekDay, "周三") == -1 {
  3310. advice_three = append(advice_three, advice)
  3311. }
  3312. break
  3313. case 4:
  3314. if strings.Index(advice.WeekDay, "周四") == -1 {
  3315. advice_three = append(advice_three, advice)
  3316. }
  3317. break
  3318. case 5:
  3319. if strings.Index(advice.WeekDay, "周五") == -1 {
  3320. advice_three = append(advice_three, advice)
  3321. }
  3322. break
  3323. case 6:
  3324. if strings.Index(advice.WeekDay, "周六") == -1 {
  3325. advice_three = append(advice_three, advice)
  3326. }
  3327. break
  3328. case 0:
  3329. if strings.Index(advice.WeekDay, "周日") == -1 {
  3330. advice_three = append(advice_three, advice)
  3331. }
  3332. break
  3333. }
  3334. }
  3335. }
  3336. for _, advice := range advices_two {
  3337. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3338. now := p.Unix()
  3339. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3340. dayStr2 := "-" + dayStr
  3341. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3342. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3343. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3344. for _, ad := range advices {
  3345. advice_three = append(advice_three, ad)
  3346. }
  3347. }
  3348. if err == nil {
  3349. c.ServeSuccessJSON(map[string]interface{}{
  3350. "status": "2",
  3351. "advices": advices,
  3352. "advices_two": RemoveRepeatedElement(advice_three),
  3353. "is_open_remind": config.IsOpenRemind,
  3354. })
  3355. }
  3356. }
  3357. }
  3358. func (c *DialysisApiController) GetLongAdviceOne() {
  3359. patient_id, _ := c.GetInt64("patient_id")
  3360. schedule_date := c.GetString("schedule_date")
  3361. adminUserInfo := c.GetAdminUserInfo()
  3362. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3363. timeLayout := "2006-01-02"
  3364. loc, _ := time.LoadLocation("Local")
  3365. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3366. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3367. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3368. c.ServeSuccessJSON(map[string]interface{}{
  3369. "status": "1",
  3370. })
  3371. return
  3372. } else { //开启推送提醒
  3373. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3374. var advice_three []*models.DoctorAdvice
  3375. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3376. //recordDateStr := time.Now().Format("2006-01-02")
  3377. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3378. //
  3379. //nowtime := recordDate.Unix()
  3380. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3381. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3382. for _, advice := range advices {
  3383. if advice.FrequencyType == 3 {
  3384. t := time.Now()
  3385. week := int(t.Weekday())
  3386. switch week {
  3387. case 1:
  3388. if strings.Index(advice.WeekDay, "周一") == -1 {
  3389. advice_three = append(advice_three, advice)
  3390. }
  3391. break
  3392. case 2:
  3393. if strings.Index(advice.WeekDay, "周二") == -1 {
  3394. advice_three = append(advice_three, advice)
  3395. }
  3396. break
  3397. case 3:
  3398. if strings.Index(advice.WeekDay, "周三") == -1 {
  3399. advice_three = append(advice_three, advice)
  3400. }
  3401. break
  3402. case 4:
  3403. if strings.Index(advice.WeekDay, "周四") == -1 {
  3404. advice_three = append(advice_three, advice)
  3405. }
  3406. break
  3407. case 5:
  3408. if strings.Index(advice.WeekDay, "周五") == -1 {
  3409. advice_three = append(advice_three, advice)
  3410. }
  3411. break
  3412. case 6:
  3413. if strings.Index(advice.WeekDay, "周六") == -1 {
  3414. advice_three = append(advice_three, advice)
  3415. }
  3416. break
  3417. case 0:
  3418. if strings.Index(advice.WeekDay, "周日") == -1 {
  3419. advice_three = append(advice_three, advice)
  3420. }
  3421. break
  3422. }
  3423. }
  3424. }
  3425. for _, advice := range advices_two {
  3426. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3427. now := p.Unix()
  3428. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3429. dayStr2 := "-" + dayStr
  3430. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3431. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3432. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3433. for _, ad := range advices {
  3434. advice_three = append(advice_three, ad)
  3435. }
  3436. }
  3437. if err == nil {
  3438. c.ServeSuccessJSON(map[string]interface{}{
  3439. "status": "2",
  3440. "advices": advices,
  3441. "advices_two": RemoveRepeatedElement(advice_three),
  3442. "is_open_remind": config.IsOpenRemind,
  3443. })
  3444. }
  3445. }
  3446. }
  3447. func (c *DialysisApiController) GetLongAdviceTwo() {
  3448. patient_id, _ := c.GetInt64("patient_id")
  3449. schedule_date, _ := c.GetInt64("schedule_date")
  3450. adminUserInfo := c.GetAdminUserInfo()
  3451. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3452. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3453. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3454. c.ServeSuccessJSON(map[string]interface{}{
  3455. "status": "1",
  3456. })
  3457. return
  3458. } else { //开启推送提醒
  3459. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3460. var advice_three []*models.DoctorAdvice
  3461. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3462. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3463. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3464. for _, advice := range advices {
  3465. if advice.FrequencyType == 3 {
  3466. t := time.Now()
  3467. week := int(t.Weekday())
  3468. switch week {
  3469. case 1:
  3470. if strings.Index(advice.WeekDay, "周一") == -1 {
  3471. advice_three = append(advice_three, advice)
  3472. }
  3473. break
  3474. case 2:
  3475. if strings.Index(advice.WeekDay, "周二") == -1 {
  3476. advice_three = append(advice_three, advice)
  3477. }
  3478. break
  3479. case 3:
  3480. if strings.Index(advice.WeekDay, "周三") == -1 {
  3481. advice_three = append(advice_three, advice)
  3482. }
  3483. break
  3484. case 4:
  3485. if strings.Index(advice.WeekDay, "周四") == -1 {
  3486. advice_three = append(advice_three, advice)
  3487. }
  3488. break
  3489. case 5:
  3490. if strings.Index(advice.WeekDay, "周五") == -1 {
  3491. advice_three = append(advice_three, advice)
  3492. }
  3493. break
  3494. case 6:
  3495. if strings.Index(advice.WeekDay, "周六") == -1 {
  3496. advice_three = append(advice_three, advice)
  3497. }
  3498. break
  3499. case 0:
  3500. if strings.Index(advice.WeekDay, "周日") == -1 {
  3501. advice_three = append(advice_three, advice)
  3502. }
  3503. break
  3504. }
  3505. }
  3506. }
  3507. for _, advice := range advices_two {
  3508. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3509. now := p.Unix()
  3510. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3511. dayStr2 := "-" + dayStr
  3512. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3513. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3514. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3515. for _, ad := range advices {
  3516. advice_three = append(advice_three, ad)
  3517. }
  3518. }
  3519. if err == nil {
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "status": "2",
  3522. "advices": advices,
  3523. "advices_two": RemoveRepeatedElement(advice_three),
  3524. "is_open_remind": config.IsOpenRemind,
  3525. })
  3526. }
  3527. }
  3528. }
  3529. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3530. newArr = make([]*models.DoctorAdvice, 0)
  3531. for i := 0; i < len(arr); i++ {
  3532. repeat := false
  3533. for j := i + 1; j < len(arr); j++ {
  3534. if arr[i].ID == arr[j].ID {
  3535. repeat = true
  3536. break
  3537. }
  3538. }
  3539. if !repeat {
  3540. newArr = append(newArr, arr[i])
  3541. }
  3542. }
  3543. return
  3544. }
  3545. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3546. patient, _ := c.GetInt64("id", 0)
  3547. groupNo, _ := c.GetInt64("groupno", 0)
  3548. if patient <= 0 {
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. adminUserInfo := c.GetAdminUserInfo()
  3553. dataBody := make(map[string]interface{}, 0)
  3554. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3555. if err != nil {
  3556. utils.ErrorLog(err.Error())
  3557. return
  3558. }
  3559. utils.ErrorLog("%v", dataBody)
  3560. timeLayout := "2006-01-02 15:04"
  3561. loc, _ := time.LoadLocation("Local")
  3562. timeLayout2 := "2006-01-02"
  3563. loc2, _ := time.LoadLocation("Local")
  3564. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3565. utils.ErrorLog("advice_type")
  3566. return
  3567. }
  3568. adviceType := int64(2)
  3569. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3570. utils.ErrorLog("advice_date")
  3571. return
  3572. }
  3573. adviceDate, _ := dataBody["advice_date"].(string)
  3574. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3575. AdviceDate := theTime.Unix()
  3576. RecordDate := theTime.Unix()
  3577. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3578. utils.ErrorLog("start_time")
  3579. return
  3580. }
  3581. startTime, _ := dataBody["start_time"].(string)
  3582. if len(startTime) == 0 {
  3583. utils.ErrorLog("len(start_time) == 0")
  3584. return
  3585. }
  3586. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3587. if err != nil {
  3588. utils.ErrorLog(err.Error())
  3589. return
  3590. }
  3591. StartTime := theTimeUnix.Unix()
  3592. fmt.Println("startTIME", StartTime)
  3593. Remark := ""
  3594. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3595. remark, _ := dataBody["remark"].(string)
  3596. Remark = remark
  3597. }
  3598. var advices []*models.GroupAdvice
  3599. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3600. utils.ErrorLog("advices")
  3601. return
  3602. }
  3603. adviceNames := dataBody["advices"].([]interface{})
  3604. for _, adviceNameMap := range adviceNames {
  3605. adviceNameM := adviceNameMap.(map[string]interface{})
  3606. var advice models.GroupAdvice
  3607. advice.Remark = Remark
  3608. advice.AdviceType = adviceType
  3609. advice.StartTime = StartTime
  3610. advice.AdviceDate = AdviceDate
  3611. advice.RecordDate = RecordDate
  3612. advice.Status = 1
  3613. advice.CreatedTime = time.Now().Unix()
  3614. advice.UpdatedTime = time.Now().Unix()
  3615. advice.StopState = 2
  3616. advice.ExecutionState = 2
  3617. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3618. advice.PatientId = patient
  3619. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3620. advice.IsSettle = 2
  3621. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3622. utils.ErrorLog("advice_name")
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. adviceName, _ := adviceNameM["advice_name"].(string)
  3627. if len(adviceName) == 0 {
  3628. utils.ErrorLog("len(advice_name) == 0")
  3629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3630. return
  3631. }
  3632. advice.AdviceName = adviceName
  3633. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3634. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3635. advice.DrugSpec = drugSpec
  3636. }
  3637. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3638. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3639. advice.AdviceDesc = adviceDesc
  3640. }
  3641. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3642. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3643. advice.DrugSpecUnit = drugSpecUnit
  3644. }
  3645. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3646. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3647. // advice.SingleDose = singleDose
  3648. //}
  3649. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3650. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3651. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3652. }
  3653. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3654. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3655. advice.SingleDoseUnit = singleDoseUnit
  3656. }
  3657. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3658. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3659. // advice.PrescribingNumber = prescribingNumber
  3660. //}
  3661. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3662. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3663. }
  3664. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3665. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3666. advice.PrescribingNumberUnit = prescribingNumberUnit
  3667. }
  3668. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3669. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3670. advice.DeliveryWay = deliveryWay
  3671. }
  3672. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3673. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3674. advice.ExecutionFrequency = executionFrequency
  3675. }
  3676. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3677. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3678. advice.FrequencyType = frequency_type
  3679. }
  3680. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3681. day_count := int64(adviceNameM["day_count"].(float64))
  3682. advice.DayCount = day_count
  3683. }
  3684. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3685. way := int64(adviceNameM["way"].(float64))
  3686. advice.Way = way
  3687. }
  3688. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3689. drug_id := int64(adviceNameM["drug_id"].(float64))
  3690. advice.DrugId = drug_id
  3691. }
  3692. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3693. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3694. advice.DrugNameId = drug_name_id
  3695. }
  3696. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3697. week_day, _ := adviceNameM["week_day"].(string)
  3698. advice.WeekDay = week_day
  3699. }
  3700. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3701. template_id, _ := adviceNameM["template_id"].(string)
  3702. advice.TemplateId = template_id
  3703. }
  3704. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3705. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3706. advice.ExecutionFrequency = executionFrequency
  3707. }
  3708. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3709. children := adviceNameM["child"].([]interface{})
  3710. if len(children) > 0 {
  3711. for _, childrenMap := range children {
  3712. childMap := childrenMap.(map[string]interface{})
  3713. var child models.GroupAdvice
  3714. child.Remark = Remark
  3715. child.AdviceType = adviceType
  3716. child.StartTime = StartTime
  3717. child.AdviceDate = AdviceDate
  3718. child.RecordDate = RecordDate
  3719. child.Status = 1
  3720. child.CreatedTime = time.Now().Unix()
  3721. child.UpdatedTime = time.Now().Unix()
  3722. child.StopState = 2
  3723. child.ExecutionState = 2
  3724. child.UserOrgId = adminUserInfo.CurrentOrgId
  3725. child.PatientId = patient
  3726. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3727. child.IsSettle = 2
  3728. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3729. utils.ErrorLog("child advice_name")
  3730. return
  3731. }
  3732. childAdviceName, _ := childMap["advice_name"].(string)
  3733. if len(childAdviceName) == 0 {
  3734. utils.ErrorLog("len(child advice_name) == 0")
  3735. return
  3736. }
  3737. child.AdviceName = childAdviceName
  3738. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3739. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3740. child.AdviceDesc = childAdviceDesc
  3741. }
  3742. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3743. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3744. child.DrugSpec = childDrugSpec
  3745. }
  3746. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3747. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3748. child.DrugSpecUnit = childDrugSpecUnit
  3749. }
  3750. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3751. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3752. child.SingleDose = childSingleDose
  3753. }
  3754. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3755. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3756. child.SingleDose = childMap["single_dose"].(float64)
  3757. }
  3758. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3759. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3760. child.Remark = childMap["remark"].(string)
  3761. }
  3762. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3763. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3764. child.DrugId = int64(childMap["drug_id"].(float64))
  3765. }
  3766. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3767. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3768. child.SingleDoseUnit = childSingleDoseUnit
  3769. }
  3770. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3771. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3772. child.PrescribingNumber = childPrescribingNumber
  3773. }
  3774. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3775. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3776. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3777. }
  3778. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3779. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3780. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3781. }
  3782. child.DeliveryWay = advice.DeliveryWay
  3783. child.ExecutionFrequency = advice.ExecutionFrequency
  3784. advice.Children = append(advice.Children, &child)
  3785. }
  3786. }
  3787. }
  3788. advices = append(advices, &advice)
  3789. }
  3790. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3791. redis := service.RedisClient()
  3792. formatAdviceDate := theTime.Format("2006-01-02")
  3793. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3794. redis.Set(key, "", time.Second)
  3795. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3796. redis.Set(keyOne, "", time.Second)
  3797. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3798. redis.Set(keyFour, "", time.Second)
  3799. defer redis.Close()
  3800. if err != nil {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3802. return
  3803. }
  3804. c.ServeSuccessJSON(map[string]interface{}{
  3805. "msg": "ok",
  3806. "advices": list,
  3807. })
  3808. return
  3809. }
  3810. func (c *DialysisApiController) GetSolution() {
  3811. patient_id, _ := c.GetInt64("patient_id")
  3812. mode_id, _ := c.GetInt64("mode_id")
  3813. adminUserInfo := c.GetAdminUserInfo()
  3814. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3815. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3816. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3817. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  3818. if err != nil {
  3819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3820. return
  3821. }
  3822. c.ServeSuccessJSON(map[string]interface{}{
  3823. "solution": solution,
  3824. "prescription": prescription,
  3825. "system_prescription": system_prescription,
  3826. "dialysisPrescription": dialysisPrescription,
  3827. })
  3828. }
  3829. func (c *DialysisApiController) GetSchedule() {
  3830. schedual_type, _ := c.GetInt64("schedual_type")
  3831. adminUserInfo := c.GetAdminUserInfo()
  3832. //timeLayout := "2006-01-02 15:04:05"
  3833. //
  3834. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3835. //loc, _ := time.LoadLocation("Local")
  3836. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3837. //scheduleTime := theStartTime.Unix()
  3838. scheduleTime, _ := c.GetInt64("record_date")
  3839. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3840. c.ServeSuccessJSON(map[string]interface{}{
  3841. "number": deviceNumber,
  3842. })
  3843. }
  3844. func (this *DialysisApiController) GetTodayMonitor() {
  3845. thisTime := time.Now()
  3846. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3847. timeLayout := "2006-01-02 15:04:05"
  3848. loc, _ := time.LoadLocation("Local")
  3849. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3850. theAssessmentDateTime := theStartTime.Unix()
  3851. patientID, _ := this.GetInt64("patient_id")
  3852. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3853. adminInfo := this.GetAdminUserInfo()
  3854. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3855. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3856. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3857. var ultrafiltration_rate float64
  3858. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3859. //针对福建医师汇 获取透前评估预增脱水量
  3860. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3861. fmt.Println("透前评估数据", evaluation)
  3862. if prescription.ID > 0 {
  3863. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3864. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3865. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3867. record.UltrafiltrationRate = ultrafiltration_rate
  3868. }
  3869. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3870. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3871. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3872. record.UltrafiltrationRate = ultrafiltration_rate
  3873. }
  3874. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3875. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3876. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3877. record.UltrafiltrationRate = ultrafiltration_rate
  3878. }
  3879. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3880. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3881. record.UltrafiltrationRate = ultrafiltration_rate
  3882. }
  3883. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3884. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3885. record.UltrafiltrationRate = ultrafiltration_rate
  3886. }
  3887. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3888. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3889. record.UltrafiltrationRate = ultrafiltration_rate
  3890. }
  3891. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3892. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3893. record.UltrafiltrationRate = ultrafiltration_rate
  3894. }
  3895. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3896. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3897. record.UltrafiltrationRate = ultrafiltration_rate
  3898. }
  3899. // 只针对方济医院
  3900. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3901. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3902. ultrafiltration_rate = value
  3903. record.UltrafiltrationRate = ultrafiltration_rate
  3904. }
  3905. //长沙南雅
  3906. 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 || adminInfo.CurrentOrgId == 10471 {
  3907. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3908. record.UltrafiltrationRate = ultrafiltration_rate
  3909. }
  3910. }
  3911. }
  3912. // record.UltrafiltrationRate = ultrafiltration_rate
  3913. record.UltrafiltrationVolume = 0
  3914. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3915. if ultrafiltration_rate > 0 {
  3916. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3917. record.UltrafiltrationVolume = value
  3918. }
  3919. }
  3920. 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 {
  3921. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3922. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3923. record.UltrafiltrationVolume = ultrafiltration_volume
  3924. }
  3925. }
  3926. //长沙南雅
  3927. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  3928. if ultrafiltration_rate > 0 {
  3929. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3930. record.UltrafiltrationVolume = ultrafiltration_volume
  3931. }
  3932. }
  3933. if template.TemplateId == 47 || template.TemplateId == 54 {
  3934. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3935. }
  3936. this.ServeSuccessJSON(map[string]interface{}{
  3937. "monitor": record,
  3938. })
  3939. }
  3940. func (c *DialysisApiController) UploadDryWeight() {
  3941. patient_id, _ := c.GetInt64("id")
  3942. dry_weight, _ := c.GetFloat("dry_weight")
  3943. doctor_id, _ := c.GetInt64("doctor_id")
  3944. remark := c.GetString("remark")
  3945. adminUserInfo := c.GetAdminUserInfo()
  3946. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3947. fmt.Println(err)
  3948. if err == gorm.ErrRecordNotFound {
  3949. dryWeight := &models.SgjPatientDryweight{
  3950. PatientId: patient_id,
  3951. DryWeight: dry_weight,
  3952. Remakes: remark,
  3953. Ctime: time.Now().Unix(),
  3954. Mtime: time.Now().Unix(),
  3955. Creator: doctor_id,
  3956. Status: 1,
  3957. UserOrgId: adminUserInfo.CurrentOrgId,
  3958. AdjustedValue: "/",
  3959. UserId: adminUserInfo.AdminUser.Id,
  3960. }
  3961. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3962. loc, _ := time.LoadLocation("Local")
  3963. nowTime := time.Now()
  3964. nowDay := nowTime.Format("2006-01-02")
  3965. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3966. redis := service.RedisClient()
  3967. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3968. redis.Set(keyOne, "", time.Second)
  3969. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3970. redis.Set(key, "", time.Second)
  3971. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3972. redis.Set(keyTwo, "", time.Second)
  3973. redis.Close()
  3974. if createErr == nil {
  3975. c.ServeSuccessJSON(map[string]interface{}{
  3976. "msg": "提交成功",
  3977. "weight": dryWeight,
  3978. })
  3979. }
  3980. } else {
  3981. dryWeight := &models.SgjPatientDryweight{
  3982. PatientId: patient_id,
  3983. DryWeight: dry_weight,
  3984. Remakes: remark,
  3985. Ctime: time.Now().Unix(),
  3986. Mtime: time.Now().Unix(),
  3987. Creator: doctor_id,
  3988. Status: 1,
  3989. UserOrgId: adminUserInfo.CurrentOrgId,
  3990. AdjustedValue: "/",
  3991. UserId: adminUserInfo.AdminUser.Id,
  3992. }
  3993. var value float64
  3994. value = dry_weight - weightAdjust.DryWeight
  3995. fmt.Println(value)
  3996. if value < 0 {
  3997. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3998. } else if value == 0 {
  3999. dryWeight.AdjustedValue = "/"
  4000. } else if value > 0 {
  4001. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4002. }
  4003. fmt.Println(value)
  4004. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4005. loc, _ := time.LoadLocation("Local")
  4006. nowTime := time.Now()
  4007. nowDay := nowTime.Format("2006-01-02")
  4008. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4009. redis := service.RedisClient()
  4010. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4011. redis.Set(keyOne, "", time.Second)
  4012. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4013. redis.Set(key, "", time.Second)
  4014. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4015. redis.Set(keyTwo, "", time.Second)
  4016. redis.Close()
  4017. if createErr == nil {
  4018. c.ServeSuccessJSON(map[string]interface{}{
  4019. "msg": "提交成功",
  4020. "weight": dryWeight,
  4021. })
  4022. }
  4023. }
  4024. }
  4025. func (this *DialysisApiController) GetFuncPurview() {
  4026. adminUserInfo := this.GetAdminUserInfo()
  4027. user_id := adminUserInfo.AdminUser.Id
  4028. app_id := adminUserInfo.CurrentAppId
  4029. org_id := adminUserInfo.CurrentOrgId
  4030. create_url := this.GetString("create_url")
  4031. modify_url := this.GetString("modify_url")
  4032. modify_other_url := this.GetString("modify_other_url")
  4033. del_url := this.GetString("del_url")
  4034. del_other_url := this.GetString("del_other_url")
  4035. exce_url := this.GetString("exce_url")
  4036. check_url := this.GetString("check_url")
  4037. modify_exce_url := this.GetString("modify_exce_url")
  4038. module, _ := this.GetInt64("module", 0)
  4039. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4040. var is_has_create bool
  4041. var is_has_modify bool
  4042. var is_has_modify_other bool
  4043. var is_has_del bool
  4044. var is_has_del_other bool
  4045. var is_has_exce bool
  4046. var is_has_check bool
  4047. var is_has_modify_exce bool
  4048. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4049. if adminUserInfo.AdminUser.Id != org.Creator {
  4050. if app_role != nil {
  4051. if len(app_role.RoleIds) > 0 {
  4052. roles := strings.Split(app_role.RoleIds, ",")
  4053. var userRolePurviews string
  4054. for _, item := range roles {
  4055. role_id, _ := strconv.ParseInt(item, 10, 64)
  4056. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4057. if len(userRolePurviews) == 0 {
  4058. userRolePurviews = purviews
  4059. } else {
  4060. userRolePurviews = userRolePurviews + "," + purviews
  4061. }
  4062. }
  4063. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4064. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4065. for _, item := range funcPurviews {
  4066. //for _, url := range strings.Split(item.Urlfor,","){
  4067. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4068. is_has_create = true
  4069. }
  4070. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4071. is_has_modify = true
  4072. }
  4073. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4074. is_has_modify_other = true
  4075. }
  4076. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4077. is_has_del = true
  4078. }
  4079. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4080. is_has_del_other = true
  4081. }
  4082. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4083. is_has_exce = true
  4084. }
  4085. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4086. is_has_check = true
  4087. }
  4088. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4089. is_has_modify_exce = true
  4090. }
  4091. }
  4092. } else {
  4093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4094. return
  4095. }
  4096. this.ServeSuccessJSON(map[string]interface{}{
  4097. "is_has_create": is_has_create,
  4098. "is_has_modify": is_has_modify,
  4099. "is_has_modify_other": is_has_modify_other,
  4100. "is_has_del": is_has_del,
  4101. "is_has_del_other": is_has_del_other,
  4102. "is_has_exce": is_has_exce,
  4103. "is_has_check": is_has_check,
  4104. "is_has_modify_exce": is_has_modify_exce,
  4105. "module": module,
  4106. })
  4107. } else {
  4108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4109. return
  4110. }
  4111. } else {
  4112. this.ServeSuccessJSON(map[string]interface{}{
  4113. "is_has_create": true,
  4114. "is_has_modify": true,
  4115. "is_has_modify_other": true,
  4116. "is_has_del": true,
  4117. "is_has_del_other": true,
  4118. "is_has_exce": true,
  4119. "is_has_check": true,
  4120. "is_has_modify_exce": true,
  4121. "module": true,
  4122. })
  4123. }
  4124. }
  4125. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4126. patient_id, _ := this.GetInt64("patient_id", 0)
  4127. advice_date, _ := this.GetInt64("advice_date")
  4128. adminUserInfo := this.GetAdminUserInfo()
  4129. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4130. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4131. this.ServeSuccessJSON(map[string]interface{}{
  4132. "doctorAdvice": doctorAdvice,
  4133. "hisDoctorAdvice": hisDoctorAdvice,
  4134. })
  4135. }
  4136. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4137. change_type, _ := this.GetInt64("type", 0)
  4138. record_date := this.GetString("record_time")
  4139. patient_id, _ := this.GetInt64("patient_id", 0)
  4140. timeLayout := "2006-01-02"
  4141. loc, _ := time.LoadLocation("Local")
  4142. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4143. record_time := theAdviceRecordTime.Unix()
  4144. adminUserInfo := this.GetAdminUserInfo()
  4145. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4146. if err == nil {
  4147. if len(advices) == 0 {
  4148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4149. return
  4150. } else {
  4151. this.ServeSuccessJSON(map[string]interface{}{
  4152. "advices": advices,
  4153. "schedule": sch,
  4154. })
  4155. return
  4156. }
  4157. } else {
  4158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4159. return
  4160. }
  4161. }
  4162. func (c *DialysisApiController) GetDialysisGoods() {
  4163. schedualDate := c.GetString("schedule_date")
  4164. schedule_type, _ := c.GetInt64("schedule_type")
  4165. partition_id, _ := c.GetInt64("partition_id")
  4166. page, _ := c.GetInt("page")
  4167. limit, _ := c.GetInt("limit")
  4168. keywords := c.GetString("keywords")
  4169. patient_id, _ := c.GetInt64("patient_id")
  4170. good_type, _ := c.GetInt64("good_type")
  4171. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4172. if parseDateErr != nil && len(schedualDate) != 0 {
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. schedualEndDate := int64(0)
  4177. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4178. if parseDateErr != nil && len(schedualDate) != 0 {
  4179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4180. return
  4181. }
  4182. schedualEndDate = endDate.Unix()
  4183. adminUser := c.GetAdminUserInfo()
  4184. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4185. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4186. if err == gorm.ErrRecordNotFound {
  4187. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4188. var ids []int64
  4189. for _, item := range list {
  4190. ids = append(ids, item.PatientId)
  4191. }
  4192. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4193. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4194. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4195. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4196. item.LastAutomaticReduceDetail = goodUser
  4197. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4198. }
  4199. c.ServeSuccessJSON(map[string]interface{}{
  4200. "dialysis_goods": dialysisGoods,
  4201. "good_type": goodTypes,
  4202. "total": total,
  4203. })
  4204. return
  4205. } else if err == nil {
  4206. //获取当天排班的每个患者的库存使用情况
  4207. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4208. var ids []int64
  4209. for _, item := range list {
  4210. ids = append(ids, item.PatientId)
  4211. }
  4212. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4213. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4214. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4215. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4216. fmt.Println(goodUser)
  4217. fmt.Println(lastGoodUserDetial)
  4218. item.LastAutomaticReduceDetail = goodUser
  4219. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4220. }
  4221. if err == nil {
  4222. c.ServeSuccessJSON(map[string]interface{}{
  4223. "dialysis_goods": dialysisGoods,
  4224. "good_type": goodTypes,
  4225. "total": total,
  4226. })
  4227. return
  4228. } else {
  4229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4230. return
  4231. }
  4232. } else if err != nil {
  4233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4234. return
  4235. }
  4236. }
  4237. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4238. start_time := c.GetString("start_time")
  4239. end_time := c.GetString("end_time")
  4240. timeLayout := "2006-01-02"
  4241. loc, _ := time.LoadLocation("Local")
  4242. var theStartTime int64
  4243. if len(start_time) > 0 {
  4244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4245. if err != nil {
  4246. utils.ErrorLog(err.Error())
  4247. }
  4248. theStartTime = theTime.Unix()
  4249. }
  4250. var theEndtTime int64
  4251. if len(end_time) > 0 {
  4252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4253. if err != nil {
  4254. utils.ErrorLog(err.Error())
  4255. }
  4256. theEndtTime = theTime.Unix()
  4257. }
  4258. adminUser := c.GetAdminUserInfo()
  4259. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4260. if err == nil {
  4261. c.ServeSuccessJSON(map[string]interface{}{
  4262. "stock_out": outInfo,
  4263. })
  4264. return
  4265. } else {
  4266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4267. return
  4268. }
  4269. }
  4270. func (c *DialysisApiController) GetRoleList() {
  4271. orgId := c.GetAdminUserInfo().CurrentOrgId
  4272. admin_user_id, _ := c.GetInt64("admin_user_id")
  4273. list, err := service.GetRoleList(orgId, admin_user_id)
  4274. if err == nil {
  4275. c.ServeSuccessJSON(map[string]interface{}{
  4276. "adminRole": list,
  4277. })
  4278. return
  4279. } else {
  4280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4281. return
  4282. }
  4283. }
  4284. func (c *DialysisApiController) GetInitPrintData() {
  4285. patient_id, _ := c.GetInt64("patient_id")
  4286. record_date, _ := c.GetInt64("record_date")
  4287. orgId := c.GetAdminUserInfo().CurrentOrgId
  4288. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4289. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4290. if err == nil {
  4291. c.ServeSuccessJSON(map[string]interface{}{
  4292. "list": list,
  4293. "assessmentAfterDislysis": assessmentAfterDislysis,
  4294. })
  4295. return
  4296. } else {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4298. return
  4299. }
  4300. }
  4301. func (c *DialysisApiController) GetInitPrintDataOne() {
  4302. patient_id, _ := c.GetInt64("patient_id")
  4303. start_time := c.GetString("record_date")
  4304. timeLayout := "2006-01-02"
  4305. loc, _ := time.LoadLocation("Local")
  4306. var theStartTime int64
  4307. if len(start_time) > 0 {
  4308. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4309. if err != nil {
  4310. utils.ErrorLog(err.Error())
  4311. }
  4312. theStartTime = theTime.Unix()
  4313. }
  4314. orgId := c.GetAdminUserInfo().CurrentOrgId
  4315. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4316. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4317. if err == nil {
  4318. c.ServeSuccessJSON(map[string]interface{}{
  4319. "list": list,
  4320. "assessmentAfterDislysis": assessmentAfterDislysis,
  4321. })
  4322. return
  4323. } else {
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4325. return
  4326. }
  4327. }
  4328. // 新接口
  4329. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4330. keyword := this.GetString("keywords")
  4331. limit, _ := this.GetInt64("limit")
  4332. page, _ := this.GetInt64("page")
  4333. partition_id, _ := this.GetInt64("partition_id")
  4334. schedule_type, _ := this.GetInt64("schedule_type")
  4335. start_time := this.GetString("schedule_date")
  4336. advice_ids := this.GetString("ids")
  4337. var ids []string
  4338. if advice_ids != "" {
  4339. ids = strings.Split(advice_ids, ",")
  4340. }
  4341. timeLayout := "2006-01-02"
  4342. loc, _ := time.LoadLocation("Local")
  4343. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4344. orgId := this.GetAdminUserInfo().CurrentOrgId
  4345. _, config := service.FindXTHisRecordByOrgId(orgId)
  4346. goodType, _ := service.GetAllGoodType(orgId)
  4347. if config.IsOpen != 1 {
  4348. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4349. fmt.Println("list2232323223332323232", list)
  4350. if err == nil {
  4351. this.ServeSuccessJSON(map[string]interface{}{
  4352. "list": list,
  4353. "total": total,
  4354. "config": config,
  4355. "goodType": goodType,
  4356. })
  4357. return
  4358. } else {
  4359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4360. return
  4361. }
  4362. }
  4363. if config.IsOpen == 1 {
  4364. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4365. if err == nil {
  4366. this.ServeSuccessJSON(map[string]interface{}{
  4367. "list": list,
  4368. "total": total,
  4369. "config": config,
  4370. "goodType": goodType,
  4371. })
  4372. return
  4373. }
  4374. }
  4375. }
  4376. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4377. keyword := this.GetString("keywords")
  4378. limit, _ := this.GetInt64("limit")
  4379. page, _ := this.GetInt64("page")
  4380. partition_id, _ := this.GetInt64("partition_id")
  4381. schedule_type, _ := this.GetInt64("schedule_type")
  4382. start_time := this.GetString("schedule_date")
  4383. ids := this.GetString("ids")
  4384. var idArray []string
  4385. if ids != "" {
  4386. idArray = strings.Split(ids, ",")
  4387. }
  4388. timeLayout := "2006-01-02"
  4389. loc, _ := time.LoadLocation("Local")
  4390. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4391. orgId := this.GetAdminUserInfo().CurrentOrgId
  4392. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4393. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4394. //获取长期医嘱
  4395. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4396. _, config := service.FindXTHisRecordByOrgId(orgId)
  4397. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4398. if err == nil {
  4399. this.ServeSuccessJSON(map[string]interface{}{
  4400. "list": list,
  4401. "total": total,
  4402. "adviceList": adviceList,
  4403. "config": config,
  4404. "drugList": drugList,
  4405. "tablelist": tablelist,
  4406. })
  4407. return
  4408. } else {
  4409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4410. return
  4411. }
  4412. }
  4413. func (this *DialysisApiController) SaveDialysisSetting() {
  4414. orgId := this.GetAdminUserInfo().CurrentOrgId
  4415. device_number_set, _ := this.GetInt64("device_number_set")
  4416. device_type_set, _ := this.GetInt64("device_type_set")
  4417. name_set, _ := this.GetInt64("name_set")
  4418. admission_number_set, _ := this.GetInt64("admission_number_set")
  4419. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4420. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4421. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4422. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4423. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4424. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4425. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4426. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4427. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4428. mode_id_set, _ := this.GetInt64("mode_id_set")
  4429. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4430. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4431. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4432. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4433. kalium_set, _ := this.GetInt64("kalium_set")
  4434. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4435. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4436. glucose_set, _ := this.GetInt64("glucose_set")
  4437. sodium_set, _ := this.GetInt64("sodium_set")
  4438. calcium_set, _ := this.GetInt64("calcium_set")
  4439. blood_access_set, _ := this.GetInt64("blood_access_set")
  4440. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4441. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4442. dialysisSetting := models.XtDialysisSetting{
  4443. Sodium: sodium_set,
  4444. Calcium: calcium_set,
  4445. BloodAccess: blood_access_set,
  4446. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4447. DisplaceLiquiPart: displace_liqui_part_set,
  4448. UserOrgId: orgId,
  4449. Status: 1,
  4450. DeviceNumber: device_number_set,
  4451. DeviceType: device_type_set,
  4452. Name: name_set,
  4453. AdmissionNumber: admission_number_set,
  4454. DialysisNo: dialysis_no_set,
  4455. WeightBefor: weight_befor_set,
  4456. DryWeight: dry_weight_set,
  4457. BloodPressure: blood_pressure_set,
  4458. UltrafiltrationVolume: ultrafiltration_volume_set,
  4459. InternalFistula: internal_fistula_set,
  4460. BloodFlowVolume: blood_flow_volume_set,
  4461. Anticoagulant: anticoagulant_set,
  4462. SealingFluidDispose: sealing_fluid_dispose_set,
  4463. ModeId: mode_id_set,
  4464. DialysisTime: dialysis_time_set,
  4465. DialysisDialyszers: dialysis_dialyszers_set,
  4466. DialysisIrrigation: dialysis_irrigation_set,
  4467. Gaijiliang: gaijiliang_set,
  4468. Kalium: kalium_set,
  4469. DisplaceLiquiValue: displace_liqui_value_set,
  4470. Bicarbonate: bicarbonate_set,
  4471. Glucose: glucose_set,
  4472. Ctime: time.Now().Unix(),
  4473. Mtime: time.Now().Unix(),
  4474. }
  4475. err := service.SaveDialysisSetting(dialysisSetting)
  4476. if err == nil {
  4477. this.ServeSuccessJSON(map[string]interface{}{
  4478. "dialysisSetting": dialysisSetting,
  4479. })
  4480. return
  4481. } else {
  4482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4483. return
  4484. }
  4485. }
  4486. func (this *DialysisApiController) GetDialysisSetting() {
  4487. orgId := this.GetAdminUserInfo().CurrentOrgId
  4488. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4489. this.ServeSuccessJSON(map[string]interface{}{
  4490. "dialysisSett": dialysisSett,
  4491. })
  4492. return
  4493. }
  4494. func (this *DialysisApiController) GetDialysisParameterList() {
  4495. keyword := this.GetString("keywords")
  4496. limit, _ := this.GetInt64("limit")
  4497. page, _ := this.GetInt64("page")
  4498. partition_id, _ := this.GetInt64("partition_id")
  4499. schedule_type, _ := this.GetInt64("schedule_type")
  4500. start_time := this.GetString("schedule_date")
  4501. timeLayout := "2006-01-02"
  4502. loc, _ := time.LoadLocation("Local")
  4503. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4504. orgId := this.GetAdminUserInfo().CurrentOrgId
  4505. scheduids := this.GetString("ids")
  4506. var ids []string
  4507. if scheduids != "" {
  4508. ids = strings.Split(scheduids, ",")
  4509. }
  4510. list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4511. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4512. if err == nil {
  4513. this.ServeSuccessJSON(map[string]interface{}{
  4514. "list": list,
  4515. "total": total,
  4516. "dialysisSett": dialysisSett,
  4517. })
  4518. return
  4519. } else {
  4520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4521. return
  4522. }
  4523. }
  4524. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4525. orgId := this.GetAdminUserInfo().CurrentOrgId
  4526. schedule_type, _ := this.GetInt64("schedule_type")
  4527. //partion_type, _ := this.GetInt64("partion_type")
  4528. start_time := this.GetString("selected_date")
  4529. partion_type := this.GetString("partion_type")
  4530. var ids []string
  4531. ids = strings.Split(partion_type, ",")
  4532. timeLayout := "2006-01-02"
  4533. loc, _ := time.LoadLocation("Local")
  4534. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4535. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4536. if err == nil {
  4537. this.ServeSuccessJSON(map[string]interface{}{
  4538. "list": list,
  4539. })
  4540. return
  4541. } else {
  4542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4543. return
  4544. }
  4545. }
  4546. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4547. orgId := this.GetAdminUserInfo().CurrentOrgId
  4548. schedule_type, _ := this.GetInt64("schedule_type")
  4549. //partion_type, _ := this.GetInt64("partion_type")
  4550. partion_type := this.GetString("partion_type")
  4551. var ids []string
  4552. ids = strings.Split(partion_type, ",")
  4553. start_time := this.GetString("selected_date")
  4554. timeLayout := "2006-01-02"
  4555. loc, _ := time.LoadLocation("Local")
  4556. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4557. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4558. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4559. //获取长期医嘱
  4560. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4561. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4562. _, config := service.FindXTHisRecordByOrgId(orgId)
  4563. if err == nil {
  4564. this.ServeSuccessJSON(map[string]interface{}{
  4565. "list": list,
  4566. "drug": drug,
  4567. "adviceList": adviceList,
  4568. "config": config,
  4569. "tablelist": tablelist,
  4570. })
  4571. return
  4572. } else {
  4573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4574. return
  4575. }
  4576. }
  4577. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4578. orgId := this.GetAdminUserInfo().CurrentOrgId
  4579. schedule_type, _ := this.GetInt64("schedule_type")
  4580. partion_type, _ := this.GetInt64("partion_type")
  4581. start_time := this.GetString("selected_date")
  4582. timeLayout := "2006-01-02"
  4583. loc, _ := time.LoadLocation("Local")
  4584. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4585. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4586. if err == nil {
  4587. this.ServeSuccessJSON(map[string]interface{}{
  4588. "list": list,
  4589. })
  4590. return
  4591. } else {
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4593. return
  4594. }
  4595. }
  4596. func (this *DialysisApiController) SaveHisDialysis() {
  4597. var ids []string
  4598. advice_ids := this.GetString("ids")
  4599. ids = strings.Split(advice_ids, ",")
  4600. orgId := this.GetAdminUserInfo().CurrentOrgId
  4601. service.SaveHisDialysis(orgId, ids)
  4602. returnData := make(map[string]interface{}, 0)
  4603. returnData["msg"] = "ok"
  4604. this.ServeSuccessJSON(returnData)
  4605. return
  4606. }
  4607. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4608. orgId := this.GetAdminUserInfo().CurrentOrgId
  4609. schedule_type, _ := this.GetInt64("schedule_type")
  4610. //partion_type, _ := this.GetInt64("partion_type")
  4611. partion_type := this.GetString("partion_type")
  4612. var ids []string
  4613. ids = strings.Split(partion_type, ",")
  4614. start_time := this.GetString("selected_date")
  4615. timeLayout := "2006-01-02"
  4616. loc, _ := time.LoadLocation("Local")
  4617. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4618. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4619. this.ServeSuccessJSON(map[string]interface{}{
  4620. "list": list,
  4621. })
  4622. return
  4623. }
  4624. func (this *DialysisApiController) GetPatientSchedule() {
  4625. orgId := this.GetAdminUserInfo().CurrentOrgId
  4626. patient_id, _ := this.GetInt64("patient_id")
  4627. schedule_date, _ := this.GetInt64("schedule_date")
  4628. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4629. this.ServeSuccessJSON(map[string]interface{}{
  4630. "schedulePatient": schedulePatient,
  4631. })
  4632. }
  4633. func (c *DialysisApiController) GetSchedulePrintList() {
  4634. page, _ := c.GetInt64("page", 1)
  4635. limit, _ := c.GetInt64("limit", 10)
  4636. schedulType, _ := c.GetInt64("schedule_type", 0)
  4637. partitionType, _ := c.GetInt64("partition_type", 0)
  4638. keywords := c.GetString("keywords")
  4639. schedule_date := c.GetString("schedule_date")
  4640. timeLayout := "2006-01-02"
  4641. loc, _ := time.LoadLocation("Local")
  4642. var theStartTime int64
  4643. if len(schedule_date) > 0 {
  4644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4645. if err != nil {
  4646. utils.ErrorLog(err.Error())
  4647. }
  4648. theStartTime = theTime.Unix()
  4649. }
  4650. adminUserInfo := c.GetAdminUserInfo()
  4651. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4652. for _, item := range list {
  4653. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4654. item.DialysisOrderTwenty = order
  4655. }
  4656. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4657. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4658. c.ServeSuccessJSON(map[string]interface{}{
  4659. "list": list,
  4660. "total": total,
  4661. "numberList": numberList,
  4662. "listOne": listOne,
  4663. })
  4664. }
  4665. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4666. orgId := this.GetAdminUserInfo().CurrentOrgId
  4667. list, _ := service.GetSolutionListByOrgId(orgId)
  4668. for _, item := range list {
  4669. //获取该模式最新的1条数据
  4670. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4671. //更新状态值
  4672. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4673. }
  4674. this.ServeSuccessJSON(map[string]interface{}{
  4675. "list": list,
  4676. })
  4677. }
  4678. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4679. orgId := this.GetAdminUserInfo().CurrentOrgId
  4680. is_open, _ := this.GetInt64("is_open")
  4681. idsStr := this.GetString("str")
  4682. recordIDStrs := strings.Split(idsStr, ",")
  4683. start_time := this.GetString("advice_date")
  4684. exec_time, _ := this.GetInt64("exec_time")
  4685. timeLayout := "2006-01-02"
  4686. loc, _ := time.LoadLocation("Local")
  4687. var startTime int64
  4688. if len(start_time) > 0 {
  4689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4690. if err != nil {
  4691. //fmt.Println(err)
  4692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4693. return
  4694. }
  4695. startTime = theTime.Unix()
  4696. }
  4697. config, _ := service.GetDrugOpenConfigOne(orgId)
  4698. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4699. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4700. //his医嘱
  4701. if is_open == 1 {
  4702. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4703. //查找未执行医嘱
  4704. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4705. for _, item := range list {
  4706. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4707. this.ServeSuccessJSON(map[string]interface{}{
  4708. "msg": "3",
  4709. })
  4710. return
  4711. }
  4712. }
  4713. for _, item := range groupList {
  4714. for _, it := range list {
  4715. if item.DrugId == it.DrugId {
  4716. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4717. }
  4718. }
  4719. }
  4720. for _, item := range groupList {
  4721. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4722. var sum_out_count int64
  4723. for _, it := range item.ChildDoctorAdvice {
  4724. var prescribing_number int64
  4725. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4726. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4727. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4728. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4729. }
  4730. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4731. prescribing_number = parseIntPrescribingNumber
  4732. }
  4733. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4734. prescribing_number = parseIntPrescribingNumber
  4735. }
  4736. sum_out_count += prescribing_number
  4737. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4738. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4739. //库存不足
  4740. if sum_out_count > drugStockOut.FlushCount {
  4741. this.ServeSuccessJSON(map[string]interface{}{
  4742. "msg": "2",
  4743. "drug": medical,
  4744. })
  4745. return
  4746. }
  4747. }
  4748. }
  4749. creater := this.GetAdminUserInfo().AdminUser.Id
  4750. //执行出库逻辑
  4751. for _, item := range list {
  4752. hisadvice := &models.HisDoctorAdviceInfo{
  4753. ID: item.ID,
  4754. UserOrgId: item.UserOrgId,
  4755. PatientId: item.PatientId,
  4756. AdviceType: item.AdviceType,
  4757. AdviceDate: item.AdviceDate,
  4758. StartTime: item.StartTime,
  4759. AdviceName: item.AdviceName,
  4760. AdviceDesc: item.AdviceDesc,
  4761. ReminderDate: item.ReminderDate,
  4762. SingleDose: item.SingleDose,
  4763. SingleDoseUnit: item.SingleDoseUnit,
  4764. DrugSpec: item.DrugSpec,
  4765. DrugSpecUnit: item.DrugSpecUnit,
  4766. PrescribingNumber: item.PrescribingNumber,
  4767. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4768. DeliveryWay: item.DeliveryWay,
  4769. ExecutionFrequency: item.ExecutionFrequency,
  4770. AdviceDoctor: item.AdviceDoctor,
  4771. Status: 1,
  4772. CreatedTime: item.CreatedTime,
  4773. UpdatedTime: item.UpdatedTime,
  4774. AdviceAffirm: item.AdviceAffirm,
  4775. Remark: item.Remark,
  4776. StopTime: item.StopTime,
  4777. StopReason: item.StopReason,
  4778. StopDoctor: item.StopDoctor,
  4779. StopState: item.StopState,
  4780. ParentId: item.ParentId,
  4781. ExecutionTime: item.ExecutionTime,
  4782. ExecutionStaff: creater,
  4783. ExecutionState: item.ExecutionState,
  4784. Checker: item.Checker,
  4785. RecordDate: item.RecordDate,
  4786. DialysisOrderId: item.DialysisOrderId,
  4787. CheckTime: item.CheckTime,
  4788. CheckState: item.CheckState,
  4789. RemindType: item.RemindType,
  4790. FrequencyType: item.FrequencyType,
  4791. DayCount: item.DayCount,
  4792. WeekDay: item.WeekDay,
  4793. TemplateId: item.TemplateId,
  4794. Modifier: item.Modifier,
  4795. Way: item.Way,
  4796. DrugId: item.DrugId,
  4797. ExecutionFrequencyId: item.ExecutionFrequencyId,
  4798. }
  4799. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4800. if medical.IsUse == 2 {
  4801. if config.IsOpen != 1 {
  4802. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4803. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4804. }
  4805. //不通过药房发药
  4806. if pharmacyConfig.IsOpen != 1 {
  4807. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4808. }
  4809. //查询默认仓库
  4810. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4811. //查询默认仓库剩余多少库存
  4812. var sum_count int64
  4813. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4814. for _, its := range stockInfo {
  4815. if its.MaxUnit == medical.MaxUnit {
  4816. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4817. }
  4818. sum_count += its.StockMaxNumber + its.StockMinNumber
  4819. }
  4820. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4821. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4822. }
  4823. }
  4824. info := models.HisDoctorAdviceInfo{
  4825. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4826. ExecutionTime: exec_time,
  4827. ExecutionState: 1,
  4828. UpdatedTime: time.Now().Unix(),
  4829. }
  4830. //执行医嘱
  4831. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  4832. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  4833. redis := service.RedisClient()
  4834. //清空key 值
  4835. redis.Set(key, "", time.Second)
  4836. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  4837. redis.Set(keyTwo, "", time.Second)
  4838. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4839. redis.Set(keyThree, "", time.Second)
  4840. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4841. theTime := toTime.Format("2006-01-02")
  4842. fmt.Println("theTIME", theTime)
  4843. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  4844. redis.Set(keyFour, "", time.Second)
  4845. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4846. redis.Set(keyFive, "", time.Second)
  4847. }
  4848. } else {
  4849. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  4850. //查找未执行医嘱
  4851. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4852. for _, item := range groupList {
  4853. for _, it := range list {
  4854. if item.DrugId == it.DrugId {
  4855. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4856. }
  4857. }
  4858. }
  4859. for _, item := range groupList {
  4860. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4861. var sum_out_count int64
  4862. for _, it := range item.ChildDoctorAdvice {
  4863. var prescribing_number int64
  4864. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4865. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4866. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4867. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4868. }
  4869. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4870. prescribing_number = parseIntPrescribingNumber
  4871. }
  4872. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4873. prescribing_number = parseIntPrescribingNumber
  4874. }
  4875. sum_out_count += prescribing_number
  4876. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4877. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4878. //库存不足
  4879. if sum_out_count > drugStockOut.FlushCount {
  4880. this.ServeSuccessJSON(map[string]interface{}{
  4881. "msg": "2",
  4882. "drug": medical,
  4883. })
  4884. return
  4885. }
  4886. }
  4887. }
  4888. for _, item := range list {
  4889. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4890. dadvice := &models.DoctorAdvice{
  4891. ID: item.ID,
  4892. UserOrgId: item.UserOrgId,
  4893. PatientId: item.PatientId,
  4894. AdviceType: item.AdviceType,
  4895. AdviceDate: item.AdviceDate,
  4896. StartTime: item.StartTime,
  4897. AdviceName: item.AdviceName,
  4898. AdviceDesc: item.AdviceDesc,
  4899. ReminderDate: item.ReminderDate,
  4900. SingleDose: item.SingleDose,
  4901. SingleDoseUnit: item.SingleDoseUnit,
  4902. DrugSpec: item.DrugSpec,
  4903. DrugSpecUnit: item.DrugSpecUnit,
  4904. PrescribingNumber: item.PrescribingNumber,
  4905. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4906. DeliveryWay: item.DeliveryWay,
  4907. ExecutionFrequency: item.ExecutionFrequency,
  4908. AdviceDoctor: item.AdviceDoctor,
  4909. Status: 1,
  4910. CreatedTime: item.CreatedTime,
  4911. UpdatedTime: item.UpdatedTime,
  4912. AdviceAffirm: item.AdviceAffirm,
  4913. Remark: item.Remark,
  4914. StopTime: item.StopTime,
  4915. StopReason: item.StopReason,
  4916. StopDoctor: item.StopDoctor,
  4917. StopState: item.StopState,
  4918. ParentId: item.ParentId,
  4919. ExecutionTime: item.ExecutionTime,
  4920. ExecutionStaff: item.ExecutionStaff,
  4921. ExecutionState: item.ExecutionState,
  4922. Checker: item.Checker,
  4923. RecordDate: item.ReminderDate,
  4924. DialysisOrderId: item.DialysisOrderId,
  4925. CheckTime: item.CheckTime,
  4926. CheckState: item.CheckState,
  4927. RemindType: item.RemindType,
  4928. FrequencyType: item.FrequencyType,
  4929. DayCount: item.DayCount,
  4930. WeekDay: item.WeekDay,
  4931. TemplateId: item.TemplateId,
  4932. Modifier: item.Modifier,
  4933. Way: item.Way,
  4934. DrugId: item.DrugId,
  4935. }
  4936. if medical.IsUse == 2 {
  4937. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4938. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4939. }
  4940. if pharmacyConfig.IsOpen != 1 {
  4941. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4942. }
  4943. //更新字典里面的库存
  4944. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4945. var sum_count int64
  4946. for _, its := range stockInfo {
  4947. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4948. if its.MaxUnit == baseDrug.MaxUnit {
  4949. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4950. }
  4951. sum_count += its.StockMaxNumber + its.StockMinNumber
  4952. }
  4953. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4954. //剩余库存
  4955. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4956. }
  4957. info := models.DoctorAdvice{
  4958. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4959. ExecutionTime: exec_time,
  4960. ExecutionState: 1,
  4961. UpdatedTime: time.Now().Unix(),
  4962. }
  4963. //执行医嘱
  4964. service.UpdateDoctorAdviceExecution(info, item.ID)
  4965. }
  4966. }
  4967. this.ServeSuccessJSON(map[string]interface{}{
  4968. "msg": "1",
  4969. })
  4970. return
  4971. }
  4972. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  4973. orgId := this.GetAdminUserInfo().CurrentOrgId
  4974. idsStr := this.GetString("str")
  4975. recordIDStrs := strings.Split(idsStr, ",")
  4976. start_time := this.GetString("advice_date")
  4977. timeLayout := "2006-01-02"
  4978. loc, _ := time.LoadLocation("Local")
  4979. var startTime int64
  4980. if len(start_time) > 0 {
  4981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4982. if err != nil {
  4983. //fmt.Println(err)
  4984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4985. return
  4986. }
  4987. startTime = theTime.Unix()
  4988. }
  4989. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  4990. if config.IsOpen == 1 {
  4991. creater := this.GetAdminUserInfo().AdminUser.Id
  4992. //查询未核对的医嘱
  4993. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  4994. for _, item := range advicelist {
  4995. if item.ExecutionStaff == creater {
  4996. this.ServeSuccessJSON(map[string]interface{}{
  4997. "msg": "2",
  4998. "advice": item,
  4999. })
  5000. return
  5001. }
  5002. service.CheckHisDoctorAdvice(item.ID, creater)
  5003. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5004. redis := service.RedisClient()
  5005. //清空key 值
  5006. redis.Set(key, "", time.Second)
  5007. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5008. redis.Set(keyTwo, "", time.Second)
  5009. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5010. redis.Set(keyThree, "", time.Second)
  5011. theTime := time.Now()
  5012. recordDate := theTime.Format("2006-01-02")
  5013. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5014. redis.Set(keyFour, "", time.Second)
  5015. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5016. redis.Set(keyFive, "", time.Second)
  5017. }
  5018. } else {
  5019. //查询未核对的医嘱
  5020. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5021. creater := this.GetAdminUserInfo().AdminUser.Id
  5022. for _, item := range advicelist {
  5023. if item.ExecutionStaff == creater {
  5024. this.ServeSuccessJSON(map[string]interface{}{
  5025. "msg": "2",
  5026. "advice": item,
  5027. })
  5028. return
  5029. }
  5030. service.CheckDoctorAdvice(item.ID, creater)
  5031. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5032. redis := service.RedisClient()
  5033. //清空key 值
  5034. redis.Set(key, "", time.Second)
  5035. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5036. redis.Set(keyTwo, "", time.Second)
  5037. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5038. redis.Set(keyThree, "", time.Second)
  5039. theTime := time.Now()
  5040. recordDate := theTime.Format("2006-01-02")
  5041. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5042. redis.Set(keyFour, "", time.Second)
  5043. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5044. redis.Set(keyFive, "", time.Second)
  5045. }
  5046. }
  5047. this.ServeSuccessJSON(map[string]interface{}{
  5048. "msg": "1",
  5049. })
  5050. return
  5051. }
  5052. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5053. orgId := this.GetAdminUserInfo().CurrentOrgId
  5054. is_open, _ := this.GetInt64("is_open")
  5055. idsStr := this.GetString("str")
  5056. recordIDStrs := strings.Split(idsStr, ",")
  5057. start_time := this.GetString("advice_date")
  5058. timeLayout := "2006-01-02"
  5059. loc, _ := time.LoadLocation("Local")
  5060. var startTime int64
  5061. if len(start_time) > 0 {
  5062. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5063. if err != nil {
  5064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5065. return
  5066. }
  5067. startTime = theTime.Unix()
  5068. }
  5069. if is_open == 1 {
  5070. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5071. } else {
  5072. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5073. }
  5074. this.ServeSuccessJSON(map[string]interface{}{
  5075. "msg": "1",
  5076. })
  5077. return
  5078. }
  5079. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5080. advice_id, _ := this.GetInt64("advice_id")
  5081. start_time := this.GetString("advice_date")
  5082. orgId := this.GetAdminUserInfo().CurrentOrgId
  5083. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5084. exec_time, _ := this.GetInt64("exec_time")
  5085. //his医嘱
  5086. if config.IsOpen == 1 {
  5087. //查询医嘱
  5088. advice, _ := service.GetHisDocById(advice_id, orgId)
  5089. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5090. this.ServeSuccessJSON(map[string]interface{}{
  5091. "msg": "3",
  5092. })
  5093. return
  5094. }
  5095. medical, _ := service.GetBaseDrugMedical(orgId)
  5096. var prescribing_number int64
  5097. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5098. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5099. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5100. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5101. }
  5102. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5103. prescribing_number = parseIntPrescribingNumber
  5104. }
  5105. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5106. prescribing_number = parseIntPrescribingNumber
  5107. }
  5108. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5109. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5110. //库存不足
  5111. if prescribing_number > drugStockOut.FlushCount {
  5112. this.ServeSuccessJSON(map[string]interface{}{
  5113. "msg": "2",
  5114. "drug": medical,
  5115. })
  5116. return
  5117. }
  5118. info := models.HisDoctorAdviceInfo{
  5119. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5120. ExecutionTime: exec_time,
  5121. ExecutionState: 1,
  5122. UpdatedTime: time.Now().Unix(),
  5123. }
  5124. //执行医嘱
  5125. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5126. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5127. redis := service.RedisClient()
  5128. //清空key 值
  5129. redis.Set(key, "", time.Second)
  5130. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5131. redis.Set(keyTwo, "", time.Second)
  5132. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5133. redis.Set(keyThree, "", time.Second)
  5134. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5135. theTime := toTime.Format("2006-01-02")
  5136. fmt.Println("theTIME", theTime)
  5137. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5138. redis.Set(keyFour, "", time.Second)
  5139. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5140. redis.Set(keyFive, "", time.Second)
  5141. //出库
  5142. if prescribing_number <= drugStockOut.FlushCount {
  5143. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5144. //执行出库逻辑
  5145. hisadvice := &models.HisDoctorAdviceInfo{
  5146. ID: advice.ID,
  5147. UserOrgId: advice.UserOrgId,
  5148. PatientId: advice.PatientId,
  5149. AdviceType: advice.AdviceType,
  5150. AdviceDate: advice.AdviceDate,
  5151. StartTime: advice.StartTime,
  5152. AdviceName: advice.AdviceName,
  5153. AdviceDesc: advice.AdviceDesc,
  5154. ReminderDate: advice.ReminderDate,
  5155. SingleDose: advice.SingleDose,
  5156. SingleDoseUnit: advice.SingleDoseUnit,
  5157. DrugSpec: advice.DrugSpec,
  5158. DrugSpecUnit: advice.DrugSpecUnit,
  5159. PrescribingNumber: advice.PrescribingNumber,
  5160. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5161. DeliveryWay: advice.DeliveryWay,
  5162. ExecutionFrequency: advice.ExecutionFrequency,
  5163. AdviceDoctor: advice.AdviceDoctor,
  5164. Status: 1,
  5165. CreatedTime: advice.CreatedTime,
  5166. UpdatedTime: advice.UpdatedTime,
  5167. AdviceAffirm: advice.AdviceAffirm,
  5168. Remark: advice.Remark,
  5169. StopTime: advice.StopTime,
  5170. StopReason: advice.StopReason,
  5171. StopDoctor: advice.StopDoctor,
  5172. StopState: advice.StopState,
  5173. ParentId: advice.ParentId,
  5174. ExecutionTime: advice.ExecutionTime,
  5175. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5176. ExecutionState: advice.ExecutionState,
  5177. Checker: advice.Checker,
  5178. RecordDate: advice.RecordDate,
  5179. DialysisOrderId: advice.DialysisOrderId,
  5180. CheckTime: advice.CheckTime,
  5181. CheckState: advice.CheckState,
  5182. RemindType: advice.RemindType,
  5183. FrequencyType: advice.FrequencyType,
  5184. DayCount: advice.DayCount,
  5185. WeekDay: advice.WeekDay,
  5186. TemplateId: advice.TemplateId,
  5187. Modifier: advice.Modifier,
  5188. Way: advice.Way,
  5189. DrugId: advice.DrugId,
  5190. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5191. }
  5192. if medical.IsUse == 2 {
  5193. if config.IsOpen != 1 {
  5194. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5195. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5196. }
  5197. //不通过药房发药
  5198. if pharmacyConfig.IsOpen != 1 {
  5199. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5200. }
  5201. //查询默认仓库
  5202. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5203. //查询默认仓库剩余多少库存
  5204. var sum_count int64
  5205. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5206. for _, its := range stockInfo {
  5207. if its.MaxUnit == medical.MaxUnit {
  5208. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5209. }
  5210. sum_count += its.StockMaxNumber + its.StockMinNumber
  5211. }
  5212. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5213. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5214. }
  5215. }
  5216. }
  5217. this.ServeSuccessJSON(map[string]interface{}{
  5218. "msg": "1",
  5219. })
  5220. return
  5221. }
  5222. if config.IsOpen == 2 || config.IsOpen == 0 {
  5223. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5224. medical, _ := service.GetBaseDrugMedical(orgId)
  5225. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5226. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5227. var prescribing_number int64
  5228. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5229. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5230. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5231. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5232. }
  5233. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5234. prescribing_number = parseIntPrescribingNumber
  5235. }
  5236. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5237. prescribing_number = parseIntPrescribingNumber
  5238. }
  5239. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5240. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5241. //库存不足
  5242. if prescribing_number > drugStockOut.FlushCount {
  5243. this.ServeSuccessJSON(map[string]interface{}{
  5244. "msg": "2",
  5245. "drug": medical,
  5246. })
  5247. return
  5248. }
  5249. info := models.DoctorAdvice{
  5250. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5251. ExecutionTime: exec_time,
  5252. ExecutionState: 1,
  5253. UpdatedTime: time.Now().Unix(),
  5254. }
  5255. //执行医嘱
  5256. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5257. dadvice := &models.DoctorAdvice{
  5258. ID: advice.ID,
  5259. UserOrgId: advice.UserOrgId,
  5260. PatientId: advice.PatientId,
  5261. AdviceType: advice.AdviceType,
  5262. AdviceDate: advice.AdviceDate,
  5263. StartTime: advice.StartTime,
  5264. AdviceName: advice.AdviceName,
  5265. AdviceDesc: advice.AdviceDesc,
  5266. ReminderDate: advice.ReminderDate,
  5267. SingleDose: advice.SingleDose,
  5268. SingleDoseUnit: advice.SingleDoseUnit,
  5269. DrugSpec: advice.DrugSpec,
  5270. DrugSpecUnit: advice.DrugSpecUnit,
  5271. PrescribingNumber: advice.PrescribingNumber,
  5272. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5273. DeliveryWay: advice.DeliveryWay,
  5274. ExecutionFrequency: advice.ExecutionFrequency,
  5275. AdviceDoctor: advice.AdviceDoctor,
  5276. Status: 1,
  5277. CreatedTime: advice.CreatedTime,
  5278. UpdatedTime: advice.UpdatedTime,
  5279. AdviceAffirm: advice.AdviceAffirm,
  5280. Remark: advice.Remark,
  5281. StopTime: advice.StopTime,
  5282. StopReason: advice.StopReason,
  5283. StopDoctor: advice.StopDoctor,
  5284. StopState: advice.StopState,
  5285. ParentId: advice.ParentId,
  5286. ExecutionTime: advice.ExecutionTime,
  5287. ExecutionStaff: advice.ExecutionStaff,
  5288. ExecutionState: advice.ExecutionState,
  5289. Checker: advice.Checker,
  5290. RecordDate: advice.ReminderDate,
  5291. DialysisOrderId: advice.DialysisOrderId,
  5292. CheckTime: advice.CheckTime,
  5293. CheckState: advice.CheckState,
  5294. RemindType: advice.RemindType,
  5295. FrequencyType: advice.FrequencyType,
  5296. DayCount: advice.DayCount,
  5297. WeekDay: advice.WeekDay,
  5298. TemplateId: advice.TemplateId,
  5299. Modifier: advice.Modifier,
  5300. Way: advice.Way,
  5301. DrugId: advice.DrugId,
  5302. }
  5303. if medical.IsUse == 2 {
  5304. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5305. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5306. }
  5307. if pharmacyConfig.IsOpen != 1 {
  5308. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5309. }
  5310. //更新字典里面的库存
  5311. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5312. var sum_count int64
  5313. for _, its := range stockInfo {
  5314. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5315. if its.MaxUnit == baseDrug.MaxUnit {
  5316. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5317. }
  5318. sum_count += its.StockMaxNumber + its.StockMinNumber
  5319. }
  5320. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5321. //剩余库存
  5322. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5323. }
  5324. }
  5325. this.ServeSuccessJSON(map[string]interface{}{
  5326. "msg": "1",
  5327. })
  5328. return
  5329. }
  5330. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5331. orgId := this.GetAdminUserInfo().CurrentOrgId
  5332. schedule_type, _ := this.GetInt64("schedule_type")
  5333. //partion_type, _ := this.GetInt64("partion_type")
  5334. partion_type := this.GetString("partion_type")
  5335. var ids []string
  5336. ids = strings.Split(partion_type, ",")
  5337. start_time := this.GetString("selected_date")
  5338. timeLayout := "2006-01-02"
  5339. loc, _ := time.LoadLocation("Local")
  5340. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5341. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5342. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5343. _, config := service.FindXTHisRecordByOrgId(orgId)
  5344. appId := this.GetAdminUserInfo().CurrentAppId
  5345. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5346. if err == nil {
  5347. this.ServeSuccessJSON(map[string]interface{}{
  5348. "list": list,
  5349. "drug": drug,
  5350. "config": config,
  5351. "doctorList": doctorList,
  5352. })
  5353. return
  5354. } else {
  5355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5356. return
  5357. }
  5358. }
  5359. func (this *DialysisApiController) GetMobileScheduleList() {
  5360. orgId := this.GetAdminUserInfo().CurrentOrgId
  5361. schedule, _ := service.GetMobileScheduleList(orgId)
  5362. if len(schedule) > 0 {
  5363. for _, its := range schedule {
  5364. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5365. //its.DialysisPrescription = prescription
  5366. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5367. //its.MonitoringRecord = monitor
  5368. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5369. //its.XtAssessmentAfterDislysis = after
  5370. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5371. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5372. }
  5373. }
  5374. this.ServeSuccessJSON(map[string]interface{}{
  5375. "schedule": schedule,
  5376. })
  5377. return
  5378. }