dialysis_api_controller.go 206KB

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