dialysis_api_controller.go 308KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "github.com/jinzhu/gorm"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. beego.Router("/api/patient/saveinformation", &DialysisApiController{}, "Get:SaveInformation")
  78. beego.Router("/api/patient/savedialysisInformationsetting", &DialysisApiController{}, "Get:SaveDialysisInformationSetting")
  79. beego.Router("/api/patient/getdialyisinformationsetting", &DialysisApiController{}, "Get:GetDialysisInformationSetting")
  80. beego.Router("/api/patient/checkdialysisinformation", &DialysisApiController{}, "Get:CheckDialysisInformation")
  81. beego.Router("/api/dialysis/patientsflow", &DialysisApiController{}, "Get:GetDialysisPatientsFlow")
  82. beego.Router("/api/patient/getlongdialysisadvicetoday", &DialysisApiController{}, "Get:GetLongDialysisAdviceToday")
  83. beego.Router("/api/patient/getpatientlist", &DialysisApiController{}, "Get:GetPatientList")
  84. beego.Router("/api/patient/getprescriptionloglist", &DialysisApiController{}, "Get:GetPrescriptionLogList")
  85. beego.Router("/api/patient/getbeforloglist", &DialysisApiController{}, "Get:GetBeforLogList")
  86. beego.Router("/api/patient/getdocloglist", &DialysisApiController{}, "Get:GetDocLogList")
  87. beego.Router("/api/patient/getmonitorloglist", &DialysisApiController{}, "Get:GetMonitorLogList")
  88. beego.Router("/api/patient/getafterloglist", &DialysisApiController{}, "Get:GetAfterLogList")
  89. beego.Router("/api/patient/savegathersetting", &DialysisApiController{}, "Get:SaveGatherSetting")
  90. beego.Router("/api/patient/getgathersetting", &DialysisApiController{}, "Get:GetGatherSetting")
  91. beego.Router("/api/patient/getdialysisgatherlist", &DialysisApiController{}, "Get:GetDialysisGatherList")
  92. beego.Router("/api/getpatientdialysisrecordlist", &DialysisApiController{}, "Get:GetPatientDialysisRecordList")
  93. beego.Router("/api/patient/getpatientrecordlist", &DialysisApiController{}, "Get:GetPatientRecordList")
  94. beego.Router("/api/patient/getdialysistotalcount", &DialysisApiController{}, "Get:GetDialysisTotalCount")
  95. beego.Router("/api/schedule/getdialysisproject", &DialysisApiController{}, "Get:GetDialysisProject")
  96. beego.Router("/api/schedule/getpatientbefor", &DialysisApiController{}, "Get:GetPatientBefor")
  97. }
  98. func (c *DialysisApiController) GetQueueCall() {
  99. adminUserInfo := c.GetAdminUserInfo()
  100. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  101. if queueConfig.ID <= 0 {
  102. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  103. queueConfig.Qhsj = 10
  104. queueConfig.Jzdcbbcs = 3
  105. queueConfig.Jzbbsy = 1
  106. queueConfig.Jzjhyc = 0
  107. queueConfig.Sjdcbbcs = 3
  108. queueConfig.Sjbbsy = 0
  109. queueConfig.Sjjhyc = 0
  110. queueConfig.Txxqyxs = 0
  111. queueConfig.Txglsyxs = 0
  112. }
  113. c.ServeSuccessJSON(map[string]interface{}{
  114. "queue_config": queueConfig,
  115. })
  116. }
  117. func (c *DialysisApiController) UpdateQueueCall() {
  118. adminUserInfo := c.GetAdminUserInfo()
  119. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  120. if queueConfig.ID <= 0 {
  121. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  122. queueConfig.Qhsj = 10
  123. queueConfig.Jzdcbbcs = 3
  124. queueConfig.Jzbbsy = 1
  125. queueConfig.Jzjhyc = 0
  126. queueConfig.Sjdcbbcs = 3
  127. queueConfig.Sjbbsy = 0
  128. queueConfig.Sjjhyc = 0
  129. queueConfig.Txxqyxs = 0
  130. queueConfig.Txglsyxs = 0
  131. queueConfig.CreateTime = time.Now().Unix()
  132. queueConfig.UpdateTime = time.Now().Unix()
  133. }
  134. qhsj, _ := c.GetInt64("qhsj", 0)
  135. if qhsj > 0 {
  136. queueConfig.Qhsj = qhsj
  137. }
  138. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  139. if jzdcbbcs > 0 {
  140. queueConfig.Jzdcbbcs = jzdcbbcs
  141. }
  142. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  143. if jzbbsy > 0 {
  144. queueConfig.Jzbbsy = jzbbsy
  145. }
  146. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  147. queueConfig.Jzjhyc = jzjhyc
  148. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  149. if sjdcbbcs > 0 {
  150. queueConfig.Sjdcbbcs = sjdcbbcs
  151. }
  152. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  153. if sjbbsy > 0 {
  154. queueConfig.Sjbbsy = sjbbsy
  155. }
  156. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  157. queueConfig.Sjjhyc = sjjhyc
  158. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  159. queueConfig.Txxqyxs = txxqyxs
  160. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  161. queueConfig.Txglsyxs = txglsyxs
  162. queueConfig.UpdateTime = time.Now().Unix()
  163. service.UpDateQueueCallInfo(queueConfig)
  164. c.ServeSuccessJSON(map[string]interface{}{
  165. "queue_config": queueConfig,
  166. })
  167. }
  168. func (c *DialysisApiController) PostPrescription() {
  169. patient, _ := c.GetInt64("patient_id", 0)
  170. recordDateStr := c.GetString("record_date")
  171. if patient <= 0 {
  172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  173. return
  174. }
  175. adminUserInfo := c.GetAdminUserInfo()
  176. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  177. if patientInfo.ID == 0 {
  178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  179. return
  180. }
  181. if len(recordDateStr) == 0 {
  182. recordDateStr = time.Now().Format("2006-01-02")
  183. }
  184. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  185. if parseDateErr != nil {
  186. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. mode_id, _ := c.GetInt64("mode_id", 0)
  191. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  192. dialyzer, _ := c.GetInt64("dialyzer", 0)
  193. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  194. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  195. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  196. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  197. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  198. replacement_way, _ := c.GetInt64("replacement_way", 0)
  199. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  200. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  201. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  202. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  203. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  204. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  205. kalium, _ := c.GetFloat("kalium", 0)
  206. sodium, _ := c.GetFloat("sodium", 0)
  207. replacement_total, _ := c.GetFloat("replacement_total", 0)
  208. calcium, _ := c.GetFloat("calcium", 0)
  209. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  210. glucose, _ := c.GetFloat("glucose", 0)
  211. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  212. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  213. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  214. conductivity, _ := c.GetFloat("conductivity", 0)
  215. remark := c.GetString("remark")
  216. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  217. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  218. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  219. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  220. body_fluid, _ := c.GetInt64("body_fluid", 0)
  221. special_medicine, _ := c.GetInt64("special_medicine", 0)
  222. special_medicine_other := c.GetString("special_medicine_other")
  223. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  224. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  225. blood_access, _ := c.GetInt64("blood_access", 0)
  226. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  227. body_fluid_other := c.GetString("body_fluid_other")
  228. target_ktv, _ := c.GetFloat("target_ktv", 0)
  229. niprocart, _ := c.GetInt64("niprocart", 0)
  230. jms, _ := c.GetInt64("jms", 0)
  231. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  232. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  233. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  234. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  235. filtryzer, _ := c.GetInt64("filtryzer", 0)
  236. dialyzers, _ := c.GetInt64("dialyzers", 0)
  237. injector, _ := c.GetInt64("injector", 0)
  238. bloodlines, _ := c.GetInt64("bloodlines", 0)
  239. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  240. safe_package, _ := c.GetInt64("package", 0)
  241. a_liquid, _ := c.GetInt64("a_liquid", 0)
  242. preImpules, _ := c.GetFloat("pre_impulse", 0)
  243. fmt.Println("", preImpules)
  244. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  245. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  246. blood := c.GetString("blood")
  247. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  248. dialysis_irrigation := c.GetString("dialysis_irrigation")
  249. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  250. displace_speed := c.GetString("displace_speed")
  251. illness, _ := c.GetInt64("illness")
  252. amylaceum := c.GetString("amylaceum")
  253. single_time := c.GetString("single_time")
  254. single_water := c.GetString("single_water")
  255. replacement_flow := c.GetString("replacement_flow")
  256. plasma_separator := c.GetString("plasma_separator")
  257. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  258. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  259. oxygen_flow := c.GetString("oxygen_flow")
  260. oxygen_time := c.GetString("oxygen_time")
  261. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  262. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  263. puncture_needle := c.GetString("puncture_needle")
  264. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  265. epo := c.GetString("epo")
  266. epo_count, _ := c.GetFloat("epo_count", 0)
  267. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  268. admin_user_id, _ := c.GetInt64("admin_user_id")
  269. is_water, _ := c.GetInt64("is_water")
  270. drhy_water := c.GetString("drhy_water")
  271. dry_water_hour := c.GetString("dry_water_hour")
  272. water_machine := c.GetString("water_machine")
  273. add_amount, _ := c.GetFloat("add_amount")
  274. reduce_amount, _ := c.GetFloat("reduce_amount")
  275. dialysis_remark := c.GetString("dialysis_remark")
  276. prescribing_number, _ := c.GetFloat("prescribing_number")
  277. treatment_remark := c.GetString("treatment_remark")
  278. prescription_sodium := c.GetString("prescription_sodium")
  279. start_sodium := c.GetString("start_sodium")
  280. sodium_curve := c.GetString("sodium_curve")
  281. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  282. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  283. prescription_water, _ := c.GetFloat("prescription_water")
  284. dialysis_strainer := c.GetString("dialysis_strainer")
  285. chaptalization := c.GetString("chaptalization")
  286. washing_time := c.GetString("washing_time")
  287. warsh_count := c.GetString("warsh_count")
  288. blood_access_part_id := c.GetString("blood_access_part_id")
  289. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  290. dialyzate := c.GetString("dialyzate")
  291. first_super, _ := c.GetInt64("first_super")
  292. is_sequential, _ := c.GetInt64("is_sequential")
  293. conduct := c.GetString("conduct")
  294. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  295. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  296. //if template.TemplateId == 2 || template.TemplateId == 6 {
  297. // if appRole.UserType == 3 {
  298. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  299. // if getPermissionErr != nil {
  300. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  301. // return
  302. // } else if headNursePermission == nil {
  303. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  304. // return
  305. // }
  306. // }
  307. //}
  308. goodList, _ := service.GetMobileGoodList(adminUserInfo.CurrentOrgId)
  309. var dialysis_dialyszers_id int64
  310. var dialysis_strainer_id int64
  311. var dialysis_irrigation_id int64
  312. if len(goodList) > 0 {
  313. for _, item := range goodList {
  314. if item.SpecificationName == dialysis_dialyszers {
  315. dialysis_dialyszers_id = item.ID
  316. }
  317. if item.SpecificationName == dialysis_irrigation {
  318. dialysis_irrigation_id = item.ID
  319. }
  320. if item.SpecificationName == dialysis_strainer {
  321. dialysis_strainer_id = item.ID
  322. }
  323. }
  324. }
  325. prescription := models.DialysisPrescription{
  326. UserOrgId: adminUserInfo.CurrentOrgId,
  327. PatientId: patient,
  328. RecordDate: recordDate.Unix(),
  329. ModeId: mode_id,
  330. DialysisDuration: dialysis_duration,
  331. Dialyzer: dialyzer,
  332. ReplacementTotal: replacement_total,
  333. PerfusionApparatus: perfusion_apparatus,
  334. BloodFlowVolume: blood_flow_volume,
  335. DewaterAmount: dewater_amount,
  336. DisplaceLiqui: displace_liqui,
  337. ReplacementWay: replacement_way,
  338. Anticoagulant: anticoagulant,
  339. AnticoagulantShouji: anticoagulant_shouji,
  340. AnticoagulantWeichi: anticoagulant_weichi,
  341. AnticoagulantZongliang: anticoagulant_zongliang,
  342. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  343. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  344. Kalium: kalium,
  345. Sodium: sodium,
  346. Calcium: calcium,
  347. Bicarbonate: bicarbonate,
  348. Glucose: glucose,
  349. // DryWeight: dry_weight,
  350. DialysateFlow: dialysate_flow,
  351. DialysateTemperature: dialysate_temperature,
  352. Conductivity: conductivity,
  353. Remark: remark,
  354. Status: 1,
  355. CreatedTime: time.Now().Unix(),
  356. UpdatedTime: time.Now().Unix(),
  357. DialysisDurationMinute: dialysisDurationMinute,
  358. DialysisDurationHour: dialysisDurationHour,
  359. TargetUltrafiltration: targetUltrafiltration,
  360. DialysateFormulation: dialysateFormulation,
  361. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  362. BodyFluid: body_fluid,
  363. SpecialMedicine: special_medicine,
  364. SpecialMedicineOther: special_medicine_other,
  365. DisplaceLiquiPart: displace_liqui_part,
  366. DisplaceLiquiValue: displace_liqui_value,
  367. BloodAccess: blood_access,
  368. Ultrafiltration: ultrafiltration,
  369. BodyFluidOther: body_fluid_other,
  370. TargetKtv: target_ktv,
  371. Niprocart: niprocart,
  372. Jms: jms,
  373. FistulaNeedleSet: fistula_needle_set,
  374. FistulaNeedleSet16: fistula_needle_set_16,
  375. Hemoperfusion: hemoperfusion,
  376. DialyserSterilised: dialyser_sterilised,
  377. Filtryzer: filtryzer,
  378. Dialyzers: dialyzers,
  379. Injector: injector,
  380. Bloodlines: bloodlines,
  381. TubingHemodialysis: tubing_hemodialysis,
  382. Package: safe_package,
  383. ALiquid: a_liquid,
  384. PreImpulse: preImpules,
  385. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  386. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  387. Blood: blood,
  388. DialysisDialyszers: dialysis_dialyszers,
  389. DialysisIrrigation: dialysis_irrigation,
  390. AntioxidantCommodityName: antioxidant_commodity_name,
  391. DisplaceSpeed: displace_speed,
  392. Illness: illness,
  393. Amylaceum: amylaceum,
  394. SingleTime: single_time,
  395. SingleWater: single_water,
  396. ReplacementFlow: replacement_flow,
  397. PlasmaSeparator: plasma_separator,
  398. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  399. OxygenFlow: oxygen_flow,
  400. OxygenUptake: oxygen_uptake,
  401. OxygenTime: oxygen_time,
  402. HemodialysisPipelines: hemodialysis_pipelines,
  403. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  404. PunctureNeedle: puncture_needle,
  405. PunctureNeedleCount: puncture_needle_count,
  406. Epo: epo,
  407. EpoCount: epo_count,
  408. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  409. AdminUserId: admin_user_id,
  410. IsWater: is_water,
  411. DrhyWater: drhy_water,
  412. DryWaterHour: dry_water_hour,
  413. WaterMachine: water_machine,
  414. AddAmount: add_amount,
  415. ReduceAmount: reduce_amount,
  416. DialysisRemark: dialysis_remark,
  417. PrescribingNumber: prescribing_number,
  418. TreatmentRemark: treatment_remark,
  419. PrescriptionSodium: prescription_sodium,
  420. StartSodium: start_sodium,
  421. SodiumCurve: sodium_curve,
  422. DialysisFluidFlow: dialysis_fluid_flow,
  423. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  424. PrescriptionWater: prescription_water,
  425. DialysisStrainer: dialysis_strainer,
  426. Chaptalization: chaptalization,
  427. WarshCount: warsh_count,
  428. WashingTime: washing_time,
  429. BloodAccessPartId: blood_access_part_id,
  430. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  431. Dialyzate: dialyzate,
  432. DialysisStrainerId: dialysis_strainer_id,
  433. DialysisIrrigationId: dialysis_irrigation_id,
  434. DialysisDialyszersId: dialysis_dialyszers_id,
  435. FirstSuper: first_super,
  436. IsSequential: is_sequential,
  437. Conduct: conduct,
  438. }
  439. if adminUserInfo.CurrentOrgId == 10721 {
  440. if prescription.ModeId == 2 {
  441. if prescription.ReplacementTotal == 0 {
  442. prescription.ReplacementTotal = 15
  443. }
  444. }
  445. }
  446. //长沙南雅医院,自动生成抗凝剂的临时处方
  447. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  448. if prescribing_number == 0 {
  449. prescribing_number = 1
  450. }
  451. advice := models.DoctorAdvice{
  452. UserOrgId: adminUserInfo.CurrentOrgId,
  453. PatientId: patient,
  454. GroupNo: 0,
  455. AdviceType: 2,
  456. RecordDate: recordDate.Unix(),
  457. AdviceDate: recordDate.Unix(),
  458. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  459. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  460. AdviceDesc: "",
  461. ReminderDate: 0,
  462. SingleDose: anticoagulant_zongliang,
  463. SingleDoseUnit: "iu",
  464. DrugSpec: 0,
  465. DrugSpecUnit: "",
  466. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  467. PrescribingNumberUnit: "支",
  468. DeliveryWay: "静脉注射",
  469. ExecutionFrequency: "上机前",
  470. AdviceDoctor: 0,
  471. Status: 1,
  472. CreatedTime: time.Now().Unix(),
  473. UpdatedTime: time.Now().Unix(),
  474. IsPrescription: 1,
  475. ExecutionState: 2,
  476. StopState: 2,
  477. IsSettle: 2,
  478. }
  479. // 查询排班信息
  480. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  481. if schedulePatient.ID > 0 {
  482. if schedulePatient.ScheduleType == 1 {
  483. advice.StartTime = recordDate.Unix() + 6.5*60*60
  484. }
  485. if schedulePatient.ScheduleType == 2 {
  486. advice.StartTime = recordDate.Unix() + 9*60*60
  487. }
  488. }
  489. // 抗凝剂名称
  490. switch anticoagulant {
  491. case 1:
  492. advice.AdviceName = "无肝素"
  493. break
  494. case 2:
  495. advice.AdviceName = "普通肝素"
  496. break
  497. case 3:
  498. advice.AdviceName = "低分子肝素"
  499. break
  500. case 4:
  501. advice.AdviceName = "阿加曲班"
  502. break
  503. case 5:
  504. advice.AdviceName = "枸橼酸钠"
  505. break
  506. case 6:
  507. advice.AdviceName = "低分子肝素钙"
  508. break
  509. case 7:
  510. advice.AdviceName = "低分子肝素钠"
  511. break
  512. case 8:
  513. advice.AdviceName = "依诺肝素"
  514. break
  515. case 9:
  516. advice.AdviceName = "达肝素"
  517. break
  518. case 10:
  519. advice.AdviceName = "体外抗凝"
  520. break
  521. case 11:
  522. advice.AdviceName = "那曲肝素"
  523. break
  524. case 12:
  525. advice.AdviceName = "无抗凝剂"
  526. break
  527. }
  528. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  529. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  530. advice.AdviceDoctor = appRole.AdminUserId
  531. }
  532. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  533. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  534. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  535. advice.AdviceName = "低分子肝素钠注射液"
  536. // 修改患者临时医嘱里的抗凝剂医嘱
  537. advice.ID = advicePrescription.ID
  538. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  539. //service.UpdateDoctorAdvice(&advice)
  540. } else {
  541. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  542. advice.AdviceName = "低分子肝素钠注射液"
  543. // 新增患者临时医嘱里的抗凝剂医嘱
  544. service.CreateDoctorAdvice(&advice)
  545. }
  546. }
  547. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  548. redis := service.RedisClient()
  549. //清空key 值
  550. redis.Set(key, "", time.Second)
  551. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  552. redis.Set(keyOne, "", time.Second)
  553. }
  554. if appRole.UserType == 2 || appRole.UserType == 1 {
  555. prescription.PrescriptionDoctor = appRole.AdminUserId
  556. }
  557. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  558. if dialysisPrescription.ID == 0 { //新增
  559. if mode_id > 0 {
  560. var str string
  561. //查找该机构用的是什么透析器
  562. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  563. if filedConfig.ID > 0 {
  564. str = dialyzerPerfusionApparatus
  565. } else {
  566. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  567. }
  568. if adminUserInfo.CurrentOrgId == 10346 {
  569. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  570. } else {
  571. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  572. }
  573. }
  574. prescription.Creater = adminUserInfo.AdminUser.Id
  575. //针对河间咸得
  576. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  577. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  578. prescription.DisplaceLiquiPart = 0
  579. prescription.DisplaceLiquiValue = 0
  580. }
  581. }
  582. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  583. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  584. }
  585. // 查询信息规挡的设置天数
  586. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  587. if infor.ID > 0 && infor.WeekDay > 0 {
  588. var cha_time int64
  589. timeNowStr := time.Now().Format("2006-01-02")
  590. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  591. //今日的日期减去设置的日期
  592. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  593. if cha_time >= recordDate.Unix() {
  594. //查询审核是否允许
  595. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  596. //申请状态不允许的情况 拒绝修改
  597. if infor.ApplicationStatus != 1 {
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  599. return
  600. }
  601. }
  602. }
  603. err := service.AddSigleRecord(&prescription)
  604. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  605. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  606. if len(monitorList) > 0 {
  607. var ultrafiltration_rate float64
  608. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  609. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  610. var replacement_rate float64
  611. //乘10 除10是为了保留一位小数
  612. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  613. var firstOpeateTime = monitorList[0].OperateTime
  614. for _, item := range monitorList {
  615. //超滤率
  616. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  617. //置换率
  618. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  619. //超滤量
  620. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  621. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  622. //置换量
  623. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  624. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  625. }
  626. }
  627. }
  628. //记录日志
  629. byterequest, _ := json.Marshal(prescription)
  630. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  631. UserOrgId: adminUserInfo.CurrentOrgId,
  632. Ctime: time.Now().Unix(),
  633. Mtime: 0,
  634. ErrLog: string(byterequest),
  635. AdminUserId: adminUserInfo.AdminUser.Id,
  636. RecordDate: prescription.RecordDate,
  637. PatientId: prescription.PatientId,
  638. Source: "电脑端新建处方",
  639. Status: 1,
  640. }
  641. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  642. //创建步骤表
  643. finish := models.XtDialysisFinish{
  644. IsFinish: 1,
  645. UserOrgId: adminUserInfo.CurrentOrgId,
  646. Status: 1,
  647. Ctime: time.Now().Unix(),
  648. Mtime: 0,
  649. Module: 1,
  650. RecordDate: recordDate.Unix(),
  651. Sourse: 1,
  652. PatientId: patient,
  653. }
  654. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  655. if dialysisFinish.ID == 0 {
  656. service.CreateDialysisFinish(finish)
  657. }
  658. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  659. redis := service.RedisClient()
  660. //清空key 值
  661. redis.Set(key, "", time.Second)
  662. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  663. redis.Set(keyTwo, "", time.Second)
  664. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  665. redis.Set(keyThree, "", time.Second)
  666. defer redis.Close()
  667. if err == nil {
  668. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  669. if updateErr != nil {
  670. utils.ErrorLog("%v", updateErr)
  671. }
  672. c.ServeSuccessJSON(map[string]interface{}{
  673. "prescription": &prescription,
  674. })
  675. } else {
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  677. }
  678. } else { //修改
  679. if mode_id > 0 {
  680. var str string
  681. //查找该机构用的是什么透析器
  682. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  683. if filedConfig.ID > 0 {
  684. str = dialyzerPerfusionApparatus
  685. } else {
  686. str = dialysis_dialyszers + "/" + dialysis_irrigation
  687. }
  688. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  689. }
  690. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  691. //if template.TemplateId == 1 {
  692. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  694. // if getPermissionErr != nil {
  695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  696. // return
  697. // } else if headNursePermission == nil {
  698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  699. // return
  700. // }
  701. // }
  702. //}
  703. if appRole.UserType == 2 || appRole.UserType == 1 {
  704. prescription_doctor := adminUserInfo.AdminUser.Id
  705. prescription.PrescriptionDoctor = prescription_doctor
  706. }
  707. if dialysisPrescription.Creater == 0 { //体重称
  708. prescription.Creater = adminUserInfo.AdminUser.Id
  709. } else {
  710. prescription.Creater = dialysisPrescription.Creater
  711. if adminUserInfo.CurrentOrgId == 9882 {
  712. if appRole.UserType == 2 || appRole.UserType == 1 {
  713. prescription_doctor := adminUserInfo.AdminUser.Id
  714. prescription.PrescriptionDoctor = prescription_doctor
  715. prescription.Creater = prescription_doctor
  716. }
  717. }
  718. }
  719. prescription.CreatedTime = dialysisPrescription.CreatedTime
  720. prescription.UpdatedTime = time.Now().Unix()
  721. prescription.Modifier = adminUserInfo.AdminUser.Id
  722. prescription.ID = dialysisPrescription.ID
  723. // 查询信息规挡的设置天数
  724. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  725. if infor.ID > 0 && infor.WeekDay > 0 {
  726. var cha_time int64
  727. timeNowStr := time.Now().Format("2006-01-02")
  728. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  729. //今日的日期减去设置的日期
  730. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  731. if cha_time >= recordDate.Unix() {
  732. //查询审核是否允许
  733. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  734. //申请状态不允许的情况 拒绝修改
  735. if infor.ApplicationStatus != 1 {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  737. return
  738. }
  739. }
  740. }
  741. if adminUserInfo.CurrentOrgId == 10721 {
  742. if prescription.ModeId == 2 {
  743. if prescription.ReplacementTotal == 0 {
  744. prescription.ReplacementTotal = 15
  745. }
  746. }
  747. }
  748. updateErr := service.UpDateDialysisPrescription(&prescription)
  749. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  750. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  751. if len(monitorList) > 0 {
  752. var ultrafiltration_rate float64
  753. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  754. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  755. var replacement_rate float64
  756. //乘10 除10是为了保留一位小数
  757. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  758. var firstOpeateTime = monitorList[0].OperateTime
  759. for _, item := range monitorList {
  760. //超滤率
  761. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  762. //置换率
  763. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  764. //超滤量
  765. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  766. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  767. //置换量
  768. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  769. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  770. }
  771. }
  772. }
  773. //记录日志
  774. byterequest, _ := json.Marshal(prescription)
  775. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  776. UserOrgId: adminUserInfo.CurrentOrgId,
  777. Ctime: time.Now().Unix(),
  778. Mtime: 0,
  779. ErrLog: string(byterequest),
  780. AdminUserId: adminUserInfo.AdminUser.Id,
  781. RecordDate: prescription.RecordDate,
  782. PatientId: prescription.PatientId,
  783. Source: "电脑端修改处方",
  784. Status: 1,
  785. }
  786. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  787. //创建步骤表
  788. finish := models.XtDialysisFinish{
  789. IsFinish: 1,
  790. UserOrgId: adminUserInfo.CurrentOrgId,
  791. Status: 1,
  792. Ctime: time.Now().Unix(),
  793. Mtime: 0,
  794. Module: 1,
  795. RecordDate: recordDate.Unix(),
  796. Sourse: 1,
  797. PatientId: patient,
  798. }
  799. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  800. if dialysisFinish.ID == 0 {
  801. service.CreateDialysisFinish(finish)
  802. }
  803. //修改处方
  804. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  805. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  806. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  807. if advicePrescription.ID > 0 {
  808. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  809. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  810. redis := service.RedisClient()
  811. defer redis.Close()
  812. //清空key 值
  813. redis.Set(key, "", time.Second)
  814. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  815. redis.Set(keyOne, "", time.Second)
  816. }
  817. }
  818. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  819. redis := service.RedisClient()
  820. defer redis.Close()
  821. //清空key 值
  822. redis.Set(key, "", time.Second)
  823. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  824. redis.Set(keyOne, "", time.Second)
  825. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  826. redis.Set(keyThree, "", time.Second)
  827. if updateErr == nil {
  828. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  829. if updateErr != nil {
  830. utils.ErrorLog("%v", updateErr)
  831. }
  832. c.ServeSuccessJSON(map[string]interface{}{
  833. "prescription": &prescription,
  834. })
  835. } else {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  837. }
  838. }
  839. }
  840. func (c *DialysisApiController) PostSoulution() {
  841. patient, _ := c.GetInt64("patient", 0)
  842. recordDateStr := c.GetString("record_date")
  843. if patient <= 0 {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  845. return
  846. }
  847. adminUserInfo := c.GetAdminUserInfo()
  848. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  849. if patientInfo.ID == 0 {
  850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  851. return
  852. }
  853. if len(recordDateStr) == 0 {
  854. recordDateStr = time.Now().Format("2006-01-02")
  855. }
  856. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  857. if parseDateErr != nil {
  858. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  860. return
  861. }
  862. mode_id, _ := c.GetInt64("mode_id", 0)
  863. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  864. dialyzer, _ := c.GetInt64("dialyzer", 0)
  865. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  866. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  867. replacement_total, _ := c.GetFloat("replacement_total", 0)
  868. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  869. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  870. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  871. replacement_way, _ := c.GetInt64("replacement_way", 0)
  872. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  873. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  874. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  875. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  876. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  877. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  878. kalium, _ := c.GetFloat("kalium", 0)
  879. sodium, _ := c.GetFloat("sodium", 0)
  880. calcium, _ := c.GetFloat("calcium", 0)
  881. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  882. glucose, _ := c.GetFloat("glucose", 0)
  883. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  884. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  885. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  886. conductivity, _ := c.GetFloat("conductivity", 0)
  887. remark := c.GetString("remark")
  888. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  889. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  890. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  891. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  892. body_fluid, _ := c.GetInt64("body_fluid", 0)
  893. special_medicine, _ := c.GetInt64("special_medicine", 0)
  894. special_medicine_other := c.GetString("special_medicine_other")
  895. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  896. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  897. blood_access, _ := c.GetInt64("blood_access", 0)
  898. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  899. body_fluid_other := c.GetString("body_fluid_other")
  900. target_ktv, _ := c.GetFloat("target_ktv", 0)
  901. niprocart, _ := c.GetInt64("niprocart", 0)
  902. jms, _ := c.GetInt64("jms", 0)
  903. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  904. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  905. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  906. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  907. filtryzer, _ := c.GetInt64("filtryzer", 0)
  908. dialyzers, _ := c.GetInt64("dialyzers", 0)
  909. injector, _ := c.GetInt64("injector", 0)
  910. bloodlines, _ := c.GetInt64("bloodlines", 0)
  911. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  912. safe_package, _ := c.GetInt64("package", 0)
  913. a_liquid, _ := c.GetInt64("a_liquid", 0)
  914. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  915. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  916. blood := c.GetString("blood")
  917. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  918. dialysis_irrigation := c.GetString("dialysis_irrigation")
  919. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  920. displace_speed := c.GetString("displace_speed")
  921. illness, _ := c.GetInt64("illness")
  922. amylaceum := c.GetString("amylaceum")
  923. single_time := c.GetString("single_time")
  924. single_water := c.GetString("single_water")
  925. replacement_flow := c.GetString("replacement_flow")
  926. plasma_separator := c.GetString("plasma_separator")
  927. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  928. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  929. oxygen_flow := c.GetString("oxygen_flow")
  930. oxygen_time := c.GetString("oxygen_time")
  931. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  932. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  933. puncture_needle := c.GetString("puncture_needle")
  934. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  935. epo := c.GetString("epo")
  936. epo_count, _ := c.GetFloat("epo_count", 0)
  937. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  938. impulse := c.GetString("impulse")
  939. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  940. admin_user_id, _ := c.GetInt64("admin_user_id")
  941. fmt.Println("", preImpules)
  942. is_water, _ := c.GetInt64("is_water")
  943. dry_water_hour := c.GetString("dry_water_hour")
  944. drhy_water := c.GetString("drhy_water")
  945. water_machine := c.GetString("water_machine")
  946. add_amount, _ := c.GetFloat("add_amount")
  947. reduce_amount, _ := c.GetFloat("reduce_amount")
  948. dialysis_remark := c.GetString("dialysis_remark")
  949. prescribing_number, _ := c.GetFloat("prescribing_number")
  950. treatment_remark := c.GetString("treatment_remark")
  951. prescription_sodium := c.GetString("prescription_sodium")
  952. start_sodium := c.GetString("start_sodium")
  953. sodium_curve := c.GetString("sodium_curve")
  954. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  955. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  956. prescription_water, _ := c.GetFloat("prescription_water")
  957. dialysis_strainer := c.GetString("dialysis_strainer")
  958. chaptalization := c.GetString("chaptalization")
  959. warsh_count := c.GetString("warsh_count")
  960. washing_time := c.GetString("washing_time")
  961. blood_access_part_id := c.GetString("blood_access_part_id")
  962. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  963. dialyzate := c.GetString("dialyzate")
  964. first_super, _ := c.GetInt64("first_super")
  965. is_sequential, _ := c.GetInt64("is_sequential")
  966. conduct := c.GetString("conduct")
  967. var prescription_doctor int64
  968. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  969. if appRole.UserType == 2 || appRole.UserType == 1 {
  970. prescription_doctor = appRole.AdminUserId
  971. }
  972. if mode_id > 0 {
  973. var str string
  974. //查找该机构用的是什么透析器
  975. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  976. if filedConfig.ID > 0 {
  977. str = dialyzerPerfusionApparatus
  978. } else {
  979. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  980. }
  981. if adminUserInfo.CurrentOrgId == 10346 {
  982. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  983. } else {
  984. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  985. }
  986. }
  987. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  988. //
  989. //if template.TemplateId == 2 || template.TemplateId == 6 {
  990. // if appRole.UserType == 3 {
  991. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  992. // if getPermissionErr != nil {
  993. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  994. // return
  995. // } else if headNursePermission == nil {
  996. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  997. // return
  998. // }
  999. // }
  1000. //}
  1001. // 查询信息规挡的设置天数
  1002. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1003. if infor.ID > 0 && infor.WeekDay > 0 {
  1004. var cha_time int64
  1005. timeNowStr := time.Now().Format("2006-01-02")
  1006. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1007. //今日的日期减去设置的日期
  1008. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1009. if cha_time >= recordDate.Unix() {
  1010. //查询审核是否允许
  1011. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  1012. //申请状态不允许的情况 拒绝修改
  1013. if infor.ApplicationStatus != 1 {
  1014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1015. return
  1016. }
  1017. }
  1018. }
  1019. goodList, _ := service.GetMobileGoodList(adminUserInfo.CurrentOrgId)
  1020. var dialysis_dialyszers_id int64
  1021. var dialysis_strainer_id int64
  1022. var dialysis_irrigation_id int64
  1023. if len(goodList) > 0 {
  1024. for _, item := range goodList {
  1025. if item.SpecificationName == dialysis_dialyszers {
  1026. dialysis_dialyszers_id = item.ID
  1027. }
  1028. if item.SpecificationName == dialysis_irrigation {
  1029. dialysis_irrigation_id = item.ID
  1030. }
  1031. if item.SpecificationName == dialysis_strainer {
  1032. dialysis_strainer_id = item.ID
  1033. }
  1034. }
  1035. }
  1036. prescription := models.DialysisPrescription{
  1037. UserOrgId: adminUserInfo.CurrentOrgId,
  1038. PatientId: patient,
  1039. RecordDate: recordDate.Unix(),
  1040. ModeId: mode_id,
  1041. DialysisDuration: dialysis_duration,
  1042. Dialyzer: dialyzer,
  1043. PerfusionApparatus: perfusion_apparatus,
  1044. BloodFlowVolume: blood_flow_volume,
  1045. DewaterAmount: dewater_amount,
  1046. DisplaceLiqui: displace_liqui,
  1047. ReplacementWay: replacement_way,
  1048. Anticoagulant: anticoagulant,
  1049. AnticoagulantShouji: anticoagulant_shouji,
  1050. AnticoagulantWeichi: anticoagulant_weichi,
  1051. AnticoagulantZongliang: anticoagulant_zongliang,
  1052. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1053. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1054. Kalium: kalium,
  1055. Sodium: sodium,
  1056. Calcium: calcium,
  1057. Bicarbonate: bicarbonate,
  1058. Glucose: glucose,
  1059. // DryWeight: dry_weight,
  1060. DialysateFlow: dialysate_flow,
  1061. DialysateTemperature: dialysate_temperature,
  1062. Conductivity: conductivity,
  1063. Remark: remark,
  1064. PrescriptionDoctor: prescription_doctor,
  1065. Status: 1,
  1066. CreatedTime: time.Now().Unix(),
  1067. UpdatedTime: time.Now().Unix(),
  1068. DialysisDurationMinute: dialysisDurationMinute,
  1069. DialysisDurationHour: dialysisDurationHour,
  1070. TargetUltrafiltration: targetUltrafiltration,
  1071. DialysateFormulation: dialysateFormulation,
  1072. ReplacementTotal: replacement_total,
  1073. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1074. BodyFluid: body_fluid,
  1075. SpecialMedicine: special_medicine,
  1076. SpecialMedicineOther: special_medicine_other,
  1077. DisplaceLiquiPart: displace_liqui_part,
  1078. DisplaceLiquiValue: displace_liqui_value,
  1079. BloodAccess: blood_access,
  1080. Ultrafiltration: ultrafiltration,
  1081. BodyFluidOther: body_fluid_other,
  1082. TargetKtv: target_ktv,
  1083. Niprocart: niprocart,
  1084. Jms: jms,
  1085. FistulaNeedleSet: fistula_needle_set,
  1086. FistulaNeedleSet16: fistula_needle_set_16,
  1087. Hemoperfusion: hemoperfusion,
  1088. DialyserSterilised: dialyser_sterilised,
  1089. Filtryzer: filtryzer,
  1090. Dialyzers: dialyzers,
  1091. Injector: injector,
  1092. Bloodlines: bloodlines,
  1093. TubingHemodialysis: tubing_hemodialysis,
  1094. Package: safe_package,
  1095. ALiquid: a_liquid,
  1096. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1097. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1098. Blood: blood,
  1099. DialysisIrrigation: dialysis_irrigation,
  1100. DialysisDialyszers: dialysis_dialyszers,
  1101. AntioxidantCommodityName: antioxidant_commodity_name,
  1102. DisplaceSpeed: displace_speed,
  1103. Illness: illness,
  1104. Amylaceum: amylaceum,
  1105. SingleTime: single_time,
  1106. SingleWater: single_water,
  1107. ReplacementFlow: replacement_flow,
  1108. PlasmaSeparator: plasma_separator,
  1109. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1110. OxygenTime: oxygen_time,
  1111. OxygenUptake: oxygen_uptake,
  1112. OxygenFlow: oxygen_flow,
  1113. HemodialysisPipelines: hemodialysis_pipelines,
  1114. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1115. PunctureNeedle: puncture_needle,
  1116. PunctureNeedleCount: puncture_needle_count,
  1117. Epo: epo,
  1118. EpoCount: epo_count,
  1119. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1120. PreImpulse: preImpules,
  1121. AdminUserId: admin_user_id,
  1122. IsWater: is_water,
  1123. DryWaterHour: dry_water_hour,
  1124. DrhyWater: drhy_water,
  1125. WaterMachine: water_machine,
  1126. AddAmount: add_amount,
  1127. ReduceAmount: reduce_amount,
  1128. DialysisRemark: dialysis_remark,
  1129. PrescribingNumber: prescribing_number,
  1130. StartSodium: start_sodium,
  1131. PrescriptionSodium: prescription_sodium,
  1132. SodiumCurve: sodium_curve,
  1133. TreatmentRemark: treatment_remark,
  1134. DialysisFluidFlow: dialysis_fluid_flow,
  1135. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1136. PrescriptionWater: prescription_water,
  1137. DialysisStrainer: dialysis_strainer,
  1138. Chaptalization: chaptalization,
  1139. WarshCount: warsh_count,
  1140. WashingTime: washing_time,
  1141. BloodAccessPartId: blood_access_part_id,
  1142. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1143. Dialyzate: dialyzate,
  1144. DialysisDialyszersId: dialysis_dialyszers_id,
  1145. DialysisIrrigationId: dialysis_irrigation_id,
  1146. DialysisStrainerId: dialysis_strainer_id,
  1147. FirstSuper: first_super,
  1148. IsSequential: is_sequential,
  1149. Conduct: conduct,
  1150. }
  1151. if prescription.Anticoagulant == 0 {
  1152. prescription.Anticoagulant = 3
  1153. }
  1154. //查询最近透析准备表里是否存在 透析器 灌流器
  1155. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1156. //
  1157. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1158. //
  1159. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  1160. //if len(mation)>0{
  1161. // for _, item := range splitStr {
  1162. // for _,it := range mation{
  1163. // if(item == it.SpecificationName){
  1164. //
  1165. // //查询最近一次的透析器
  1166. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1167. //
  1168. // if errcode == gorm.ErrRecordNotFound{
  1169. // //插入数据
  1170. // prepare := models.DialysisBeforePrepare{
  1171. // UserOrgId: adminUserInfo.CurrentOrgId,
  1172. // PatientId: patient,
  1173. // RecordDate: recordDate.Unix(),
  1174. // GoodTypeId: it.GoodTypeId,
  1175. // GoodId: it.ID,
  1176. // Count: 1,
  1177. // Ctime: time.Now().Unix(),
  1178. // Creater: adminUserInfo.AdminUser.Id,
  1179. // Status:1,
  1180. //
  1181. // }
  1182. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1183. // fmt.Println("",errcode)
  1184. // }
  1185. // }
  1186. // }
  1187. //
  1188. // }
  1189. //
  1190. // for _, item := range splitIrrigation {
  1191. // for _,it := range mation{
  1192. // if(item == it.SpecificationName){
  1193. // //查询最近一次的透析器
  1194. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1195. // if errcode == gorm.ErrRecordNotFound{
  1196. // //插入数据
  1197. // prepare := models.DialysisBeforePrepare{
  1198. // UserOrgId: adminUserInfo.CurrentOrgId,
  1199. // PatientId: patient,
  1200. // RecordDate: recordDate.Unix(),
  1201. // GoodTypeId: it.GoodTypeId,
  1202. // GoodId: it.ID,
  1203. // Count: 1,
  1204. // Ctime: time.Now().Unix(),
  1205. // Creater: adminUserInfo.AdminUser.Id,
  1206. // Status:1,
  1207. //
  1208. // }
  1209. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1210. // fmt.Println(errcode)
  1211. // }
  1212. // }
  1213. // }
  1214. // }
  1215. //}
  1216. //创建步骤表
  1217. finish := models.XtDialysisFinish{
  1218. IsFinish: 1,
  1219. UserOrgId: adminUserInfo.CurrentOrgId,
  1220. Status: 1,
  1221. Ctime: time.Now().Unix(),
  1222. Mtime: 0,
  1223. Module: 1,
  1224. RecordDate: recordDate.Unix(),
  1225. Sourse: 1,
  1226. PatientId: patient,
  1227. }
  1228. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1229. if dialysisFinish.ID == 0 {
  1230. service.CreateDialysisFinish(finish)
  1231. }
  1232. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1233. if dialysisPrescription.ID == 0 { //新增
  1234. if appRole.UserType == 2 || appRole.UserType == 1 {
  1235. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1236. }
  1237. prescription.Creater = adminUserInfo.AdminUser.Id
  1238. } else { //修改
  1239. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1240. //if template.TemplateId == 1 {
  1241. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1242. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1243. // if getPermissionErr != nil {
  1244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1245. // return
  1246. // } else if headNursePermission == nil {
  1247. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1248. // return
  1249. // }
  1250. // }
  1251. //}
  1252. if appRole.UserType == 2 || appRole.UserType == 1 {
  1253. prescription_doctor := adminUserInfo.AdminUser.Id
  1254. prescription.PrescriptionDoctor = prescription_doctor
  1255. } else {
  1256. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1257. }
  1258. if dialysisPrescription.Creater == 0 {
  1259. prescription.Creater = adminUserInfo.AdminUser.Id
  1260. } else {
  1261. prescription.Creater = dialysisPrescription.Creater
  1262. if appRole.UserType == 2 || appRole.UserType == 1 {
  1263. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1264. prescription.Creater = adminUserInfo.AdminUser.Id
  1265. }
  1266. }
  1267. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1268. prescription.UpdatedTime = time.Now().Unix()
  1269. prescription.Modifier = adminUserInfo.AdminUser.Id
  1270. prescription.ID = dialysisPrescription.ID
  1271. }
  1272. solution := models.DialysisSolution{
  1273. RegistrarsId: adminUserInfo.AdminUser.Id,
  1274. UserOrgId: adminUserInfo.CurrentOrgId,
  1275. Doctor: prescription_doctor,
  1276. PatientId: patient,
  1277. ModeId: mode_id,
  1278. DialysisDuration: dialysis_duration,
  1279. PerfusionApparatus: perfusion_apparatus,
  1280. BloodFlowVolume: blood_flow_volume,
  1281. Dewater: dewater_amount,
  1282. DisplaceLiqui: displace_liqui,
  1283. ReplacementWay: replacement_way,
  1284. Anticoagulant: anticoagulant,
  1285. AnticoagulantShouji: anticoagulant_shouji,
  1286. AnticoagulantWeichi: anticoagulant_weichi,
  1287. AnticoagulantZongliang: anticoagulant_zongliang,
  1288. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1289. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1290. Kalium: kalium,
  1291. Sodium: sodium,
  1292. Calcium: calcium,
  1293. Bicarbonate: bicarbonate,
  1294. Glucose: glucose,
  1295. // DryWeight: dry_weight,
  1296. DialysateFlow: dialysate_flow,
  1297. DialysateTemperature: dialysate_temperature,
  1298. Conductivity: conductivity,
  1299. Remark: remark,
  1300. Status: 1,
  1301. CreatedTime: time.Now().Unix(),
  1302. UpdatedTime: time.Now().Unix(),
  1303. DialysisDurationMinute: dialysisDurationMinute,
  1304. DialysisDurationHour: dialysisDurationHour,
  1305. TargetUltrafiltration: targetUltrafiltration,
  1306. DialysateFormulation: dialysateFormulation,
  1307. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1308. BodyFluid: body_fluid,
  1309. SpecialMedicine: special_medicine,
  1310. SpecialMedicineOther: special_medicine_other,
  1311. DisplaceLiquiPart: displace_liqui_part,
  1312. DisplaceLiquiValue: displace_liqui_value,
  1313. BloodAccess: blood_access,
  1314. Ultrafiltration: ultrafiltration,
  1315. BodyFluidOther: body_fluid_other,
  1316. ReplacementTotal: replacement_total,
  1317. TargetKtv: target_ktv,
  1318. DialysisIrrigation: dialysis_irrigation,
  1319. DialysisDialyszers: dialysis_dialyszers,
  1320. HemodialysisPipelines: hemodialysis_pipelines,
  1321. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1322. PunctureNeedle: puncture_needle,
  1323. PunctureNeedleCount: puncture_needle_count,
  1324. Epo: epo,
  1325. EpoCount: epo_count,
  1326. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1327. OxygenUptake: oxygen_uptake,
  1328. OxygenFlow: oxygen_flow,
  1329. OxygenTime: oxygen_time,
  1330. PreImpulse: preImpules,
  1331. SolutionStatus: 1,
  1332. DialysisRemark: dialysis_remark,
  1333. PrescribingNumber: prescribing_number,
  1334. StartSodium: start_sodium,
  1335. PrescriptionSodium: prescription_sodium,
  1336. SodiumCurve: sodium_curve,
  1337. TreatmentRemark: treatment_remark,
  1338. DialysisFluidFlow: dialysis_fluid_flow,
  1339. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1340. PrescriptionWater: prescribing_number,
  1341. DialysisStrainer: dialysis_strainer,
  1342. Chaptalization: chaptalization,
  1343. WarshCount: warsh_count,
  1344. WashingTime: washing_time,
  1345. BloodAccessPartId: blood_access_part_id,
  1346. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1347. Dialyzate: dialyzate,
  1348. DialysisDialyszersId: dialysis_dialyszers_id,
  1349. DialysisIrrigationId: dialysis_irrigation_id,
  1350. DialysisStrainerId: dialysis_strainer_id,
  1351. FirstSuper: first_super,
  1352. IsSequential: is_sequential,
  1353. Conduct: conduct,
  1354. }
  1355. if solution.Anticoagulant == 0 {
  1356. solution.Anticoagulant = 3
  1357. }
  1358. //针对河间咸得
  1359. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1360. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1361. prescription.DisplaceLiquiPart = 0
  1362. prescription.DisplaceLiquiValue = 0
  1363. }
  1364. }
  1365. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1366. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1367. solution.DisplaceLiquiPart = 0
  1368. solution.DisplaceLiquiValue = 0
  1369. }
  1370. }
  1371. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1372. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1373. }
  1374. if adminUserInfo.CurrentOrgId == 10721 {
  1375. if prescription.ModeId == 2 {
  1376. if prescription.ReplacementTotal == 0 {
  1377. prescription.ReplacementTotal = 15
  1378. }
  1379. }
  1380. }
  1381. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1382. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  1383. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  1384. if len(monitorList) > 0 {
  1385. var ultrafiltration_rate float64
  1386. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1387. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  1388. var replacement_rate float64
  1389. //乘10 除10是为了保留一位小数
  1390. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  1391. var firstOpeateTime = monitorList[0].OperateTime
  1392. for _, item := range monitorList {
  1393. //超滤率
  1394. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  1395. //置换率
  1396. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  1397. //超滤量
  1398. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  1399. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  1400. //置换量
  1401. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  1402. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  1403. }
  1404. }
  1405. }
  1406. //记录日志
  1407. byterequest, _ := json.Marshal(prescription)
  1408. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  1409. UserOrgId: adminUserInfo.CurrentOrgId,
  1410. Ctime: time.Now().Unix(),
  1411. Mtime: 0,
  1412. ErrLog: string(byterequest),
  1413. AdminUserId: adminUserInfo.AdminUser.Id,
  1414. RecordDate: prescription.RecordDate,
  1415. PatientId: prescription.PatientId,
  1416. Source: "电脑端新增长期处方",
  1417. Status: 1,
  1418. }
  1419. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  1420. //创建步骤表
  1421. finishOne := models.XtDialysisFinish{
  1422. IsFinish: 1,
  1423. UserOrgId: adminUserInfo.CurrentOrgId,
  1424. Status: 1,
  1425. Ctime: time.Now().Unix(),
  1426. Mtime: 0,
  1427. Module: 1,
  1428. RecordDate: recordDate.Unix(),
  1429. Sourse: 1,
  1430. PatientId: patient,
  1431. }
  1432. dialysisFinishOne, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1433. if dialysisFinishOne.ID == 0 {
  1434. service.CreateDialysisFinish(finishOne)
  1435. }
  1436. //获取最新1条
  1437. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1438. //更新状态
  1439. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1440. //长沙南雅医院,自动生成抗凝剂的临时处方
  1441. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1442. if prescribing_number == 0 {
  1443. prescribing_number = 1
  1444. }
  1445. advice := models.DoctorAdvice{
  1446. UserOrgId: adminUserInfo.CurrentOrgId,
  1447. PatientId: patient,
  1448. GroupNo: 0,
  1449. AdviceType: 2,
  1450. RecordDate: recordDate.Unix(),
  1451. AdviceDate: recordDate.Unix(),
  1452. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1453. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1454. AdviceDesc: "",
  1455. ReminderDate: 0,
  1456. SingleDose: anticoagulant_zongliang,
  1457. SingleDoseUnit: "iu",
  1458. DrugSpec: 0,
  1459. DrugSpecUnit: "",
  1460. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1461. PrescribingNumberUnit: "支",
  1462. DeliveryWay: "静脉注射",
  1463. ExecutionFrequency: "上机前",
  1464. AdviceDoctor: 0,
  1465. Status: 1,
  1466. CreatedTime: time.Now().Unix(),
  1467. UpdatedTime: time.Now().Unix(),
  1468. IsPrescription: 1,
  1469. ExecutionState: 2,
  1470. StopState: 2,
  1471. IsSettle: 2,
  1472. }
  1473. // 查询排班信息
  1474. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1475. if schedulePatient.ID > 0 {
  1476. if schedulePatient.ScheduleType == 1 {
  1477. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1478. }
  1479. if schedulePatient.ScheduleType == 2 {
  1480. advice.StartTime = recordDate.Unix() + 9*60*60
  1481. }
  1482. }
  1483. // 抗凝剂名称
  1484. switch anticoagulant {
  1485. case 1:
  1486. advice.AdviceName = "无肝素"
  1487. break
  1488. case 2:
  1489. advice.AdviceName = "普通肝素"
  1490. break
  1491. case 3:
  1492. advice.AdviceName = "低分子肝素"
  1493. break
  1494. case 4:
  1495. advice.AdviceName = "阿加曲班"
  1496. break
  1497. case 5:
  1498. advice.AdviceName = "枸橼酸钠"
  1499. break
  1500. case 6:
  1501. advice.AdviceName = "低分子肝素钙"
  1502. break
  1503. case 7:
  1504. advice.AdviceName = "低分子肝素钠"
  1505. break
  1506. case 8:
  1507. advice.AdviceName = "依诺肝素"
  1508. break
  1509. case 9:
  1510. advice.AdviceName = "达肝素"
  1511. break
  1512. case 10:
  1513. advice.AdviceName = "体外抗凝"
  1514. break
  1515. case 11:
  1516. advice.AdviceName = "那曲肝素"
  1517. break
  1518. case 12:
  1519. advice.AdviceName = "无抗凝剂"
  1520. break
  1521. }
  1522. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1523. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1524. advice.AdviceDoctor = appRole.AdminUserId
  1525. }
  1526. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1527. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1528. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1529. advice.AdviceName = "低分子肝素钠注射液"
  1530. // 修改患者临时医嘱里的抗凝剂医嘱
  1531. advice.ID = advicePrescription.ID
  1532. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1533. } else {
  1534. // 新增患者临时医嘱里的抗凝剂医嘱
  1535. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1536. advice.AdviceName = "低分子肝素钠注射液"
  1537. service.CreateDoctorAdvice(&advice)
  1538. }
  1539. }
  1540. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1541. redis := service.RedisClient()
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. }
  1547. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1548. redis := service.RedisClient()
  1549. //清空key 值
  1550. redis.Set(key, "", time.Second)
  1551. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1552. //清空key 值
  1553. redis.Set(keyOne, "", time.Second)
  1554. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1555. redis.Set(keyTwo, "", time.Second)
  1556. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1557. redis.Set(keyThree, "", time.Second)
  1558. defer redis.Close()
  1559. if err == nil {
  1560. c.ServeSuccessJSON(map[string]interface{}{
  1561. "solution": &solution,
  1562. "prescription": &prescription,
  1563. })
  1564. } else {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1566. }
  1567. }
  1568. func (c *DialysisApiController) PostDouleCheck() {
  1569. id, _ := c.GetInt64("patient", 0)
  1570. recordDateStr := c.GetString("record_date")
  1571. checkTimeStr := c.GetString("check_time")
  1572. firstCheckTimeStr := c.GetString("first_check_time")
  1573. creater, _ := c.GetInt64("creater", 0)
  1574. modifier, _ := c.GetInt64("modifier", 0)
  1575. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1576. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1577. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1578. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1579. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1580. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1581. vascular_access_desc := c.GetString("vascular_access_desc")
  1582. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1583. collator, _ := c.GetInt64("collator", 0)
  1584. employee_number := c.GetString("employee_number")
  1585. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1586. needle_batch_number := c.GetString("needle_batch_number")
  1587. if id <= 0 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1589. return
  1590. }
  1591. adminUserInfo := c.GetAdminUserInfo()
  1592. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1593. if patient.ID == 0 {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1595. return
  1596. }
  1597. if len(recordDateStr) == 0 {
  1598. recordDateStr = time.Now().Format("2006-01-02")
  1599. }
  1600. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1601. if parseDateErr != nil {
  1602. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1604. return
  1605. }
  1606. var checkDate int64
  1607. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1608. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1609. if employee_number != list.JobNumber {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1611. return
  1612. }
  1613. }
  1614. if len(checkTimeStr) == 0 {
  1615. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1616. checkDate = 0
  1617. } else {
  1618. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1619. checkDate = checkDateUnix.Unix()
  1620. }
  1621. var firstCheckTimeDate int64
  1622. if len(firstCheckTimeStr) == 0 {
  1623. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1624. firstCheckTimeDate = 0
  1625. } else {
  1626. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1627. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1628. }
  1629. doubleCheck := models.DoubleCheck{
  1630. UserOrgId: adminUserInfo.CurrentOrgId,
  1631. PatientId: id,
  1632. DialysisItemCheck: dialysis_item_check,
  1633. DialysisParameterCheck: dialysis_parameter_check,
  1634. VascularAccessVerification: vascular_access_verification,
  1635. PipelineConnectionCheck: pipeline_connection_check,
  1636. DialysisItemDesc: dialysis_item_desc,
  1637. DialysisParameterDesc: dialysis_parameter_desc,
  1638. VascularAccessDesc: vascular_access_desc,
  1639. PipelineConnectionDesc: pipeline_connection_desc,
  1640. Collator: collator,
  1641. Status: 1,
  1642. CreatedTime: time.Now().Unix(),
  1643. UpdatedTime: time.Now().Unix(),
  1644. CheckDate: recordDate.Unix(),
  1645. EmployeeNumber: employee_number,
  1646. DialyzerBatchNumber: dialyzer_batch_number,
  1647. NeedleBatchNumber: needle_batch_number,
  1648. }
  1649. // 查询信息规挡的设置天数
  1650. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1651. if infor.ID > 0 && infor.WeekDay > 0 {
  1652. var cha_time int64
  1653. timeNowStr := time.Now().Format("2006-01-02")
  1654. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1655. //今日的日期减去设置的日期
  1656. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1657. if cha_time >= recordDate.Unix() {
  1658. //查询审核是否允许
  1659. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1660. //申请状态不允许的情况 拒绝修改
  1661. if infor.ApplicationStatus != 1 {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1663. return
  1664. }
  1665. }
  1666. }
  1667. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1668. if check.ID == 0 { //新增
  1669. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1670. doubleCheck.CheckTime = checkDate
  1671. doubleCheck.Creater = creater
  1672. doubleCheck.Modifier = modifier
  1673. err := service.AddSigleDoubleCheck(&doubleCheck)
  1674. //创建步骤表
  1675. finish := models.XtDialysisFinish{
  1676. IsFinish: 1,
  1677. UserOrgId: adminUserInfo.CurrentOrgId,
  1678. Status: 1,
  1679. Ctime: time.Now().Unix(),
  1680. Mtime: 0,
  1681. Module: 5,
  1682. RecordDate: recordDate.Unix(),
  1683. Sourse: 1,
  1684. PatientId: id,
  1685. }
  1686. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 5, id)
  1687. if dialysisFinish.ID == 0 {
  1688. service.CreateDialysisFinish(finish)
  1689. }
  1690. // 查询信息规挡的设置天数
  1691. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1692. if infor.ID > 0 {
  1693. var cha_time int64
  1694. timeNowStr := time.Now().Format("2006-01-02")
  1695. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1696. //今日的日期减去设置的日期
  1697. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1698. if cha_time >= recordDate.Unix() {
  1699. //查询审核是否允许
  1700. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1701. //申请状态不允许的情况 拒绝修改
  1702. if infor.ApplicationStatus != 1 {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1704. return
  1705. }
  1706. }
  1707. }
  1708. //针对溪康
  1709. if adminUserInfo.CurrentOrgId == 10721 {
  1710. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1711. if len(adviceInfoList) > 0 {
  1712. for _, item := range adviceInfoList {
  1713. service.UpdateHisAdviceList(item.ID, creater)
  1714. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1715. redis := service.RedisClient()
  1716. //清空key 值
  1717. redis.Set(key, "", time.Second)
  1718. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1719. redis.Set(keyTwo, "", time.Second)
  1720. theTime := time.Now()
  1721. recordDate := theTime.Format("2006-01-02")
  1722. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1723. redis.Set(keyFour, "", time.Second)
  1724. defer redis.Close()
  1725. }
  1726. }
  1727. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1728. if len(adviceList) > 0 {
  1729. for _, item := range adviceList {
  1730. service.UpdateAdviceList(item.ID, creater)
  1731. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1732. redis := service.RedisClient()
  1733. //清空key 值
  1734. redis.Set(key, "", time.Second)
  1735. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1736. redis.Set(keyTwo, "", time.Second)
  1737. theTime := time.Now()
  1738. recordDate := theTime.Format("2006-01-02")
  1739. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1740. redis.Set(keyFour, "", time.Second)
  1741. defer redis.Close()
  1742. }
  1743. }
  1744. }
  1745. redis := service.RedisClient()
  1746. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1747. //清空key 值
  1748. redis.Set(key, "", time.Second)
  1749. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1750. redis.Set(keyTwo, "", time.Second)
  1751. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1752. redis.Set(keyThree, "", time.Second)
  1753. defer redis.Close()
  1754. if err == nil {
  1755. c.ServeSuccessJSON(map[string]interface{}{
  1756. "doubleCheck": doubleCheck,
  1757. })
  1758. } else {
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1760. }
  1761. } else { //修改
  1762. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1763. doubleCheck.CheckTime = checkDate
  1764. doubleCheck.Creater = creater
  1765. doubleCheck.Modifier = modifier
  1766. doubleCheck.CreatedTime = check.CreatedTime
  1767. doubleCheck.UpdatedTime = time.Now().Unix()
  1768. doubleCheck.ID = check.ID
  1769. redis := service.RedisClient()
  1770. err := service.UpdateDoubleCheck(&doubleCheck)
  1771. //针对溪康
  1772. if adminUserInfo.CurrentOrgId == 10721 {
  1773. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1774. if len(adviceInfoList) > 0 {
  1775. for _, item := range adviceInfoList {
  1776. service.UpdateHisAdviceList(item.ID, creater)
  1777. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1778. redis := service.RedisClient()
  1779. //清空key 值
  1780. redis.Set(key, "", time.Second)
  1781. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1782. redis.Set(keyTwo, "", time.Second)
  1783. theTime := time.Now()
  1784. recordDate := theTime.Format("2006-01-02")
  1785. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1786. redis.Set(keyFour, "", time.Second)
  1787. defer redis.Close()
  1788. }
  1789. }
  1790. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1791. if len(adviceList) > 0 {
  1792. for _, item := range adviceList {
  1793. service.UpdateAdviceList(item.ID, creater)
  1794. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1795. redis := service.RedisClient()
  1796. //清空key 值
  1797. redis.Set(key, "", time.Second)
  1798. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1799. redis.Set(keyTwo, "", time.Second)
  1800. theTime := time.Now()
  1801. recordDate := theTime.Format("2006-01-02")
  1802. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1803. redis.Set(keyFour, "", time.Second)
  1804. defer redis.Close()
  1805. }
  1806. }
  1807. }
  1808. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1809. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1810. redis.Set(keyTwo, "", time.Second)
  1811. //清空key 值
  1812. redis.Set(key, "", time.Second)
  1813. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1814. redis.Set(keyThree, "", time.Second)
  1815. defer redis.Close()
  1816. if err == nil {
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "doubleCheck": doubleCheck,
  1819. })
  1820. } else {
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1822. }
  1823. }
  1824. }
  1825. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1826. id, _ := c.GetInt64("patient", 0)
  1827. recordDateStr := c.GetString("record_date")
  1828. way, _ := c.GetInt64("way", 0)
  1829. consciousness, _ := c.GetInt64("consciousness", 0)
  1830. appetite, _ := c.GetInt64("appetite", 0)
  1831. condition, _ := c.GetInt64("condition", 0)
  1832. posture, _ := c.GetInt64("posture")
  1833. score := c.GetString("score")
  1834. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1835. danger_level, _ := c.GetInt64("danger_level", 0)
  1836. intake, _ := c.GetInt64("intake", 0)
  1837. nutrition, _ := c.GetInt64("nutrition", 0)
  1838. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1839. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1840. sick_condition_other := c.GetString("sick_condition_other")
  1841. //precaution, _ := c.GetInt64("precaution", 0)
  1842. precaution := c.GetString("precaution")
  1843. precaution_other := c.GetString("precaution_other")
  1844. psychological_other := c.GetString("psychological_other")
  1845. admission_number := c.GetString("admission_number")
  1846. tumble, _ := c.GetInt64("tumble")
  1847. his_department := c.GetString("his_department")
  1848. his_bed := c.GetString("his_bed")
  1849. diacrisis := c.GetString("diacrisis")
  1850. if id <= 0 {
  1851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1852. return
  1853. }
  1854. adminUserInfo := c.GetAdminUserInfo()
  1855. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1856. if patient.ID == 0 {
  1857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1858. return
  1859. }
  1860. if len(recordDateStr) == 0 {
  1861. recordDateStr = time.Now().Format("2006-01-02")
  1862. }
  1863. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1864. if parseDateErr != nil {
  1865. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1867. return
  1868. }
  1869. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1870. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1871. UserOrgId: adminUserInfo.CurrentOrgId,
  1872. PatientId: id,
  1873. RecordDate: recordDate.Unix(),
  1874. Way: way,
  1875. Consciousness: consciousness,
  1876. Appetite: appetite,
  1877. Condition: condition,
  1878. SickCondition: sick_condition,
  1879. DangerLevel: danger_level,
  1880. Intake: intake,
  1881. Nutrition: nutrition,
  1882. PsychologicalAssessment: psychological_assessment,
  1883. PsychologicalAssessmentOther: psychological_assessment_other,
  1884. SickConditionOther: sick_condition_other,
  1885. Posture: posture,
  1886. CreatedTime: time.Now().Unix(),
  1887. UpdateTime: time.Now().Unix(),
  1888. Status: 1,
  1889. Score: score,
  1890. Precaution: precaution,
  1891. PrecautionOther: precaution_other,
  1892. PsychologicalOther: psychological_other,
  1893. AdmissionNumber: admission_number,
  1894. Tumble: tumble,
  1895. HisDepartment: his_department,
  1896. HisBed: his_bed,
  1897. Diacrisis: diacrisis,
  1898. }
  1899. // 查询信息规挡的设置天数
  1900. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1901. if infor.ID > 0 && infor.WeekDay > 0 {
  1902. var cha_time int64
  1903. timeNowStr := time.Now().Format("2006-01-02")
  1904. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1905. //今日的日期减去设置的日期
  1906. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1907. if cha_time >= recordDate.Unix() {
  1908. //查询审核是否允许
  1909. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  1910. //申请状态不允许的情况 拒绝修改
  1911. if infor.ApplicationStatus != 1 {
  1912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1913. return
  1914. }
  1915. }
  1916. }
  1917. if receiveTreatment.ID == 0 { //新增
  1918. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1919. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1920. //创建步骤表
  1921. finish := models.XtDialysisFinish{
  1922. IsFinish: 1,
  1923. UserOrgId: adminUserInfo.CurrentOrgId,
  1924. Status: 1,
  1925. Ctime: time.Now().Unix(),
  1926. Mtime: 0,
  1927. Module: 2,
  1928. RecordDate: recordDate.Unix(),
  1929. Sourse: 1,
  1930. PatientId: id,
  1931. }
  1932. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 2, id)
  1933. if dialysisFinish.ID == 0 {
  1934. service.CreateDialysisFinish(finish)
  1935. }
  1936. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1937. redis := service.RedisClient()
  1938. //清空key 值
  1939. redis.Set(key, "", time.Second)
  1940. defer redis.Close()
  1941. if err == nil {
  1942. c.ServeSuccessJSON(map[string]interface{}{
  1943. "receiveTreatmentAsses": receiveTreatmentAsses,
  1944. })
  1945. } else {
  1946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1947. }
  1948. } else { //修改
  1949. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1950. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1951. // if getPermissionErr != nil {
  1952. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1953. // return
  1954. // } else if headNursePermission == nil {
  1955. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1956. // return
  1957. // }
  1958. //}
  1959. // 查询信息规挡的设置天数
  1960. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1961. if infor.ID > 0 && infor.WeekDay > 0 {
  1962. var cha_time int64
  1963. timeNowStr := time.Now().Format("2006-01-02")
  1964. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1965. //今日的日期减去设置的日期
  1966. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1967. if cha_time >= recordDate.Unix() {
  1968. //查询审核是否允许
  1969. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  1970. //申请状态不允许的情况 拒绝修改
  1971. if infor.ApplicationStatus != 1 {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1973. return
  1974. }
  1975. }
  1976. }
  1977. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1978. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1979. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1980. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1981. receiveTreatmentAsses.ID = receiveTreatment.ID
  1982. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1983. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1984. redis := service.RedisClient()
  1985. defer redis.Close()
  1986. redis.Set(keyOne, "", time.Second*60*60*18)
  1987. if err == nil {
  1988. c.ServeSuccessJSON(map[string]interface{}{
  1989. "receiveTreatmentAsses": receiveTreatmentAsses,
  1990. })
  1991. } else {
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1993. }
  1994. }
  1995. }
  1996. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1997. patient, _ := c.GetInt64("patient", 0)
  1998. recordDateStr := c.GetString("record_date")
  1999. record_time := c.GetString("record_time")
  2000. if patient <= 0 {
  2001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2002. return
  2003. }
  2004. adminUserInfo := c.GetAdminUserInfo()
  2005. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2006. if patientInfo.ID == 0 {
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2008. return
  2009. }
  2010. if len(recordDateStr) == 0 {
  2011. recordDateStr = time.Now().Format("2006-01-02")
  2012. }
  2013. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2014. if parseDateErr != nil {
  2015. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2017. return
  2018. }
  2019. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", record_time)
  2020. // data := make(map[string]interface{}, 0)
  2021. var data models.AssessmentAfterDislysis
  2022. var err error
  2023. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2024. fmt.Println(err)
  2025. if err != nil {
  2026. c.ErrorLog("数据解析错误:%v", err)
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2028. return
  2029. }
  2030. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2031. assessment.DialysisOrderId = data.DialysisOrderId
  2032. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2033. assessment.Status = 1
  2034. assessment.WeightAfter = data.WeightAfter
  2035. assessment.WeightLoss = data.WeightLoss
  2036. assessment.Temperature = data.Temperature
  2037. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2038. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2039. assessment.PulseFrequency = data.PulseFrequency
  2040. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2041. assessment.ActualDisplacement = data.ActualDisplacement
  2042. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2043. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2044. assessment.Cruor = data.Cruor
  2045. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2046. assessment.DialysisIntakes = data.DialysisIntakes
  2047. assessment.InternalFistula = data.InternalFistula
  2048. assessment.BloodAccessPartId = data.BloodAccessPartId
  2049. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2050. assessment.Catheter = data.Catheter
  2051. assessment.Complication = data.Complication
  2052. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2053. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2054. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2055. assessment.PatientGose = data.PatientGose
  2056. assessment.InpatientDepartment = data.InpatientDepartment
  2057. assessment.ObservationContent = data.ObservationContent
  2058. assessment.ObservationContentOther = data.ObservationContentOther
  2059. assessment.Remark = data.Remark
  2060. assessment.BreathingRate = data.BreathingRate
  2061. assessment.DialysisProcess = data.DialysisProcess
  2062. assessment.InAdvanceMinute = data.InAdvanceMinute
  2063. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2064. assessment.InAdvanceReason = data.InAdvanceReason
  2065. assessment.HemostasisOpera = data.HemostasisOpera
  2066. assessment.HemostasisMinute = data.HemostasisMinute
  2067. assessment.TremorNoise = data.TremorNoise
  2068. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2069. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2070. assessment.ArterialTube = data.ArterialTube
  2071. assessment.IntravenousTube = data.IntravenousTube
  2072. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2073. assessment.Dialyzer = data.Dialyzer
  2074. assessment.IsEat = data.IsEat
  2075. assessment.CvcA = data.CvcA
  2076. assessment.CvcV = data.CvcV
  2077. assessment.Channel = data.Channel
  2078. assessment.ReturnBlood = data.ReturnBlood
  2079. assessment.RehydrationVolume = data.RehydrationVolume
  2080. assessment.DialysisDuring = data.DialysisDuring
  2081. assessment.StrokeVolume = data.StrokeVolume
  2082. assessment.BloodFlow = data.BloodFlow
  2083. assessment.SealingFluidDispose = data.SealingFluidDispose
  2084. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  2085. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  2086. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  2087. assessment.SettingPressure = data.SettingPressure
  2088. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  2089. assessment.DiastolicPressure = data.DiastolicPressure
  2090. assessment.AdditionalWeight = data.AdditionalWeight
  2091. assessment.OtherComplication = data.OtherComplication
  2092. assessment.Ktv = data.Ktv
  2093. assessment.Urr = data.Urr
  2094. assessment.Hypertenison = data.Hypertenison
  2095. assessment.Hypopiesia = data.Hypopiesia
  2096. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  2097. assessment.Lapse = data.Lapse
  2098. assessment.Consciousness = data.Consciousness
  2099. assessment.Fallrisk = data.Fallrisk
  2100. assessment.MachineRun = data.MachineRun
  2101. assessment.AfterUrea = data.AfterUrea
  2102. assessment.PipCoagulation = data.PipCoagulation
  2103. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  2104. assessment.TransfusionVolume = data.TransfusionVolume
  2105. assessment.Condenser = data.Condenser
  2106. assessment.LastAfterWeight = data.LastAfterWeight
  2107. assessment.DisplaceLiquiValue = data.DisplaceLiquiValue
  2108. assessment.RecordTime = startDate.Unix()
  2109. assessment.SymptomAfterDialysisRemark = data.SymptomAfterDialysisRemark
  2110. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2111. if assessment.ID > 0 {
  2112. if appRole.UserType == 2 || appRole.UserType == 1 {
  2113. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2114. assessment.AssessmentTime = time.Now().Unix()
  2115. } else {
  2116. if assessment.Creater == 0 {
  2117. assessment.Modifier = adminUserInfo.AdminUser.Id
  2118. assessment.Creater = adminUserInfo.AdminUser.Id
  2119. } else {
  2120. assessment.Modifier = adminUserInfo.AdminUser.Id
  2121. }
  2122. }
  2123. assessment.UpdatedTime = time.Now().Unix()
  2124. // 查询信息规挡的设置天数
  2125. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2126. if infor.ID > 0 {
  2127. var cha_time int64
  2128. timeNowStr := time.Now().Format("2006-01-02")
  2129. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2130. //今日的日期减去设置的日期
  2131. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2132. if cha_time >= recordDate.Unix() {
  2133. //查询审核是否允许
  2134. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 9)
  2135. //申请状态不允许的情况 拒绝修改
  2136. if infor.ApplicationStatus != 1 {
  2137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2138. return
  2139. }
  2140. }
  2141. }
  2142. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(assessment)
  2145. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2146. UserOrgId: assessment.UserOrgId,
  2147. PatientId: assessment.PatientId,
  2148. RecordDate: assessment.AssessmentDate,
  2149. Status: 1,
  2150. ErrLog: string(byterequest),
  2151. AdminUserId: adminUserInfo.AdminUser.Id,
  2152. Ctime: time.Now().Unix(),
  2153. Mtime: 0,
  2154. Source: "电脑端保存透后评估",
  2155. }
  2156. service.CreateAfterDialysisLog(afterDialysisLog)
  2157. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2158. redis := service.RedisClient()
  2159. //清空key 值
  2160. redis.Set(key, "", time.Second)
  2161. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2162. redis.Set(keyThree, "", time.Second)
  2163. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2164. redis.Set(keyTwo, "", time.Second)
  2165. defer redis.Close()
  2166. } else {
  2167. if appRole.UserType == 2 || appRole.UserType == 1 {
  2168. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2169. assessment.AssessmentTime = time.Now().Unix()
  2170. } else {
  2171. assessment.Creater = adminUserInfo.AdminUser.Id
  2172. }
  2173. assessment.CreatedTime = time.Now().Unix()
  2174. assessment.UpdatedTime = time.Now().Unix()
  2175. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2176. assessment.PatientId = patient
  2177. assessment.AssessmentDate = recordDate.Unix()
  2178. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2179. //记录日志
  2180. byterequest, _ := json.Marshal(assessment)
  2181. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2182. UserOrgId: assessment.UserOrgId,
  2183. PatientId: assessment.PatientId,
  2184. RecordDate: assessment.AssessmentDate,
  2185. Status: 1,
  2186. ErrLog: string(byterequest),
  2187. AdminUserId: adminUserInfo.AdminUser.Id,
  2188. Ctime: time.Now().Unix(),
  2189. Mtime: 0,
  2190. Source: "电脑端修改保存透后评估",
  2191. }
  2192. service.CreateAfterDialysisLog(afterDialysisLog)
  2193. finish := models.XtDialysisFinish{
  2194. IsFinish: 1,
  2195. UserOrgId: adminUserInfo.CurrentOrgId,
  2196. Status: 1,
  2197. Ctime: time.Now().Unix(),
  2198. Mtime: 0,
  2199. Module: 9,
  2200. RecordDate: recordDate.Unix(),
  2201. Sourse: 1,
  2202. PatientId: patient,
  2203. }
  2204. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  2205. if dialysisFinish.ID == 0 {
  2206. service.CreateDialysisFinish(finish)
  2207. }
  2208. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2209. redis := service.RedisClient()
  2210. //清空key 值
  2211. redis.Set(key, "", time.Second)
  2212. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2213. redis.Set(keyThree, "", time.Second)
  2214. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2215. redis.Set(keyTwo, "", time.Second)
  2216. defer redis.Close()
  2217. }
  2218. if err != nil {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2220. return
  2221. }
  2222. c.ServeSuccessJSON(map[string]interface{}{
  2223. "AssessmentAfterDislysis": &assessment,
  2224. })
  2225. }
  2226. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2227. patient, _ := c.GetInt64("patient", 0)
  2228. recordDateStr := c.GetString("record_date")
  2229. if patient <= 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2231. return
  2232. }
  2233. adminUserInfo := c.GetAdminUserInfo()
  2234. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2235. if patientInfo.ID == 0 {
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2237. return
  2238. }
  2239. if len(recordDateStr) == 0 {
  2240. recordDateStr = time.Now().Format("2006-01-02")
  2241. }
  2242. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2243. if parseDateErr != nil {
  2244. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2246. return
  2247. }
  2248. weight_before, _ := c.GetFloat("weight_before", 0)
  2249. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2250. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2251. temperature, _ := c.GetFloat("temperature", 0)
  2252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2253. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2254. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2255. last_post_dialysis := c.GetString("last_post_dialysis")
  2256. dialysis_interphase := c.GetString("dialysis_interphase")
  2257. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2258. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2259. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2260. bloodAccessPartId := c.GetString("blood_access_part_id")
  2261. internalFistula := c.GetString("internal_fistula")
  2262. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2263. catheter := c.GetString("catheter")
  2264. catheter_bend, _ := c.GetInt("catheter_bend")
  2265. complication := c.GetString("complication")
  2266. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2267. hemorrhage := c.GetString("hemorrhage")
  2268. hemorrhage_other := c.GetString("hemorrhage_other")
  2269. remark := c.GetString("remark")
  2270. puncture_method := c.GetString("puncture_method")
  2271. dialysis_count := c.GetString("dialysis_count")
  2272. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2273. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2274. ductus_arantii := c.GetString("ductus_arantii")
  2275. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2276. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2277. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2278. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2279. puncture_way := c.GetString("puncture_way")
  2280. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2281. internal_fistula_other := c.GetString("internal_fistula_other")
  2282. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2283. breathing_rate := c.GetString("breathing_rate")
  2284. is_infect, _ := c.GetInt64("is_infect", 0)
  2285. exposed, _ := c.GetFloat("exposed", 0)
  2286. skin := c.GetString("skin")
  2287. skin_other := c.GetString("skin_other")
  2288. infect_other := c.GetString("infect_other")
  2289. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2290. machine_type := c.GetString("machine_type")
  2291. puncture_needle := c.GetString("puncture_needle")
  2292. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2293. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  2294. phinholing := c.GetString("pinholing")
  2295. catheter_suture := c.GetString("catheter_suture")
  2296. catheter_suture_other := c.GetString("catheter_suture_other")
  2297. edema := c.GetString("edema")
  2298. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2299. special_treatment := c.GetString("special_treatment")
  2300. catheter_maintenance := c.GetString("catheter_maintenance")
  2301. thrombusType := c.GetString("thromubus_type")
  2302. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  2303. thrombus_a := c.GetString("thromubus_a")
  2304. thrombus_av := c.GetString("thrombus_av")
  2305. thrombus_v := c.GetString("thromubus_v")
  2306. dehydration := c.GetString("dehydration")
  2307. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  2308. period, _ := c.GetInt64("period")
  2309. estimated_food_intake := c.GetString("estimated_food_intake")
  2310. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  2311. urea_befor := c.GetString("urea_befor")
  2312. suction := c.GetString("suction")
  2313. weight_befor_remake := c.GetString("weight_befor_remake")
  2314. height := c.GetString("height")
  2315. age := c.GetString("age")
  2316. his_department := c.GetString("his_department")
  2317. his_bed := c.GetString("his_bed")
  2318. point_puncture := c.GetString("point_puncture")
  2319. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  2320. skin_site_catheterization := c.GetString("skin_site_catheterization")
  2321. pathway_formation_time := c.GetString("pathway_formation_time")
  2322. timeLayout := "2006-01-02"
  2323. loc, _ := time.LoadLocation("Local")
  2324. var startTime int64
  2325. if len(pathway_formation_time) > 0 {
  2326. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2327. startTime = theTime.Unix()
  2328. }
  2329. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  2330. lien_necessary, _ := c.GetInt64("lien_necessary")
  2331. befor_symptoms := c.GetString("befor_symptoms")
  2332. warsh_count := c.GetString("warsh_count")
  2333. washing_time := c.GetString("washing_time")
  2334. puncture_needle_direction := c.GetString("puncture_needle_direction")
  2335. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2336. DialysisCount: dialysis_count,
  2337. EmergencyTreatment: emergency_treatment,
  2338. EmergencyTreatmentOther: emergency_treatment_other,
  2339. DuctusArantii: ductus_arantii,
  2340. VenousCatheterization: venous_catheterization,
  2341. VenousCatheterizationPart: venous_catheterization_part,
  2342. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2343. PunctureWay: puncture_way,
  2344. BloodAccessInternalFistula: blood_access_internal_fistula,
  2345. BloodAccessNoise: blood_access_noise,
  2346. InternalFistulaOther: internal_fistula_other,
  2347. Evaluator: adminUserInfo.AdminUser.Id,
  2348. UserOrgId: adminUserInfo.CurrentOrgId,
  2349. PatientId: patient,
  2350. AssessmentDate: recordDate.Unix(),
  2351. Temperature: temperature,
  2352. PulseFrequency: pulse_frequency,
  2353. SystolicBloodPressure: systolic_blood_pressure,
  2354. DiastolicBloodPressure: diastolic_blood_pressure,
  2355. WeightBefore: weight_before,
  2356. DryWeight: dry_weight,
  2357. AdditionalWeight: additional_weight,
  2358. DialysisInterphase: dialysis_interphase,
  2359. LastPostDialysis: last_post_dialysis,
  2360. SymptomBeforeDialysis: symptom_before_dialysis,
  2361. InternalFistula: internalFistula,
  2362. InternalFistulaSkin: internal_fistula_skin,
  2363. Catheter: catheter,
  2364. CatheterBend: catheter_bend,
  2365. Complication: complication,
  2366. CreatedTime: time.Now().Unix(),
  2367. Status: 1,
  2368. Remark: remark,
  2369. IsHemorrhage: is_hemorrhage,
  2370. Hemorrhage: hemorrhage,
  2371. HemorrhageOther: hemorrhage_other,
  2372. BloodAccessPartId: bloodAccessPartId,
  2373. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2374. PunctureMethod: puncture_method,
  2375. BreathingRate: breathing_rate,
  2376. IsInfect: is_infect,
  2377. Exposed: exposed,
  2378. Skin: skin,
  2379. SkinOther: skin_other,
  2380. InfectOther: infect_other,
  2381. DuctusArantiiOther: ductus_arantii_other,
  2382. MachineType: machine_type,
  2383. PunctureNeedle: puncture_needle,
  2384. HumorExcessiveSymptom: humor_excessive_symptom,
  2385. Phinholing: phinholing,
  2386. CatheterSuture: catheter_suture,
  2387. CatheterSutureOther: catheter_suture_other,
  2388. Edema: edema,
  2389. UrineVolume: urine_volume,
  2390. SpecialTreatment: special_treatment,
  2391. CatheterMaintenance: catheter_maintenance,
  2392. ThromubusType: thrombusInt,
  2393. ThrombusAv: thrombus_av,
  2394. ThromubusA: thrombus_a,
  2395. ThromubusV: thrombus_v,
  2396. Dehydration: dehydration,
  2397. PreDialysisDrugs: pre_dialysis_drugs,
  2398. Period: period,
  2399. EstimatedFoodIntake: estimated_food_intake,
  2400. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2401. UreaBefor: urea_befor,
  2402. Suction: suction,
  2403. WeightBeforRemake: weight_befor_remake,
  2404. Height: height,
  2405. Age: age,
  2406. HisDepartment: his_department,
  2407. HisBed: his_bed,
  2408. PointPuncture: point_puncture,
  2409. CatheterEvaluationProgram: catheter_evaluation_program,
  2410. SkinSiteCatheterization: skin_site_catheterization,
  2411. PathwayFormationTime: startTime,
  2412. WhetherUnobstructed: whether_unobstructed,
  2413. LienNecessary: lien_necessary,
  2414. BeforSymptoms: befor_symptoms,
  2415. WarshCount: warsh_count,
  2416. WashingTime: washing_time,
  2417. PunctureNeedleDirection: puncture_needle_direction,
  2418. }
  2419. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2420. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2421. if evaluation.ID == 0 { //新增
  2422. if appRole.UserType == 2 || appRole.UserType == 1 {
  2423. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2424. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2425. } else {
  2426. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2427. }
  2428. // 查询信息规挡的设置天数
  2429. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2430. if infor.ID > 0 && infor.WeekDay > 0 {
  2431. var cha_time int64
  2432. timeNowStr := time.Now().Format("2006-01-02")
  2433. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2434. //今日的日期减去设置的日期
  2435. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2436. if cha_time >= recordDate.Unix() {
  2437. //查询审核是否允许
  2438. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2439. //申请状态不允许的情况 拒绝修改
  2440. if infor.ApplicationStatus != 1 {
  2441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2442. return
  2443. }
  2444. }
  2445. }
  2446. if adminUserInfo.CurrentOrgId == 10644 {
  2447. assessmentBeforeDislysis.PunctureNeedle = ""
  2448. }
  2449. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2450. //记录日志
  2451. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2452. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2453. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2454. AdminUserId: adminUserInfo.AdminUser.Id,
  2455. ErrLog: string(byterequest),
  2456. PatientId: assessmentBeforeDislysis.PatientId,
  2457. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2458. Ctime: time.Now().Unix(),
  2459. Mtime: 0,
  2460. Status: 1,
  2461. Source: "电脑端保存透前评估",
  2462. }
  2463. service.CreateBeforLog(beforeDislysisLog)
  2464. //创建步骤表
  2465. finish := models.XtDialysisFinish{
  2466. IsFinish: 1,
  2467. UserOrgId: adminUserInfo.CurrentOrgId,
  2468. Status: 1,
  2469. Ctime: time.Now().Unix(),
  2470. Mtime: 0,
  2471. Module: 3,
  2472. RecordDate: recordDate.Unix(),
  2473. Sourse: 1,
  2474. PatientId: patient,
  2475. }
  2476. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2477. if dialysisFinish.ID == 0 {
  2478. service.CreateDialysisFinish(finish)
  2479. }
  2480. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 || adminUserInfo.CurrentOrgId == 10551 || adminUserInfo.CurrentOrgId == 10579 || adminUserInfo.CurrentOrgId == 10580 || adminUserInfo.CurrentOrgId == 10585 || adminUserInfo.CurrentOrgId == 10344 || adminUserInfo.CurrentOrgId == 10622 || adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 || adminUserInfo.CurrentOrgId == 10723 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10727 || adminUserInfo.CurrentOrgId == 10726 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10727 || adminUserInfo.CurrentOrgId == 10751 {
  2481. var dewater_amount float64
  2482. dewater_amount = 0
  2483. if dry_weight > 0 {
  2484. dewater_amount = weight_before - dry_weight - additional_weight
  2485. if adminUserInfo.CurrentOrgId != 10551 && adminUserInfo.CurrentOrgId != 10579 && adminUserInfo.CurrentOrgId != 10580 && adminUserInfo.CurrentOrgId != 10585 && adminUserInfo.CurrentOrgId != 10344 && adminUserInfo.CurrentOrgId != 10622 && adminUserInfo.CurrentOrgId != 10702 && adminUserInfo.CurrentOrgId != 10635 && adminUserInfo.CurrentOrgId != 10723 {
  2486. dewater_amount = dewater_amount * 1000
  2487. }
  2488. if dewater_amount <= 0 {
  2489. dewater_amount = 0
  2490. }
  2491. } else {
  2492. dewater_amount = 0
  2493. }
  2494. // 计算透析处方的相关超滤量
  2495. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2496. var lastDialysisPrescribe *models.DialysisPrescription
  2497. var dialysisSolution *models.DialysisSolution
  2498. var dialysisPrescribe *models.DialysisPrescription
  2499. var mode_id int64
  2500. if schedual != nil {
  2501. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2502. if dialysisPrescribe == nil {
  2503. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2504. }
  2505. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2506. // 获取透析模版
  2507. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2508. mode_id = schedual.ModeId
  2509. } else {
  2510. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2511. // 获取透析模版
  2512. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2513. // 获取透析模版
  2514. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2515. if dialysisPrescribe == nil && dialysisSolution != nil {
  2516. mode_id = dialysisSolution.ModeId
  2517. }
  2518. if dialysisPrescribe == nil && dialysisSolution == nil {
  2519. mode_id = 0
  2520. }
  2521. }
  2522. // 插入透析处方
  2523. if dialysisPrescribe == nil && dialysisSolution != nil {
  2524. var newprescribe models.DialysisPrescription
  2525. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2526. newprescribe.PatientId = patient
  2527. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2528. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2529. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2530. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2531. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2532. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2533. newprescribe.ModeId = dialysisSolution.ModeId
  2534. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2535. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2536. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2537. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2538. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2539. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2540. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2541. newprescribe.Glucose = dialysisSolution.Glucose
  2542. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2543. newprescribe.Kalium = dialysisSolution.Kalium
  2544. newprescribe.Sodium = dialysisSolution.Sodium
  2545. newprescribe.Calcium = dialysisSolution.Calcium
  2546. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2547. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2548. newprescribe.Conductivity = dialysisSolution.Conductivity
  2549. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2550. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2551. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2552. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2553. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2554. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2555. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2556. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2557. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2558. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2559. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2560. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2561. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2562. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2563. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2564. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2565. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2566. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2567. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2568. newprescribe.CreatedTime = time.Now().Unix()
  2569. newprescribe.UpdatedTime = time.Now().Unix()
  2570. newprescribe.RecordDate = recordDate.Unix()
  2571. newprescribe.DewaterAmount = dewater_amount
  2572. newprescribe.TargetUltrafiltration = dewater_amount
  2573. newprescribe.PrescriptionWater = dewater_amount
  2574. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2575. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  2576. newprescribe.Status = 1
  2577. if adminUserInfo.CurrentOrgId == 10579 {
  2578. newprescribe.Modifier = 0
  2579. newprescribe.PrescriptionDoctor = 0
  2580. newprescribe.Creater = 0
  2581. }
  2582. err := service.AddSigleRecord(&newprescribe)
  2583. //记录日志
  2584. byterequest, _ := json.Marshal(newprescribe)
  2585. prescriptionLog := models.XtDialysisPrescriptionLog{
  2586. UserOrgId: newprescribe.UserOrgId,
  2587. Ctime: time.Now().Unix(),
  2588. Mtime: 0,
  2589. ErrLog: string(byterequest),
  2590. AdminUserId: adminUserInfo.AdminUser.Id,
  2591. RecordDate: newprescribe.RecordDate,
  2592. PatientId: newprescribe.PatientId,
  2593. Source: "电脑端透前评估保存",
  2594. Status: 1,
  2595. }
  2596. service.CreatePrescriptionLog(prescriptionLog)
  2597. if err != nil {
  2598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2599. }
  2600. }
  2601. if dialysisPrescribe == nil && dialysisSolution == nil {
  2602. if lastDialysisPrescribe != nil {
  2603. var newprescribe models.DialysisPrescription
  2604. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2605. newprescribe.PatientId = patient
  2606. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2607. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2608. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2609. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2610. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2611. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2612. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2613. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2614. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2615. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2616. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2617. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2618. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2619. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2620. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2621. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2622. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2623. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2624. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2625. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2626. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2627. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2628. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2629. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2630. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2631. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2632. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2633. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2634. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2635. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2636. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2637. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2638. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2639. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2640. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2641. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2642. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2643. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2644. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2645. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2646. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  2647. newprescribe.CreatedTime = time.Now().Unix()
  2648. newprescribe.UpdatedTime = time.Now().Unix()
  2649. newprescribe.RecordDate = recordDate.Unix()
  2650. newprescribe.DewaterAmount = dewater_amount
  2651. newprescribe.PrescriptionWater = dewater_amount
  2652. newprescribe.TargetUltrafiltration = dewater_amount
  2653. newprescribe.Status = 1
  2654. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2655. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2656. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2657. if adminUserInfo.CurrentOrgId == 10579 {
  2658. newprescribe.Modifier = 0
  2659. newprescribe.PrescriptionDoctor = 0
  2660. newprescribe.Creater = 0
  2661. }
  2662. err := service.AddSigleRecord(&newprescribe)
  2663. //记录日志
  2664. byterequest, _ := json.Marshal(newprescribe)
  2665. prescriptionLog := models.XtDialysisPrescriptionLog{
  2666. UserOrgId: newprescribe.UserOrgId,
  2667. Ctime: time.Now().Unix(),
  2668. Mtime: 0,
  2669. ErrLog: string(byterequest),
  2670. AdminUserId: adminUserInfo.AdminUser.Id,
  2671. RecordDate: newprescribe.RecordDate,
  2672. PatientId: newprescribe.PatientId,
  2673. Source: "电脑端透前评估保存",
  2674. Status: 1,
  2675. }
  2676. service.CreatePrescriptionLog(prescriptionLog)
  2677. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2678. redis := service.RedisClient()
  2679. defer redis.Close()
  2680. //清空key 值
  2681. redis.Set(key, "", time.Second)
  2682. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2683. redis.Set(keyOne, "", time.Second)
  2684. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2685. redis.Set(keyThree, "", time.Second)
  2686. if err != nil {
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2688. }
  2689. } else {
  2690. var newprescribe models.DialysisPrescription
  2691. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2692. newprescribe.PatientId = patient
  2693. newprescribe.ModeId = mode_id
  2694. newprescribe.CreatedTime = time.Now().Unix()
  2695. newprescribe.UpdatedTime = time.Now().Unix()
  2696. newprescribe.RecordDate = recordDate.Unix()
  2697. newprescribe.DewaterAmount = dewater_amount
  2698. newprescribe.TargetUltrafiltration = dewater_amount
  2699. newprescribe.Status = 1
  2700. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2701. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2702. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2703. if adminUserInfo.CurrentOrgId == 10579 {
  2704. newprescribe.Modifier = 0
  2705. newprescribe.PrescriptionDoctor = 0
  2706. newprescribe.Creater = 0
  2707. }
  2708. err := service.AddSigleRecord(&newprescribe)
  2709. //记录日志
  2710. byterequest, _ := json.Marshal(newprescribe)
  2711. prescriptionLog := models.XtDialysisPrescriptionLog{
  2712. UserOrgId: newprescribe.UserOrgId,
  2713. Ctime: time.Now().Unix(),
  2714. Mtime: 0,
  2715. ErrLog: string(byterequest),
  2716. AdminUserId: adminUserInfo.AdminUser.Id,
  2717. RecordDate: newprescribe.RecordDate,
  2718. PatientId: newprescribe.PatientId,
  2719. Source: "电脑端透前评估保存",
  2720. Status: 1,
  2721. }
  2722. service.CreatePrescriptionLog(prescriptionLog)
  2723. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2724. redis := service.RedisClient()
  2725. defer redis.Close()
  2726. //清空key 值
  2727. redis.Set(key, "", time.Second)
  2728. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2729. redis.Set(keyOne, "", time.Second)
  2730. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2731. redis.Set(keyThree, "", time.Second)
  2732. if err != nil {
  2733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2734. }
  2735. }
  2736. }
  2737. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  2738. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  2739. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2740. if len(monitorList) > 0 {
  2741. var ultrafiltration_rate float64
  2742. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2743. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2744. var replacement_rate float64
  2745. //乘10 除10是为了保留一位小数
  2746. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2747. var firstOpeateTime = monitorList[0].OperateTime
  2748. for _, item := range monitorList {
  2749. //超滤率
  2750. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2751. //置换率
  2752. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2753. //超滤量
  2754. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2755. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2756. //置换量
  2757. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2758. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2759. }
  2760. }
  2761. }
  2762. }
  2763. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2764. redis := service.RedisClient()
  2765. //清空key 值
  2766. redis.Set(key, "", time.Second)
  2767. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2768. redis.Set(keyOne, "", time.Second)
  2769. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2770. redis.Set(keyTwo, "", time.Second)
  2771. defer redis.Close()
  2772. if err == nil {
  2773. c.ServeSuccessJSON(map[string]interface{}{
  2774. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2775. })
  2776. } else {
  2777. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2779. }
  2780. } else { //修改
  2781. //if appRole.UserType == 3 {
  2782. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2783. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2784. // if getPermissionErr != nil {
  2785. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2786. // return
  2787. // } else if headNursePermission == nil {
  2788. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2789. // return
  2790. // }
  2791. // }
  2792. //}
  2793. if appRole.UserType == 2 || appRole.UserType == 1 {
  2794. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2795. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2796. } else {
  2797. if evaluation.Creater == 0 {
  2798. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2799. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2800. } else {
  2801. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2802. }
  2803. }
  2804. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2805. assessmentBeforeDislysis.ID = evaluation.ID
  2806. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2807. //
  2808. //新增逻辑
  2809. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2810. var dewater_amount float64
  2811. dewater_amount = 0
  2812. if evaluation.DryWeight > 0 {
  2813. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2814. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 || adminUserInfo.CurrentOrgId == 10551 || adminUserInfo.CurrentOrgId == 10751 {
  2815. if adminUserInfo.CurrentOrgId != 10551 && adminUserInfo.CurrentOrgId != 10751 {
  2816. dewater_amount = dewater_amount * 1000
  2817. }
  2818. }
  2819. if dewater_amount <= 0 {
  2820. dewater_amount = 0
  2821. }
  2822. } else {
  2823. dewater_amount = 0
  2824. }
  2825. // 计算透析处方的相关超滤量
  2826. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2827. var lastDialysisPrescribe *models.DialysisPrescription
  2828. var dialysisSolution *models.DialysisSolution
  2829. var dialysisPrescribe *models.DialysisPrescription
  2830. var mode_id int64
  2831. if schedual != nil {
  2832. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2833. if dialysisPrescribe == nil {
  2834. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2835. }
  2836. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2837. // 获取透析模版
  2838. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2839. mode_id = schedual.ModeId
  2840. } else {
  2841. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2842. // 获取透析模版
  2843. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2844. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2845. if dialysisPrescribe == nil && dialysisSolution != nil {
  2846. mode_id = dialysisSolution.ModeId
  2847. }
  2848. if dialysisPrescribe == nil && dialysisSolution == nil {
  2849. mode_id = 0
  2850. }
  2851. }
  2852. // 插入透析处方
  2853. if dialysisPrescribe == nil && dialysisSolution != nil {
  2854. var newprescribe models.DialysisPrescription
  2855. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2856. newprescribe.PatientId = patient
  2857. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2858. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2859. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2860. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2861. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2862. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2863. newprescribe.ModeId = dialysisSolution.ModeId
  2864. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2865. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2866. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2867. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2868. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2869. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2870. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2871. newprescribe.Glucose = dialysisSolution.Glucose
  2872. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2873. newprescribe.Kalium = dialysisSolution.Kalium
  2874. newprescribe.Sodium = dialysisSolution.Sodium
  2875. newprescribe.Calcium = dialysisSolution.Calcium
  2876. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2877. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2878. newprescribe.Conductivity = dialysisSolution.Conductivity
  2879. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2880. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2881. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2882. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2883. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2884. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2885. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2886. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2887. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2888. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2889. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2890. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2891. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2892. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2893. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2894. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2895. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2896. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2897. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2898. newprescribe.CreatedTime = time.Now().Unix()
  2899. newprescribe.UpdatedTime = time.Now().Unix()
  2900. newprescribe.RecordDate = recordDate.Unix()
  2901. newprescribe.DewaterAmount = dewater_amount
  2902. newprescribe.TargetUltrafiltration = dewater_amount
  2903. newprescribe.PrescriptionWater = dewater_amount
  2904. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2905. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  2906. newprescribe.Status = 1
  2907. if adminUserInfo.CurrentOrgId == 10579 {
  2908. newprescribe.Modifier = 0
  2909. newprescribe.PrescriptionDoctor = 0
  2910. newprescribe.Creater = 0
  2911. }
  2912. err := service.AddSigleRecord(&newprescribe)
  2913. //记录日志
  2914. byterequest, _ := json.Marshal(newprescribe)
  2915. prescriptionLog := models.XtDialysisPrescriptionLog{
  2916. UserOrgId: newprescribe.UserOrgId,
  2917. Ctime: time.Now().Unix(),
  2918. Mtime: 0,
  2919. ErrLog: string(byterequest),
  2920. AdminUserId: adminUserInfo.AdminUser.Id,
  2921. RecordDate: newprescribe.RecordDate,
  2922. PatientId: newprescribe.PatientId,
  2923. Source: "电脑端透前评估保存",
  2924. Status: 1,
  2925. }
  2926. service.CreatePrescriptionLog(prescriptionLog)
  2927. if err != nil {
  2928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2929. }
  2930. }
  2931. if dialysisPrescribe == nil && dialysisSolution == nil {
  2932. if lastDialysisPrescribe != nil {
  2933. var newprescribe models.DialysisPrescription
  2934. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2935. newprescribe.PatientId = patient
  2936. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2937. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2938. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2939. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2940. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2941. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2942. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2943. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2944. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2945. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2946. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2947. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2948. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2949. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2950. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2951. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2952. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2953. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2954. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2955. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2956. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2957. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2958. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2959. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2960. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2961. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2962. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2963. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2964. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2965. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2966. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2967. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2968. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2969. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2970. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2971. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2972. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2973. newprescribe.CreatedTime = time.Now().Unix()
  2974. newprescribe.UpdatedTime = time.Now().Unix()
  2975. newprescribe.RecordDate = recordDate.Unix()
  2976. newprescribe.DewaterAmount = dewater_amount
  2977. newprescribe.TargetUltrafiltration = dewater_amount
  2978. newprescribe.PrescriptionWater = dewater_amount
  2979. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2980. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2981. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2982. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2983. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  2984. newprescribe.Status = 1
  2985. if adminUserInfo.CurrentOrgId == 10579 {
  2986. newprescribe.Modifier = 0
  2987. newprescribe.PrescriptionDoctor = 0
  2988. newprescribe.Creater = 0
  2989. }
  2990. err := service.AddSigleRecord(&newprescribe)
  2991. //记录日志
  2992. byterequest, _ := json.Marshal(newprescribe)
  2993. prescriptionLog := models.XtDialysisPrescriptionLog{
  2994. UserOrgId: newprescribe.UserOrgId,
  2995. Ctime: time.Now().Unix(),
  2996. Mtime: 0,
  2997. ErrLog: string(byterequest),
  2998. AdminUserId: adminUserInfo.AdminUser.Id,
  2999. RecordDate: newprescribe.RecordDate,
  3000. PatientId: newprescribe.PatientId,
  3001. Source: "电脑端透前评估保存",
  3002. Status: 1,
  3003. }
  3004. service.CreatePrescriptionLog(prescriptionLog)
  3005. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3006. redis := service.RedisClient()
  3007. defer redis.Close()
  3008. //清空key 值
  3009. redis.Set(key, "", time.Second)
  3010. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3011. redis.Set(keyOne, "", time.Second)
  3012. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3013. redis.Set(keyThree, "", time.Second)
  3014. if err != nil {
  3015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3016. }
  3017. } else {
  3018. var newprescribe models.DialysisPrescription
  3019. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3020. newprescribe.PatientId = patient
  3021. newprescribe.ModeId = mode_id
  3022. newprescribe.CreatedTime = time.Now().Unix()
  3023. newprescribe.UpdatedTime = time.Now().Unix()
  3024. newprescribe.RecordDate = recordDate.Unix()
  3025. newprescribe.DewaterAmount = dewater_amount
  3026. newprescribe.TargetUltrafiltration = dewater_amount
  3027. newprescribe.Status = 1
  3028. err := service.AddSigleRecord(&newprescribe)
  3029. //记录日志
  3030. byterequest, _ := json.Marshal(newprescribe)
  3031. prescriptionLog := models.XtDialysisPrescriptionLog{
  3032. UserOrgId: newprescribe.UserOrgId,
  3033. Ctime: time.Now().Unix(),
  3034. Mtime: 0,
  3035. ErrLog: string(byterequest),
  3036. AdminUserId: adminUserInfo.AdminUser.Id,
  3037. RecordDate: newprescribe.RecordDate,
  3038. PatientId: newprescribe.PatientId,
  3039. Source: "电脑端透前评估保存",
  3040. Status: 1,
  3041. }
  3042. service.CreatePrescriptionLog(prescriptionLog)
  3043. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3044. redis := service.RedisClient()
  3045. defer redis.Close()
  3046. //清空key 值
  3047. redis.Set(key, "", time.Second)
  3048. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3049. redis.Set(keyOne, "", time.Second)
  3050. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3051. redis.Set(keyThree, "", time.Second)
  3052. if err != nil {
  3053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3054. }
  3055. }
  3056. }
  3057. // 查询信息规挡的设置天数
  3058. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3059. if infor.ID > 0 {
  3060. var cha_time int64
  3061. timeNowStr := time.Now().Format("2006-01-02")
  3062. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3063. //今日的日期减去设置的日期
  3064. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3065. if cha_time >= recordDate.Unix() {
  3066. //查询审核是否允许
  3067. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  3068. //申请状态不允许的情况 拒绝修改
  3069. if infor.ApplicationStatus != 1 {
  3070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3071. return
  3072. }
  3073. }
  3074. }
  3075. //针对孝昌康桥超滤率计算问题
  3076. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 || adminUserInfo.CurrentOrgId == 10723 || adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10726 || adminUserInfo.CurrentOrgId == 10742 || adminUserInfo.CurrentOrgId == 10751 {
  3077. if assessmentBeforeDislysis.ID == 0 {
  3078. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3079. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3080. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3081. if adminUserInfo.CurrentOrgId == 10751 {
  3082. dewater_amount = dewater_amount * 1000
  3083. }
  3084. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3085. }
  3086. }
  3087. if assessmentBeforeDislysis.ID > 0 {
  3088. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3089. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3090. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3091. if adminUserInfo.CurrentOrgId == 10751 {
  3092. dewater_amount = dewater_amount * 1000
  3093. }
  3094. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3095. }
  3096. }
  3097. }
  3098. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  3099. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  3100. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3101. if len(monitorList) > 0 {
  3102. var ultrafiltration_rate float64
  3103. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3104. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  3105. var replacement_rate float64
  3106. //乘10 除10是为了保留一位小数
  3107. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3108. var firstOpeateTime = monitorList[0].OperateTime
  3109. for _, item := range monitorList {
  3110. //超滤率
  3111. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  3112. //置换率
  3113. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  3114. //超滤量
  3115. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  3116. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  3117. //置换量
  3118. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  3119. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  3120. }
  3121. }
  3122. }
  3123. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3124. //创建步骤表
  3125. finish := models.XtDialysisFinish{
  3126. IsFinish: 1,
  3127. UserOrgId: adminUserInfo.CurrentOrgId,
  3128. Status: 1,
  3129. Ctime: time.Now().Unix(),
  3130. Mtime: 0,
  3131. Module: 3,
  3132. RecordDate: recordDate.Unix(),
  3133. Sourse: 1,
  3134. PatientId: patient,
  3135. }
  3136. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  3137. if dialysisFinish.ID == 0 {
  3138. service.CreateDialysisFinish(finish)
  3139. }
  3140. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  3141. redis := service.RedisClient()
  3142. //清空key 值
  3143. redis.Set(key, "", time.Second)
  3144. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  3145. redis.Set(keyOne, "", time.Second)
  3146. defer redis.Close()
  3147. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3148. redis.Set(keyTwo, "", time.Second)
  3149. if err == nil {
  3150. c.ServeSuccessJSON(map[string]interface{}{
  3151. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3152. })
  3153. } else {
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3155. }
  3156. }
  3157. }
  3158. func (c *DialysisApiController) PostTreatmentSummary() {
  3159. patient, _ := c.GetInt64("patient", 0)
  3160. recordDateStr := c.GetString("record_date")
  3161. if patient <= 0 {
  3162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3163. return
  3164. }
  3165. adminUserInfo := c.GetAdminUserInfo()
  3166. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3167. if patientInfo.ID == 0 {
  3168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3169. return
  3170. }
  3171. if len(recordDateStr) == 0 {
  3172. recordDateStr = time.Now().Format("2006-01-02")
  3173. }
  3174. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3175. if parseDateErr != nil {
  3176. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3178. return
  3179. }
  3180. mission := c.GetString("mission")
  3181. dialysis_summary := c.GetString("dialysis_summary")
  3182. nursingRecord := c.GetString("nursing_record")
  3183. specialRecord := c.GetString("special_record")
  3184. sj_nurse := adminUserInfo.AdminUser.Id
  3185. zl_nurse := adminUserInfo.AdminUser.Id
  3186. hd_nurse := adminUserInfo.AdminUser.Id
  3187. xj_nurse := adminUserInfo.AdminUser.Id
  3188. zl_doctor := adminUserInfo.AdminUser.Id
  3189. treatmentSummary := models.TreatmentSummary{
  3190. UserOrgId: adminUserInfo.CurrentOrgId,
  3191. PatientId: patient,
  3192. AssessmentDate: recordDate.Unix(),
  3193. Mission: mission,
  3194. DialysisSummary: dialysis_summary,
  3195. SjNurse: sj_nurse,
  3196. ZlNurse: zl_nurse,
  3197. HdNurse: hd_nurse,
  3198. XjNurse: xj_nurse,
  3199. ZlDoctor: zl_doctor,
  3200. Status: 1,
  3201. CreatedTime: time.Now().Unix(),
  3202. NursingRecord: nursingRecord,
  3203. SpecialRecord: specialRecord,
  3204. }
  3205. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3206. if tempTreatmentSummary.ID == 0 { //新增
  3207. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3208. // 查询信息规挡的设置天数
  3209. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3210. if infor.ID > 0 && infor.WeekDay > 0 {
  3211. var cha_time int64
  3212. timeNowStr := time.Now().Format("2006-01-02")
  3213. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3214. //今日的日期减去设置的日期
  3215. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3216. if cha_time >= recordDate.Unix() {
  3217. //查询审核是否允许
  3218. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3219. //申请状态不允许的情况 拒绝修改
  3220. if infor.ApplicationStatus != 1 {
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3222. return
  3223. }
  3224. }
  3225. }
  3226. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3227. finish := models.XtDialysisFinish{
  3228. IsFinish: 1,
  3229. UserOrgId: adminUserInfo.CurrentOrgId,
  3230. Status: 1,
  3231. Ctime: time.Now().Unix(),
  3232. Mtime: 0,
  3233. Module: 10,
  3234. RecordDate: recordDate.Unix(),
  3235. Sourse: 1,
  3236. PatientId: patient,
  3237. }
  3238. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  3239. if dialysisFinish.ID == 0 {
  3240. service.CreateDialysisFinish(finish)
  3241. }
  3242. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3243. redis := service.RedisClient()
  3244. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3245. redis.Set(keyOne, "", time.Second)
  3246. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3247. redis.Set(keyThree, "", time.Second)
  3248. defer redis.Close()
  3249. //清空key 值
  3250. redis.Set(key, "", time.Second)
  3251. if err == nil {
  3252. c.ServeSuccessJSON(map[string]interface{}{
  3253. "summary": treatmentSummary,
  3254. })
  3255. } else {
  3256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3257. }
  3258. } else { //修改
  3259. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3260. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3261. // if getPermissionErr != nil {
  3262. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3263. // return
  3264. // } else if headNursePermission == nil {
  3265. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3266. // return
  3267. // }
  3268. //}
  3269. // 查询信息规挡的设置天数
  3270. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3271. if infor.ID > 0 && infor.WeekDay > 0 {
  3272. var cha_time int64
  3273. timeNowStr := time.Now().Format("2006-01-02")
  3274. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3275. //今日的日期减去设置的日期
  3276. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3277. if cha_time >= recordDate.Unix() {
  3278. //查询审核是否允许
  3279. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3280. //申请状态不允许的情况 拒绝修改
  3281. if infor.ApplicationStatus != 1 {
  3282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3283. return
  3284. }
  3285. }
  3286. }
  3287. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3288. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3289. treatmentSummary.UpdatedTime = time.Now().Unix()
  3290. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3291. treatmentSummary.ID = tempTreatmentSummary.ID
  3292. err := service.UpdateSummeRecord(&treatmentSummary)
  3293. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3294. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3295. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3296. //清空key 值
  3297. redis := service.RedisClient()
  3298. redis.Set(key, "", time.Second)
  3299. redis.Set(keyOne, "", time.Second)
  3300. redis.Set(keyThree, "", time.Second)
  3301. defer redis.Close()
  3302. if err == nil {
  3303. c.ServeSuccessJSON(map[string]interface{}{
  3304. "summary": treatmentSummary,
  3305. })
  3306. } else {
  3307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3308. }
  3309. }
  3310. }
  3311. func (c *DialysisApiController) GetDeviceList() {
  3312. adminUserInfo := c.GetAdminUserInfo()
  3313. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3314. c.ServeSuccessJSON(map[string]interface{}{
  3315. "device": device,
  3316. })
  3317. }
  3318. func (c *DialysisApiController) GetAllDeviceZone() {
  3319. adminUserInfo := c.GetAdminUserInfo()
  3320. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3321. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  3322. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  3323. if err == nil {
  3324. c.ServeSuccessJSON(map[string]interface{}{
  3325. "zone": zone,
  3326. "dics": dics,
  3327. "efs": efs,
  3328. })
  3329. }
  3330. }
  3331. func (c *DialysisApiController) GetDialysisWatch() {
  3332. page, _ := c.GetInt64("page", 1)
  3333. limit, _ := c.GetInt64("limit", 10)
  3334. schedulType, _ := c.GetInt64("schedul_type", 0)
  3335. startTime, _ := c.GetInt64("schedul_time", 0)
  3336. partitionType, _ := c.GetInt64("partition_type", 0)
  3337. keywords := c.GetString("keywords")
  3338. start_time, _ := c.GetInt64("start_time")
  3339. end_time, _ := c.GetInt64("end_time")
  3340. adminUserInfo := c.GetAdminUserInfo()
  3341. if len(keywords) > 0 {
  3342. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3343. if err == nil {
  3344. c.ServeSuccessJSON(map[string]interface{}{
  3345. "schedule": dialysisSchedule,
  3346. "total": total,
  3347. })
  3348. } else {
  3349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3350. }
  3351. } else {
  3352. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3353. for _, item := range dialysisSchedule {
  3354. patients, _ := service.GetMonitorPatients(item.PatientId)
  3355. item.MonitorPatients = patients
  3356. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  3357. item.DialysisOrder = orderObj
  3358. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  3359. item.Prescription = prescription
  3360. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  3361. item.AssessmentBeforeDislysis = evaluation
  3362. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  3363. item.AssessmentAfterDislysis = afterdislysis
  3364. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  3365. item.MonitoringRecord = monitorRecord
  3366. }
  3367. if err == nil {
  3368. c.ServeSuccessJSON(map[string]interface{}{
  3369. "schedule": dialysisSchedule,
  3370. "total": total,
  3371. })
  3372. } else {
  3373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3374. }
  3375. }
  3376. }
  3377. //func (c *DialysisApiController) GetDialysisWatch() {
  3378. // page, _ := c.GetInt64("page", 1)
  3379. // limit, _ := c.GetInt64("limit", 10)
  3380. // schedulType, _ := c.GetInt64("schedul_type", 0)
  3381. // startTime, _ := c.GetInt64("schedul_time", 0)
  3382. // partitionType, _ := c.GetInt64("partition_type", 0)
  3383. // keywords := c.GetString("keywords")
  3384. //
  3385. // adminUserInfo := c.GetAdminUserInfo()
  3386. // if len(keywords) > 0 {
  3387. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3388. //
  3389. // //获取所有床位号
  3390. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  3391. //
  3392. // //获取透析处方
  3393. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  3394. // //获取透前评估
  3395. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3396. // //获取上机
  3397. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3398. // //获取透后
  3399. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3400. //
  3401. // //获取透后监测
  3402. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3403. //
  3404. // //获取所有的患者
  3405. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3406. //
  3407. // //获取所有透析模式
  3408. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3409. //
  3410. // for key, scheduals := range dialysisSchedule {
  3411. // // 获取患者信息
  3412. // for _, patient := range patients {
  3413. // if scheduals.PatientId == patient.ID {
  3414. // dialysisSchedule[key].MonitorPatients = patient
  3415. // break
  3416. // }
  3417. // }
  3418. // // 床位信息
  3419. // for _, device := range numberList {
  3420. // if scheduals.BedId == device.ID {
  3421. // dialysisSchedule[key].DeviceNumber = device
  3422. // break
  3423. // }
  3424. // }
  3425. //
  3426. // // 医嘱信息
  3427. // for _, prescription := range prescriptions {
  3428. // if scheduals.PatientId == prescription.PatientId {
  3429. // dialysisSchedule[key].Prescription = prescription
  3430. // break
  3431. // }
  3432. // }
  3433. //
  3434. // // 透前评估
  3435. // for _, assessmentBefore := range assessmentBefores {
  3436. // if scheduals.PatientId == assessmentBefore.PatientId {
  3437. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3438. // break
  3439. // }
  3440. // }
  3441. //
  3442. // // 透析上下机
  3443. // for _, dialysisOrder := range dialysisOrders {
  3444. // if scheduals.PatientId == dialysisOrder.PatientId {
  3445. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3446. // break
  3447. // }
  3448. // }
  3449. //
  3450. // records := make([]*models.MonitoringRecord, 0)
  3451. // // 透析监测
  3452. // for _, it := range monitorlist {
  3453. // records := append(records, it)
  3454. // if scheduals.PatientId == it.PatientId {
  3455. // dialysisSchedule[key].MonitoringRecord = records
  3456. // }
  3457. // }
  3458. //
  3459. // // 透后评估
  3460. // for _, afterDislysis := range AssessmentAfterDislysis {
  3461. // if scheduals.PatientId == afterDislysis.PatientId {
  3462. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3463. // break
  3464. // }
  3465. // }
  3466. //
  3467. // //透析模式
  3468. // for _, treatment := range treatments {
  3469. // if scheduals.ModeId == treatment.ID {
  3470. // dialysisSchedule[key].TreatmentMode = treatment
  3471. // break
  3472. // }
  3473. // }
  3474. // }
  3475. // //获取所有床位号
  3476. // if err == nil {
  3477. // c.ServeSuccessJSON(map[string]interface{}{
  3478. // "schedule": dialysisSchedule,
  3479. // "total": total,
  3480. // })
  3481. // } else {
  3482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3483. // }
  3484. //
  3485. // } else {
  3486. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3487. // if err == nil {
  3488. // c.ServeSuccessJSON(map[string]interface{}{
  3489. // "schedule": dialysisSchedule,
  3490. // "total": total,
  3491. // })
  3492. // } else {
  3493. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3494. // }
  3495. // }
  3496. //}
  3497. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3498. patientId, _ := c.GetInt64("id", 0)
  3499. record_date, _ := c.GetInt64("record_date", 0)
  3500. adminUserInfo := c.GetAdminUserInfo()
  3501. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3502. var dialysisStatus int64
  3503. if dialysisOrder == nil { //没有透析记录
  3504. dialysisStatus = 0 //未透析
  3505. } else {
  3506. dialysisStatus = dialysisOrder.Stage
  3507. }
  3508. //用户基本信息
  3509. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3510. //接诊评估
  3511. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3512. //透前评估
  3513. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3514. //临时医嘱
  3515. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3516. //双人核对
  3517. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3518. //透析监测
  3519. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3520. //透后评估
  3521. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3522. //透析小结
  3523. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3524. //透析处方
  3525. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3526. if dialysisPrescription.ID == 0 {
  3527. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "patientInfo": schedualPatientInfo,
  3530. "dialysisPrescription": solution,
  3531. "receiverTreatmentAccess": receiverTreatmentAccess,
  3532. "predialysisEvaluation": PredialysisEvaluation,
  3533. "doctorAdvice": DoctorAdvice,
  3534. "doubleCheck": DoubleCheck,
  3535. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3536. "treatmentSummary": TreatmentSummary,
  3537. "monitorRecord": Record,
  3538. "dialysisStatus": dialysisStatus,
  3539. "dialysisOrder": dialysisOrder,
  3540. "isSolution": 1,
  3541. })
  3542. } else {
  3543. c.ServeSuccessJSON(map[string]interface{}{
  3544. "patientInfo": schedualPatientInfo,
  3545. "dialysisPrescription": dialysisPrescription,
  3546. "receiverTreatmentAccess": receiverTreatmentAccess,
  3547. "predialysisEvaluation": PredialysisEvaluation,
  3548. "doctorAdvice": DoctorAdvice,
  3549. "doubleCheck": DoubleCheck,
  3550. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3551. "treatmentSummary": TreatmentSummary,
  3552. "monitorRecord": Record,
  3553. "dialysisStatus": dialysisStatus,
  3554. "dialysisOrder": dialysisOrder,
  3555. "isSolution": 2,
  3556. })
  3557. }
  3558. }
  3559. func (c *DialysisApiController) CreateDoctorAdvice() {
  3560. patient, _ := c.GetInt64("id", 0)
  3561. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3562. record_date, _ := c.GetInt64("record_date", 0)
  3563. if patient <= 0 {
  3564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3565. return
  3566. }
  3567. adminUserInfo := c.GetAdminUserInfo()
  3568. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3569. if patientInfo.ID == 0 {
  3570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3571. return
  3572. }
  3573. var advice models.DoctorAdvice
  3574. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3575. if code > 0 {
  3576. c.ServeFailJSONWithSGJErrorCode(code)
  3577. return
  3578. }
  3579. if advice.ParentId > 0 {
  3580. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3581. if old.ID == 0 || old.PatientId != patient {
  3582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3583. return
  3584. }
  3585. if old.StopState == 1 || old.ExecutionState == 1 {
  3586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3587. return
  3588. }
  3589. if old.ParentId > 0 {
  3590. advice.ParentId = old.ParentId
  3591. }
  3592. advice.StartTime = old.StartTime
  3593. advice.AdviceDoctor = old.AdviceDoctor
  3594. advice.DeliveryWay = old.DeliveryWay
  3595. advice.ExecutionFrequency = old.ExecutionFrequency
  3596. }
  3597. advice.RecordDate = record_date
  3598. advice.DialysisOrderId = dialysis_id
  3599. advice.Status = 1
  3600. advice.CreatedTime = time.Now().Unix()
  3601. advice.UpdatedTime = time.Now().Unix()
  3602. advice.StopState = 2
  3603. advice.ExecutionState = 2
  3604. advice.AdviceType = 2
  3605. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3606. advice.PatientId = patient
  3607. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3608. err := service.CreateDoctorAdvice(&advice)
  3609. if err != nil {
  3610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3611. return
  3612. }
  3613. for _, subAdvice := range subAdivice {
  3614. subAdvice.ParentId = advice.ID
  3615. subAdvice.PatientId = patient
  3616. subAdvice.RecordDate = record_date
  3617. subAdvice.CreatedTime = time.Now().Unix()
  3618. subAdvice.UpdatedTime = time.Now().Unix()
  3619. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3620. }
  3621. service.CreateSubDoctorAdvice(subAdivice)
  3622. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3623. c.ServeSuccessJSON(map[string]interface{}{
  3624. "msg": "ok",
  3625. "advice": advice,
  3626. "subAdvice": subAdivices,
  3627. })
  3628. return
  3629. }
  3630. func (c *DialysisApiController) EditDoctorAdvice() {
  3631. patient, _ := c.GetInt64("patient", 0)
  3632. id, _ := c.GetInt64("id", 0)
  3633. parent_id, _ := c.GetInt64("parent_id", 0)
  3634. execution_time := c.GetString("execution_time")
  3635. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3636. // checker, _ := c.GetInt64("checker", 0)
  3637. if id <= 0 || patient <= 0 {
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3639. return
  3640. }
  3641. adminUserInfo := c.GetAdminUserInfo()
  3642. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3643. if advice.ID == 0 || advice.PatientId != patient {
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3645. return
  3646. }
  3647. if len(execution_time) <= 0 {
  3648. utils.ErrorLog("execution_time")
  3649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3650. return
  3651. }
  3652. execution_staff := adminUserInfo.AdminUser.Id
  3653. checker := adminUserInfo.AdminUser.Id
  3654. timeLayout2 := "2006-01-02 15:04"
  3655. loc, _ := time.LoadLocation("Local")
  3656. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3657. if errs != nil {
  3658. utils.ErrorLog(errs.Error())
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3660. return
  3661. }
  3662. advices := models.DoctorAdvice{
  3663. ExecutionStaff: execution_staff,
  3664. ExecutionTime: theTime.Unix(),
  3665. Checker: checker,
  3666. UpdatedTime: time.Now().Unix(),
  3667. }
  3668. var err error
  3669. if parent_id > 0 {
  3670. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3671. } else {
  3672. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3673. }
  3674. if err != nil {
  3675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3676. return
  3677. }
  3678. c.ServeSuccessJSON(map[string]interface{}{
  3679. "msg": "ok",
  3680. "advice": advice,
  3681. })
  3682. return
  3683. }
  3684. func (c *DialysisApiController) GetDoctorAdvice() {
  3685. patient, _ := c.GetInt64("patient_id", 0)
  3686. parent_id, _ := c.GetInt64("parent_id", 0)
  3687. adviceId, _ := c.GetInt64("id", 0)
  3688. if patient <= 0 {
  3689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3690. return
  3691. }
  3692. dminUserInfo := c.GetAdminUserInfo()
  3693. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3694. if patientInfo.ID == 0 {
  3695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3696. return
  3697. }
  3698. var subAdvice []*models.DoctorAdvice
  3699. var advice models.DoctorAdvice
  3700. if parent_id > 0 {
  3701. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3702. if advice.ID == 0 || advice.PatientId != patient {
  3703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3704. return
  3705. }
  3706. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3707. } else {
  3708. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3709. if advice.ID == 0 || advice.PatientId != patient {
  3710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3711. return
  3712. }
  3713. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3714. }
  3715. c.ServeSuccessJSON(map[string]interface{}{
  3716. "msg": "ok",
  3717. "advice": advice,
  3718. "subAdvice": subAdvice,
  3719. })
  3720. }
  3721. func (this *DialysisApiController) DelMonitor() {
  3722. recordID, _ := this.GetInt64("record_id")
  3723. patientID, _ := this.GetInt64("patient_id")
  3724. if recordID <= 0 || patientID <= 0 {
  3725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3726. return
  3727. }
  3728. adminInfo := this.GetAdminUserInfo()
  3729. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3730. if getPatientErr != nil {
  3731. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3733. return
  3734. } else if patient == nil {
  3735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3736. return
  3737. }
  3738. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3739. if getMonitorErr != nil {
  3740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3741. return
  3742. }
  3743. //if monitor != nil {
  3744. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3745. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3746. // if getPermissionErr != nil {
  3747. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3748. // return
  3749. // } else if headNursePermission == nil {
  3750. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3751. // return
  3752. // }
  3753. // }
  3754. //}
  3755. // 查询信息规挡的设置天数
  3756. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3757. if infor.ID > 0 && infor.WeekDay > 0 {
  3758. var cha_time int64
  3759. timeNowStr := time.Now().Format("2006-01-02")
  3760. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3761. //今日的日期减去设置的日期
  3762. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3763. if cha_time >= monitor.MonitoringDate {
  3764. //查询审核是否允许
  3765. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3766. //申请状态不允许的情况 拒绝修改
  3767. if infor.ApplicationStatus != 1 {
  3768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3769. return
  3770. }
  3771. }
  3772. }
  3773. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3774. //记录日志
  3775. byterequest, _ := json.Marshal(monitor)
  3776. monitorRecordLog := models.XtMonitorRecordLog{
  3777. RecordDate: monitor.MonitoringDate,
  3778. PatientId: monitor.PatientId,
  3779. Module: 3,
  3780. AdminUserId: adminInfo.AdminUser.Id,
  3781. Ctime: time.Now().Unix(),
  3782. Mtime: 0,
  3783. Status: 1,
  3784. UserOrgId: monitor.UserOrgId,
  3785. ErrLog: string(byterequest),
  3786. Source: "电脑端删除监测",
  3787. }
  3788. service.CreateMonitorRecordLog(monitorRecordLog)
  3789. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3790. redis := service.RedisClient()
  3791. //清空key 值
  3792. redis.Set(key, "", time.Second)
  3793. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3794. redis.Set(keyOne, "", time.Second)
  3795. defer redis.Close()
  3796. if err != nil {
  3797. this.ErrorLog("删除透析监测记录失败:%v", err)
  3798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3799. return
  3800. }
  3801. this.ServeSuccessJSON(map[string]interface{}{
  3802. "record_id": monitor.ID,
  3803. })
  3804. }
  3805. func (c *DialysisApiController) CreateMonitor() {
  3806. patient, _ := c.GetInt64("id", 0)
  3807. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3808. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3809. operate_time, _ := c.GetInt64("operate_time", 0)
  3810. // monitoring_time := c.GetString("monitoring_time")
  3811. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3812. breathing_rated := c.GetString("breathing_rated")
  3813. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3814. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3815. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3816. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3817. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3818. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3819. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3820. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3821. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3822. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3823. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3824. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3825. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3826. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3827. temperature, _ := c.GetFloat("temperature", 0)
  3828. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3829. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3830. conductivity, _ := c.GetFloat("conductivity", 0)
  3831. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3832. heparin, _ := c.GetFloat("heparin", 0)
  3833. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3834. ktv, _ := c.GetFloat("ktv", 0)
  3835. symptom := c.GetString("symptom")
  3836. dispose := c.GetString("dispose")
  3837. result := c.GetString("results")
  3838. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3839. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3840. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3841. replacement_speed, _ := c.GetFloat("replacement_speed")
  3842. dicarbonate, _ := c.GetFloat("dicarbonate")
  3843. monitoring_date = monitoring_date / 1000
  3844. // operate_time = operate_time / 1000
  3845. if patient <= 0 {
  3846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3847. return
  3848. }
  3849. adminUserInfo := c.GetAdminUserInfo()
  3850. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3851. if patientInfo.ID == 0 {
  3852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3853. return
  3854. }
  3855. monitorRecord := models.MonitoringRecord{
  3856. PatientId: patient,
  3857. MonitoringDate: monitoring_date,
  3858. DialysisOrderId: dialysis_order_id,
  3859. OperateTime: operate_time,
  3860. // MonitoringTime: monitoring_time,
  3861. PulseFrequency: pulse_frequency,
  3862. BreathingRate: breathing_rated,
  3863. SystolicBloodPressure: systolic_blood_pressure,
  3864. DiastolicBloodPressure: diastolic_blood_pressure,
  3865. BloodPressureType: blood_pressure_type,
  3866. BloodFlowVolume: blood_flow_volume,
  3867. VenousPressure: venous_pressure,
  3868. VenousPressureType: venous_pressure_type,
  3869. TransmembranePressure: transmembrane_pressure,
  3870. TransmembranePressureType: transmembrane_pressure_type,
  3871. UltrafiltrationRate: ultrafiltration_rate,
  3872. UltrafiltrationVolume: ultrafiltration_volume,
  3873. SodiumConcentration: sodium_concentration,
  3874. ArterialPressure: arterial_pressure,
  3875. ArterialPressureType: arterial_pressure_type,
  3876. DialysateTemperature: dialysate_temperature,
  3877. Temperature: temperature,
  3878. ReplacementRate: replacement_rate,
  3879. DisplacementQuantity: displacement_quantity,
  3880. Ktv: ktv,
  3881. Symptom: symptom,
  3882. Dispose: dispose,
  3883. Result: result,
  3884. MonitoringNurse: monitoring_nurse,
  3885. Status: 1,
  3886. CreatedTime: time.Now().Unix(),
  3887. UpdatedTime: time.Now().Unix(),
  3888. UserOrgId: adminUserInfo.CurrentOrgId,
  3889. Conductivity: conductivity,
  3890. DisplacementFlowQuantity: displacement_flow_quantity,
  3891. Heparin: heparin,
  3892. DialysateFlow: dialysate_flow,
  3893. MonitorAnticoagulant: monitor_anticoagulant,
  3894. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3895. ReplacementSpeed: replacement_speed,
  3896. Dicarbonate: dicarbonate,
  3897. }
  3898. // 查询信息规挡的设置天数
  3899. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3900. if infor.ID > 0 && infor.WeekDay > 0 {
  3901. var cha_time int64
  3902. timeNowStr := time.Now().Format("2006-01-02")
  3903. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3904. //今日的日期减去设置的日期
  3905. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3906. if cha_time >= monitoring_date {
  3907. //查询审核是否允许
  3908. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  3909. //申请状态不允许的情况 拒绝修改
  3910. if infor.ApplicationStatus != 1 {
  3911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3912. return
  3913. }
  3914. }
  3915. }
  3916. err := service.CreateMonitor(&monitorRecord)
  3917. finish := models.XtDialysisFinish{
  3918. IsFinish: 1,
  3919. UserOrgId: adminUserInfo.CurrentOrgId,
  3920. Status: 1,
  3921. Ctime: time.Now().Unix(),
  3922. Mtime: 0,
  3923. Module: 7,
  3924. RecordDate: monitoring_date,
  3925. Sourse: 1,
  3926. PatientId: patient,
  3927. }
  3928. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3929. if dialysisFinish.ID == 0 {
  3930. service.CreateDialysisFinish(finish)
  3931. }
  3932. redis := service.RedisClient()
  3933. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3934. redis.Set(key, "", time.Second)
  3935. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3936. redis.Set(keyOne, "", time.Second)
  3937. redis.Close()
  3938. if err != nil {
  3939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3940. return
  3941. }
  3942. c.ServeSuccessJSON(map[string]interface{}{
  3943. "msg": "ok",
  3944. "monitor": monitorRecord,
  3945. })
  3946. return
  3947. }
  3948. // 已弃用
  3949. // func (c *DialysisApiController) CreateRecordData() {
  3950. // patient, _ := c.GetInt64("id", 0)
  3951. // status, _ := c.GetInt64("status", 0)
  3952. // now := time.Now()
  3953. // year, month, day := now.Date()
  3954. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3955. // todayTimeStamp := today_time.Unix()
  3956. // if patient <= 0 {
  3957. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3958. // return
  3959. // }
  3960. // adminUserInfo := c.GetAdminUserInfo()
  3961. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3962. // if patientInfo.ID == 0 {
  3963. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3964. // return
  3965. // }
  3966. // record := &models.DialysisOrder{
  3967. // DialysisDate: todayTimeStamp,
  3968. // UserOrgId: adminUserInfo.CurrentOrgId,
  3969. // PatientId: patient,
  3970. // Stage: status,
  3971. // Status: 1,
  3972. // CreatedTime: time.Now().Unix(),
  3973. // UpdatedTime: time.Now().Unix(),
  3974. // }
  3975. // if status == 1 {
  3976. // //创建透析记录
  3977. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3978. // if err == nil {
  3979. // c.ServeSuccessJSON(map[string]interface{}{
  3980. // "dialysisOrder": record,
  3981. // })
  3982. // } else {
  3983. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3984. // }
  3985. // } else {
  3986. // record_id, _ := c.GetInt64("record_id", 0)
  3987. // //修改透析记录状态
  3988. // errs := service.ModifyDialysisRecord(record_id)
  3989. // //结束时候透析次数加1
  3990. // service.UpdateSolutionByPatientId(patient)
  3991. // if errs == nil {
  3992. // c.ServeSuccessJSON(map[string]interface{}{
  3993. // "dialysisOrder": record,
  3994. // })
  3995. // } else {
  3996. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3997. // }
  3998. // }
  3999. // }
  4000. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  4001. dataBody := make(map[string]interface{}, 0)
  4002. err := json.Unmarshal(data, &dataBody)
  4003. if err != nil {
  4004. utils.ErrorLog(err.Error())
  4005. code = enums.ErrorCodeParamWrong
  4006. return
  4007. }
  4008. timeLayout := "2006-01-02 "
  4009. timeLayout2 := "2006-01-02 15:04"
  4010. loc, _ := time.LoadLocation("Local")
  4011. if action == "create" {
  4012. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4013. utils.ErrorLog("advice_type")
  4014. code = enums.ErrorCodeParamWrong
  4015. return
  4016. }
  4017. adviceType := int64(dataBody["advice_type"].(float64))
  4018. if adviceType != 1 && adviceType != 2 {
  4019. utils.ErrorLog("advice_type != 1&&2")
  4020. code = enums.ErrorCodeParamWrong
  4021. return
  4022. }
  4023. advice.AdviceType = adviceType
  4024. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4025. utils.ErrorLog("advice_date")
  4026. code = enums.ErrorCodeParamWrong
  4027. return
  4028. }
  4029. adviceDate, _ := dataBody["advice_date"].(string)
  4030. if len(adviceDate) == 0 {
  4031. utils.ErrorLog("len(adviceDate) == 0")
  4032. code = enums.ErrorCodeParamWrong
  4033. return
  4034. }
  4035. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4036. if err != nil {
  4037. utils.ErrorLog(err.Error())
  4038. code = enums.ErrorCodeParamWrong
  4039. return
  4040. }
  4041. advice.AdviceDate = theTime.Unix()
  4042. }
  4043. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4044. utils.ErrorLog("start_time")
  4045. code = enums.ErrorCodeParamWrong
  4046. return
  4047. }
  4048. startDate, _ := dataBody["start_time"].(string)
  4049. if len(startDate) == 0 {
  4050. utils.ErrorLog("len(startDate) == 0")
  4051. code = enums.ErrorCodeParamWrong
  4052. return
  4053. }
  4054. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  4055. if err != nil {
  4056. utils.ErrorLog(err.Error())
  4057. code = enums.ErrorCodeParamWrong
  4058. return
  4059. }
  4060. advice.StartTime = theTime.Unix()
  4061. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4062. utils.ErrorLog("advice_name")
  4063. code = enums.ErrorCodeParamWrong
  4064. return
  4065. }
  4066. adviceName, _ := dataBody["advice_name"].(string)
  4067. if len(adviceName) == 0 {
  4068. utils.ErrorLog("len(advice_name) == 0")
  4069. code = enums.ErrorCodeParamWrong
  4070. return
  4071. }
  4072. advice.AdviceName = adviceName
  4073. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  4074. utils.ErrorLog("delivery_way")
  4075. code = enums.ErrorCodeParamWrong
  4076. return
  4077. }
  4078. deliveryWay, _ := dataBody["delivery_way"].(string)
  4079. if len(deliveryWay) == 0 {
  4080. utils.ErrorLog("len(deliveryWay) == 0")
  4081. code = enums.ErrorCodeParamWrong
  4082. return
  4083. }
  4084. advice.DeliveryWay = deliveryWay
  4085. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  4086. utils.ErrorLog("execution_frequency")
  4087. code = enums.ErrorCodeParamWrong
  4088. return
  4089. }
  4090. execution_frequency, _ := dataBody["execution_frequency"].(string)
  4091. if len(execution_frequency) == 0 {
  4092. utils.ErrorLog("len(execution_frequency) == 0")
  4093. code = enums.ErrorCodeParamWrong
  4094. return
  4095. }
  4096. advice.ExecutionFrequency = execution_frequency
  4097. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4098. adviceDsc, _ := dataBody["advice_desc"].(string)
  4099. advice.AdviceDesc = adviceDsc
  4100. }
  4101. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4102. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4103. advice.DrugSpecUnit = drugSpecUnit
  4104. }
  4105. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4106. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4107. advice.SingleDose = singleDose
  4108. }
  4109. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4110. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4111. advice.SingleDoseUnit = singleDoseUnit
  4112. }
  4113. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4114. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4115. advice.PrescribingNumber = prescribingNumber
  4116. }
  4117. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4118. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4119. advice.PrescribingNumberUnit = prescribingNumberUnit
  4120. }
  4121. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  4122. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  4123. if len(thisContagions) > 0 {
  4124. for _, item := range thisContagions {
  4125. items := item.(map[string]interface{})
  4126. advice_name, _ := items["advice_name"].(string)
  4127. advice_desc, _ := items["advice_desc"].(string)
  4128. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  4129. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  4130. single_dose_unit, _ := items["single_dose_unit"].(string)
  4131. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  4132. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  4133. advice := &models.DoctorAdvice{
  4134. AdviceName: advice_name,
  4135. AdviceDesc: advice_desc,
  4136. SingleDose: single_dose,
  4137. SingleDoseUnit: single_dose_unit,
  4138. DrugSpecUnit: drug_spec_unit,
  4139. PrescribingNumber: prescribing_number,
  4140. PrescribingNumberUnit: prescribing_number_unit,
  4141. }
  4142. subAdvice = append(subAdvice, advice)
  4143. }
  4144. }
  4145. }
  4146. return
  4147. }
  4148. func (c *DialysisApiController) GetDialysisOrder() {
  4149. //xtno := c.GetString("xtno")
  4150. xtdate := c.GetString("xtdate")
  4151. patient_id, _ := c.GetInt64("patient_id")
  4152. timeLayout := "2006-01-02"
  4153. loc, _ := time.LoadLocation("Local")
  4154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4155. if err != nil {
  4156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4157. return
  4158. }
  4159. xttime := theTime.Unix()
  4160. operatorIDs := make([]int64, 0)
  4161. adminUserInfo := c.GetAdminUserInfo()
  4162. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4163. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  4164. //透析单
  4165. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4166. if dialysisOrder != nil {
  4167. if dialysisOrder.FinishNurse > 0 {
  4168. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4169. }
  4170. if dialysisOrder.StartNurse > 0 {
  4171. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4172. }
  4173. }
  4174. //透前评估
  4175. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4176. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  4177. //透后评估
  4178. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4179. if AssessmentAfterDislysis.Modifier > 0 {
  4180. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4181. }
  4182. //上次透前评估
  4183. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4184. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4185. //透析处方
  4186. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4187. if dialysisPrescription.PrescriptionDoctor > 0 {
  4188. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4189. }
  4190. //获取病人的透析模式
  4191. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4192. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4193. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4194. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4195. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4196. //获取透析处方
  4197. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4198. //获取临时医嘱
  4199. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4200. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4201. //获取医嘱内容
  4202. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4203. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4204. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4205. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4206. //获取上次的透后体重
  4207. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4208. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4209. //获取透析次数
  4210. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4211. if len(DoctorAdvice) > 0 {
  4212. for _, item := range DoctorAdvice {
  4213. if item.AdviceDoctor > 0 {
  4214. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4215. }
  4216. if item.ExecutionStaff > 0 {
  4217. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4218. }
  4219. if item.Checker > 0 {
  4220. operatorIDs = append(operatorIDs, item.Checker)
  4221. }
  4222. }
  4223. }
  4224. //透析监测
  4225. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4226. //透析检测
  4227. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4228. //透析小结
  4229. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4230. //接诊评估
  4231. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4232. if receiverTreatmentAccess.Condition == 1 {
  4233. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  4234. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4235. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  4236. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  4237. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  4238. }
  4239. }
  4240. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4241. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  4242. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4243. patientInfo.TotalDialysis = dialysis_count
  4244. }
  4245. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  4246. if xttime <= 1735574400 {
  4247. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4248. patientInfo.TotalDialysis = dialysis_count
  4249. }
  4250. if xttime >= 1735660800 {
  4251. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4252. patientInfo.TotalDialysis = dialysis_count
  4253. }
  4254. }
  4255. //相关操作对应的操作人
  4256. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  4257. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4258. //fmt.Println("operators------------------------------------", operators)
  4259. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  4260. //获取当前日期月份的第一天
  4261. firstmonth := service.GetFirstDateOfMonth(theTime)
  4262. firstMonthDate := firstmonth.Unix()
  4263. //获取当前月份的病人透析次数
  4264. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  4265. var hisAdvice []*models.HisDoctorAdviceInfo
  4266. var his_advices_one []*models.HisDoctorAdviceInfo
  4267. //获取his数据
  4268. hisAdvice, _ = service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4269. //针对茂名舒和
  4270. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4271. if len(hisAdvice) > 0 {
  4272. for _, item := range hisAdvice {
  4273. drug, _ := service.GetDrugIsShow(item.DrugId, adminUserInfo.CurrentOrgId)
  4274. if drug.IsShow == 1 {
  4275. his_advices_one = append(his_advices_one, item)
  4276. }
  4277. }
  4278. }
  4279. } else {
  4280. if len(hisAdvice) > 0 {
  4281. for _, item := range hisAdvice {
  4282. his_advices_one = append(his_advices_one, item)
  4283. }
  4284. }
  4285. }
  4286. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4287. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4288. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  4289. var projects []*models.HisPrescriptionProject
  4290. projects, _ = service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4291. var projectsOne []*models.HisPrescriptionProject
  4292. //针对茂名舒和
  4293. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4294. if len(projects) > 0 {
  4295. for _, item := range projects {
  4296. if item.Type == 2 {
  4297. if item.HisProject.IsShow == 1 {
  4298. projectsOne = append(projectsOne, item)
  4299. }
  4300. }
  4301. if item.Type == 3 {
  4302. if item.GoodInfo.IsShow == 1 {
  4303. projectsOne = append(projectsOne, item)
  4304. }
  4305. }
  4306. }
  4307. }
  4308. } else {
  4309. for _, item := range projects {
  4310. projectsOne = append(projectsOne, item)
  4311. }
  4312. }
  4313. //获取诊断
  4314. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4315. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  4316. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4317. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  4318. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4319. // for _, item := range projects {
  4320. // var advice *models.HisDoctorAdviceInfo
  4321. // advice.ID = item.ID
  4322. // advice.Checker = item.Checker
  4323. // advice.CheckTime = item.CheckTime
  4324. // advice.CheckState = item.CheckState
  4325. // advice.ExecutionState = item.ExecutionState
  4326. // advice.ExecutionStaff = item.ExecutionStaff
  4327. // advice.PrescribingNumber = float64(item.Count)
  4328. // advice.PrescribingNumberUnit = item.Unit
  4329. // advice.AdviceDoctor = item.Doctor
  4330. // if item.Type == 3 {
  4331. // advice.AdviceName = item.GoodInfo.GoodName
  4332. // } else if item.Type == 2 {
  4333. // advice.AdviceName = item.HisProject.ProjectName
  4334. // }
  4335. // advice.StartTime = item.StartTime
  4336. // hisAdvice = append(hisAdvice, advice)
  4337. // }
  4338. //}
  4339. if config.IsOpen == 1 {
  4340. c.ServeSuccessJSON(map[string]interface{}{
  4341. "xtdate": xtdate,
  4342. "users": adminUser,
  4343. "patientInfo": patientInfo,
  4344. "PredialysisEvaluation": PredialysisEvaluation,
  4345. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4346. "dialysisPrescription": dialysisPrescription,
  4347. "advices": his_advices_one,
  4348. "monitors": Record,
  4349. "summary": TreatmentSummary,
  4350. "receiverTreatmentAccess": receiverTreatmentAccess,
  4351. "dialysisOrder": dialysisOrder,
  4352. "operators": operators,
  4353. "org_template_info": templateInfo,
  4354. "check": check,
  4355. "schedule": schedule,
  4356. "dialysisway": dialysisway,
  4357. "order": order,
  4358. "doctorAdvice": doctorAdvice,
  4359. "doctor": doctor,
  4360. "nurse": nurse,
  4361. "doctorAdevieInfo": doctorAdevieInfo,
  4362. "total": total,
  4363. "startNuse": startNuse,
  4364. "DoctorName": DoctorName,
  4365. "assessmentAfterDislysis": assessmentAfterDislysis,
  4366. "predialysName": predialysName,
  4367. "FinishNuse": FinishNuse,
  4368. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4369. "dialysiscount": dialysiscount,
  4370. "last_order": lastOrder,
  4371. "project_config": project_config,
  4372. "projects": projectsOne,
  4373. "prescriptionInfo": prescriptionInfo,
  4374. "patientDiagnose": patientDiagnose,
  4375. "lastSchedule": lastSchedule,
  4376. "numberList": numberList,
  4377. })
  4378. }
  4379. if config.IsOpen == 0 || config.IsOpen == 2 {
  4380. c.ServeSuccessJSON(map[string]interface{}{
  4381. "xtdate": xtdate,
  4382. "users": adminUser,
  4383. "patientInfo": patientInfo,
  4384. "PredialysisEvaluation": PredialysisEvaluation,
  4385. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4386. "dialysisPrescription": dialysisPrescription,
  4387. "advices": DoctorAdvice,
  4388. "monitors": Record,
  4389. "summary": TreatmentSummary,
  4390. "receiverTreatmentAccess": receiverTreatmentAccess,
  4391. "dialysisOrder": dialysisOrder,
  4392. "operators": operators,
  4393. "org_template_info": templateInfo,
  4394. "check": check,
  4395. "schedule": schedule,
  4396. "dialysisway": dialysisway,
  4397. "order": order,
  4398. "doctorAdvice": doctorAdvice,
  4399. "doctor": doctor,
  4400. "nurse": nurse,
  4401. "doctorAdevieInfo": doctorAdevieInfo,
  4402. "total": total,
  4403. "startNuse": startNuse,
  4404. "DoctorName": DoctorName,
  4405. "assessmentAfterDislysis": assessmentAfterDislysis,
  4406. "predialysName": predialysName,
  4407. "FinishNuse": FinishNuse,
  4408. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4409. "dialysiscount": dialysiscount,
  4410. "last_order": lastOrder,
  4411. "project_config": project_config,
  4412. "projects": projects,
  4413. "prescriptionInfo": prescriptionInfo,
  4414. "patientDiagnose": patientDiagnose,
  4415. "lastSchedule": lastSchedule,
  4416. "numberList": numberList,
  4417. })
  4418. }
  4419. }
  4420. func (c *DialysisApiController) GetLongAdvice() {
  4421. patient_id, _ := c.GetInt64("patient_id")
  4422. adminUserInfo := c.GetAdminUserInfo()
  4423. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4424. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4425. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4426. c.ServeSuccessJSON(map[string]interface{}{
  4427. "status": "1",
  4428. })
  4429. return
  4430. } else { //开启推送提醒
  4431. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4432. var advice_three []*models.DoctorAdvice
  4433. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4434. recordDateStr := time.Now().Format("2006-01-02")
  4435. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4436. nowtime := recordDate.Unix()
  4437. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4438. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4439. for _, advice := range advices {
  4440. if advice.FrequencyType == 3 {
  4441. t := time.Now()
  4442. week := int(t.Weekday())
  4443. switch week {
  4444. case 1:
  4445. if strings.Index(advice.WeekDay, "周一") == -1 {
  4446. advice_three = append(advice_three, advice)
  4447. }
  4448. break
  4449. case 2:
  4450. if strings.Index(advice.WeekDay, "周二") == -1 {
  4451. advice_three = append(advice_three, advice)
  4452. }
  4453. break
  4454. case 3:
  4455. if strings.Index(advice.WeekDay, "周三") == -1 {
  4456. advice_three = append(advice_three, advice)
  4457. }
  4458. break
  4459. case 4:
  4460. if strings.Index(advice.WeekDay, "周四") == -1 {
  4461. advice_three = append(advice_three, advice)
  4462. }
  4463. break
  4464. case 5:
  4465. if strings.Index(advice.WeekDay, "周五") == -1 {
  4466. advice_three = append(advice_three, advice)
  4467. }
  4468. break
  4469. case 6:
  4470. if strings.Index(advice.WeekDay, "周六") == -1 {
  4471. advice_three = append(advice_three, advice)
  4472. }
  4473. break
  4474. case 0:
  4475. if strings.Index(advice.WeekDay, "周日") == -1 {
  4476. advice_three = append(advice_three, advice)
  4477. }
  4478. break
  4479. }
  4480. }
  4481. }
  4482. for _, advice := range advices_two {
  4483. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4484. now := p.Unix()
  4485. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4486. dayStr2 := "-" + dayStr
  4487. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4488. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4489. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4490. for _, ad := range advices {
  4491. advice_three = append(advice_three, ad)
  4492. }
  4493. }
  4494. if err == nil {
  4495. c.ServeSuccessJSON(map[string]interface{}{
  4496. "status": "2",
  4497. "advices": advices,
  4498. "advices_two": RemoveRepeatedElement(advice_three),
  4499. "is_open_remind": config.IsOpenRemind,
  4500. })
  4501. }
  4502. }
  4503. }
  4504. func (c *DialysisApiController) GetLongAdviceOne() {
  4505. patient_id, _ := c.GetInt64("patient_id")
  4506. schedule_date := c.GetString("schedule_date")
  4507. adminUserInfo := c.GetAdminUserInfo()
  4508. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4509. timeLayout := "2006-01-02"
  4510. loc, _ := time.LoadLocation("Local")
  4511. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4512. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4513. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4514. c.ServeSuccessJSON(map[string]interface{}{
  4515. "status": "1",
  4516. })
  4517. return
  4518. } else { //开启推送提醒
  4519. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4520. var advice_three []*models.DoctorAdvice
  4521. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4522. //recordDateStr := time.Now().Format("2006-01-02")
  4523. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4524. //
  4525. //nowtime := recordDate.Unix()
  4526. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4527. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4528. for _, advice := range advices {
  4529. if advice.FrequencyType == 3 {
  4530. t := time.Now()
  4531. week := int(t.Weekday())
  4532. switch week {
  4533. case 1:
  4534. if strings.Index(advice.WeekDay, "周一") == -1 {
  4535. advice_three = append(advice_three, advice)
  4536. }
  4537. break
  4538. case 2:
  4539. if strings.Index(advice.WeekDay, "周二") == -1 {
  4540. advice_three = append(advice_three, advice)
  4541. }
  4542. break
  4543. case 3:
  4544. if strings.Index(advice.WeekDay, "周三") == -1 {
  4545. advice_three = append(advice_three, advice)
  4546. }
  4547. break
  4548. case 4:
  4549. if strings.Index(advice.WeekDay, "周四") == -1 {
  4550. advice_three = append(advice_three, advice)
  4551. }
  4552. break
  4553. case 5:
  4554. if strings.Index(advice.WeekDay, "周五") == -1 {
  4555. advice_three = append(advice_three, advice)
  4556. }
  4557. break
  4558. case 6:
  4559. if strings.Index(advice.WeekDay, "周六") == -1 {
  4560. advice_three = append(advice_three, advice)
  4561. }
  4562. break
  4563. case 0:
  4564. if strings.Index(advice.WeekDay, "周日") == -1 {
  4565. advice_three = append(advice_three, advice)
  4566. }
  4567. break
  4568. }
  4569. }
  4570. }
  4571. for _, advice := range advices_two {
  4572. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4573. now := p.Unix()
  4574. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4575. dayStr2 := "-" + dayStr
  4576. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4577. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4578. fmt.Println("oldTime--------------------------", oldTime)
  4579. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4580. fmt.Println("advices-------------------------", advices)
  4581. for _, ad := range advices {
  4582. advice_three = append(advice_three, ad)
  4583. }
  4584. }
  4585. if err == nil {
  4586. c.ServeSuccessJSON(map[string]interface{}{
  4587. "status": "2",
  4588. "advices": advices,
  4589. "advices_two": RemoveRepeatedElement(advice_three),
  4590. "is_open_remind": config.IsOpenRemind,
  4591. })
  4592. }
  4593. }
  4594. }
  4595. func (c *DialysisApiController) GetLongAdviceTwo() {
  4596. patient_id, _ := c.GetInt64("patient_id")
  4597. schedule_date, _ := c.GetInt64("schedule_date")
  4598. adminUserInfo := c.GetAdminUserInfo()
  4599. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4600. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4601. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4602. c.ServeSuccessJSON(map[string]interface{}{
  4603. "status": "1",
  4604. })
  4605. return
  4606. } else { //开启推送提醒
  4607. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4608. var advice_three []*models.DoctorAdvice
  4609. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4610. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4611. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4612. for _, advice := range advices {
  4613. if advice.FrequencyType == 3 {
  4614. t := time.Now()
  4615. week := int(t.Weekday())
  4616. switch week {
  4617. case 1:
  4618. if strings.Index(advice.WeekDay, "周一") == -1 {
  4619. advice_three = append(advice_three, advice)
  4620. }
  4621. break
  4622. case 2:
  4623. if strings.Index(advice.WeekDay, "周二") == -1 {
  4624. advice_three = append(advice_three, advice)
  4625. }
  4626. break
  4627. case 3:
  4628. if strings.Index(advice.WeekDay, "周三") == -1 {
  4629. advice_three = append(advice_three, advice)
  4630. }
  4631. break
  4632. case 4:
  4633. if strings.Index(advice.WeekDay, "周四") == -1 {
  4634. advice_three = append(advice_three, advice)
  4635. }
  4636. break
  4637. case 5:
  4638. if strings.Index(advice.WeekDay, "周五") == -1 {
  4639. advice_three = append(advice_three, advice)
  4640. }
  4641. break
  4642. case 6:
  4643. if strings.Index(advice.WeekDay, "周六") == -1 {
  4644. advice_three = append(advice_three, advice)
  4645. }
  4646. break
  4647. case 0:
  4648. if strings.Index(advice.WeekDay, "周日") == -1 {
  4649. advice_three = append(advice_three, advice)
  4650. }
  4651. break
  4652. }
  4653. }
  4654. }
  4655. for _, advice := range advices_two {
  4656. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4657. now := p.Unix()
  4658. fmt.Println("now-------------------------", now)
  4659. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4660. dayStr2 := "-" + dayStr
  4661. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4662. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4663. fmt.Println("oldTime--------------------------", oldTime)
  4664. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4665. for _, ad := range advices {
  4666. advice_three = append(advice_three, ad)
  4667. }
  4668. }
  4669. if err == nil {
  4670. c.ServeSuccessJSON(map[string]interface{}{
  4671. "status": "2",
  4672. "advices": advices,
  4673. "advices_two": RemoveRepeatedElement(advice_three),
  4674. "is_open_remind": config.IsOpenRemind,
  4675. })
  4676. }
  4677. }
  4678. }
  4679. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4680. newArr = make([]*models.DoctorAdvice, 0)
  4681. for i := 0; i < len(arr); i++ {
  4682. repeat := false
  4683. for j := i + 1; j < len(arr); j++ {
  4684. if arr[i].ID == arr[j].ID {
  4685. repeat = true
  4686. break
  4687. }
  4688. }
  4689. if !repeat {
  4690. newArr = append(newArr, arr[i])
  4691. }
  4692. }
  4693. return
  4694. }
  4695. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4696. patient, _ := c.GetInt64("id", 0)
  4697. groupNo, _ := c.GetInt64("groupno", 0)
  4698. if patient <= 0 {
  4699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4700. return
  4701. }
  4702. adminUserInfo := c.GetAdminUserInfo()
  4703. dataBody := make(map[string]interface{}, 0)
  4704. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4705. if err != nil {
  4706. utils.ErrorLog(err.Error())
  4707. return
  4708. }
  4709. utils.ErrorLog("%v", dataBody)
  4710. timeLayout := "2006-01-02 15:04"
  4711. loc, _ := time.LoadLocation("Local")
  4712. timeLayout2 := "2006-01-02"
  4713. loc2, _ := time.LoadLocation("Local")
  4714. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4715. utils.ErrorLog("advice_type")
  4716. return
  4717. }
  4718. adviceType := int64(2)
  4719. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4720. utils.ErrorLog("advice_date")
  4721. return
  4722. }
  4723. adviceDate, _ := dataBody["advice_date"].(string)
  4724. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4725. AdviceDate := theTime.Unix()
  4726. RecordDate := theTime.Unix()
  4727. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4728. utils.ErrorLog("start_time")
  4729. return
  4730. }
  4731. startTime, _ := dataBody["start_time"].(string)
  4732. if len(startTime) == 0 {
  4733. utils.ErrorLog("len(start_time) == 0")
  4734. return
  4735. }
  4736. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4737. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4738. //if err != nil {
  4739. // utils.ErrorLog(err.Error())
  4740. // return
  4741. //}
  4742. StartTime := theTimeUnix.Unix()
  4743. fmt.Println("startTIME", StartTime)
  4744. Remark := ""
  4745. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4746. remark, _ := dataBody["remark"].(string)
  4747. Remark = remark
  4748. }
  4749. var advices []*models.GroupAdvice
  4750. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4751. utils.ErrorLog("advices")
  4752. return
  4753. }
  4754. adviceNames := dataBody["advices"].([]interface{})
  4755. for _, adviceNameMap := range adviceNames {
  4756. adviceNameM := adviceNameMap.(map[string]interface{})
  4757. var advice models.GroupAdvice
  4758. advice.Remark = Remark
  4759. advice.AdviceType = adviceType
  4760. advice.StartTime = StartTime
  4761. if advice.StartTime < 0 {
  4762. advice.StartTime = time.Now().Unix()
  4763. }
  4764. advice.AdviceDate = AdviceDate
  4765. advice.RecordDate = RecordDate
  4766. advice.Status = 1
  4767. advice.CreatedTime = time.Now().Unix()
  4768. advice.UpdatedTime = time.Now().Unix()
  4769. advice.StopState = 2
  4770. advice.ExecutionState = 2
  4771. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4772. advice.PatientId = patient
  4773. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4774. advice.IsSettle = 2
  4775. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4776. utils.ErrorLog("advice_name")
  4777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4778. return
  4779. }
  4780. adviceName, _ := adviceNameM["advice_name"].(string)
  4781. if len(adviceName) == 0 {
  4782. utils.ErrorLog("len(advice_name) == 0")
  4783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4784. return
  4785. }
  4786. advice.AdviceName = adviceName
  4787. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4788. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4789. advice.DrugSpec = drugSpec
  4790. }
  4791. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4792. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4793. advice.AdviceDesc = adviceDesc
  4794. }
  4795. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4796. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4797. advice.DrugSpecUnit = drugSpecUnit
  4798. }
  4799. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4800. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4801. // advice.SingleDose = singleDose
  4802. //}
  4803. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4804. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4805. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4806. }
  4807. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4808. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4809. advice.SingleDoseUnit = singleDoseUnit
  4810. }
  4811. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4812. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4813. // advice.PrescribingNumber = prescribingNumber
  4814. //}
  4815. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4816. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4817. }
  4818. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4819. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4820. advice.PrescribingNumberUnit = prescribingNumberUnit
  4821. }
  4822. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4823. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4824. advice.DeliveryWay = deliveryWay
  4825. }
  4826. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4827. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4828. advice.ExecutionFrequency = executionFrequency
  4829. }
  4830. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4831. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4832. advice.FrequencyType = frequency_type
  4833. }
  4834. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4835. day_count := int64(adviceNameM["day_count"].(float64))
  4836. advice.DayCount = day_count
  4837. }
  4838. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4839. way := int64(adviceNameM["way"].(float64))
  4840. advice.Way = way
  4841. }
  4842. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4843. drug_id := int64(adviceNameM["drug_id"].(float64))
  4844. advice.DrugId = drug_id
  4845. }
  4846. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4847. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4848. advice.DrugNameId = drug_name_id
  4849. }
  4850. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4851. week_day, _ := adviceNameM["week_day"].(string)
  4852. advice.WeekDay = week_day
  4853. }
  4854. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4855. template_id, _ := adviceNameM["template_id"].(string)
  4856. advice.TemplateId = template_id
  4857. }
  4858. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4859. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4860. advice.ExecutionFrequency = executionFrequency
  4861. }
  4862. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4863. children := adviceNameM["child"].([]interface{})
  4864. if len(children) > 0 {
  4865. for _, childrenMap := range children {
  4866. childMap := childrenMap.(map[string]interface{})
  4867. var child models.GroupAdvice
  4868. child.Remark = Remark
  4869. child.AdviceType = adviceType
  4870. child.StartTime = StartTime
  4871. if child.StartTime < 0 {
  4872. child.StartTime = time.Now().Unix()
  4873. }
  4874. child.AdviceDate = AdviceDate
  4875. child.RecordDate = RecordDate
  4876. child.Status = 1
  4877. child.CreatedTime = time.Now().Unix()
  4878. child.UpdatedTime = time.Now().Unix()
  4879. child.StopState = 2
  4880. child.ExecutionState = 2
  4881. child.UserOrgId = adminUserInfo.CurrentOrgId
  4882. child.PatientId = patient
  4883. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4884. child.IsSettle = 2
  4885. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4886. utils.ErrorLog("child advice_name")
  4887. return
  4888. }
  4889. childAdviceName, _ := childMap["advice_name"].(string)
  4890. if len(childAdviceName) == 0 {
  4891. utils.ErrorLog("len(child advice_name) == 0")
  4892. return
  4893. }
  4894. child.AdviceName = childAdviceName
  4895. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4896. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4897. child.AdviceDesc = childAdviceDesc
  4898. }
  4899. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4900. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4901. child.DrugSpec = childDrugSpec
  4902. }
  4903. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4904. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4905. child.DrugSpecUnit = childDrugSpecUnit
  4906. }
  4907. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4908. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4909. child.SingleDose = childSingleDose
  4910. }
  4911. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4912. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4913. child.SingleDose = childMap["single_dose"].(float64)
  4914. }
  4915. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4916. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4917. child.Remark = childMap["remark"].(string)
  4918. }
  4919. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4920. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4921. child.DrugId = int64(childMap["drug_id"].(float64))
  4922. }
  4923. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4924. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4925. child.SingleDoseUnit = childSingleDoseUnit
  4926. }
  4927. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4928. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4929. child.PrescribingNumber = childPrescribingNumber
  4930. }
  4931. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4932. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4933. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4934. }
  4935. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4936. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4937. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4938. }
  4939. child.DeliveryWay = advice.DeliveryWay
  4940. child.ExecutionFrequency = advice.ExecutionFrequency
  4941. advice.Children = append(advice.Children, &child)
  4942. }
  4943. }
  4944. }
  4945. advices = append(advices, &advice)
  4946. }
  4947. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4948. for _, item := range advices {
  4949. //记录日志
  4950. byterequest, _ := json.Marshal(item)
  4951. adviceLog := models.XtDoctorAdviceLog{
  4952. UserOrgId: item.UserOrgId,
  4953. PatientId: item.PatientId,
  4954. AdminUserId: adminUserInfo.AdminUser.Id,
  4955. Module: 1,
  4956. ErrLog: string(byterequest),
  4957. Status: 1,
  4958. Ctime: time.Now().Unix(),
  4959. Mtime: 0,
  4960. Source: "电脑端医嘱推送",
  4961. RecordDate: item.AdviceDate,
  4962. }
  4963. service.CreateDoctorAdviceLog(adviceLog)
  4964. }
  4965. //创建步骤表
  4966. finish := models.XtDialysisFinish{
  4967. IsFinish: 1,
  4968. UserOrgId: adminUserInfo.CurrentOrgId,
  4969. Status: 1,
  4970. Ctime: time.Now().Unix(),
  4971. Mtime: 0,
  4972. Module: 4,
  4973. RecordDate: AdviceDate,
  4974. Sourse: 1,
  4975. PatientId: patient,
  4976. }
  4977. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4978. if dialysisFinish.ID == 0 {
  4979. service.CreateDialysisFinish(finish)
  4980. }
  4981. redis := service.RedisClient()
  4982. formatAdviceDate := theTime.Format("2006-01-02")
  4983. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4984. redis.Set(key, "", time.Second)
  4985. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4986. redis.Set(keyOne, "", time.Second)
  4987. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4988. redis.Set(keyFour, "", time.Second)
  4989. defer redis.Close()
  4990. if err != nil {
  4991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4992. return
  4993. }
  4994. c.ServeSuccessJSON(map[string]interface{}{
  4995. "msg": "ok",
  4996. "advices": list,
  4997. })
  4998. return
  4999. }
  5000. func (c *DialysisApiController) GetSolution() {
  5001. patient_id, _ := c.GetInt64("patient_id")
  5002. mode_id, _ := c.GetInt64("mode_id")
  5003. adminUserInfo := c.GetAdminUserInfo()
  5004. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5005. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5006. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  5007. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  5008. if err != nil {
  5009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5010. return
  5011. }
  5012. c.ServeSuccessJSON(map[string]interface{}{
  5013. "solution": solution,
  5014. "prescription": prescription,
  5015. "system_prescription": system_prescription,
  5016. "dialysisPrescription": dialysisPrescription,
  5017. })
  5018. }
  5019. func (c *DialysisApiController) GetSchedule() {
  5020. schedual_type, _ := c.GetInt64("schedual_type")
  5021. adminUserInfo := c.GetAdminUserInfo()
  5022. //timeLayout := "2006-01-02 15:04:05"
  5023. //
  5024. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  5025. //loc, _ := time.LoadLocation("Local")
  5026. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5027. //scheduleTime := theStartTime.Unix()
  5028. scheduleTime, _ := c.GetInt64("record_date")
  5029. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  5030. c.ServeSuccessJSON(map[string]interface{}{
  5031. "number": deviceNumber,
  5032. })
  5033. }
  5034. func (this *DialysisApiController) GetTodayMonitor() {
  5035. thisTime := time.Now()
  5036. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5037. timeLayout := "2006-01-02 15:04:05"
  5038. loc, _ := time.LoadLocation("Local")
  5039. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5040. theAssessmentDateTime := theStartTime.Unix()
  5041. patientID, _ := this.GetInt64("patient_id")
  5042. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5043. adminInfo := this.GetAdminUserInfo()
  5044. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5045. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5046. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  5047. var ultrafiltration_rate float64
  5048. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5049. //针对福建医师汇 获取透前评估预增脱水量
  5050. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5051. fmt.Println("透前评估数据", evaluation)
  5052. if prescription.ID > 0 {
  5053. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5054. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5055. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  5056. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5057. record.UltrafiltrationRate = ultrafiltration_rate
  5058. }
  5059. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  5060. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5061. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5062. record.UltrafiltrationRate = ultrafiltration_rate
  5063. }
  5064. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  5065. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5066. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5067. record.UltrafiltrationRate = ultrafiltration_rate
  5068. }
  5069. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  5070. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5071. record.UltrafiltrationRate = ultrafiltration_rate
  5072. }
  5073. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  5074. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5075. record.UltrafiltrationRate = ultrafiltration_rate
  5076. }
  5077. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  5078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5079. record.UltrafiltrationRate = ultrafiltration_rate
  5080. }
  5081. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  5082. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5083. record.UltrafiltrationRate = ultrafiltration_rate
  5084. }
  5085. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  5086. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5087. record.UltrafiltrationRate = ultrafiltration_rate
  5088. }
  5089. // 只针对方济医院
  5090. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5091. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5092. ultrafiltration_rate = value
  5093. record.UltrafiltrationRate = ultrafiltration_rate
  5094. }
  5095. //长沙南雅
  5096. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  5097. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  5098. record.UltrafiltrationRate = ultrafiltration_rate
  5099. }
  5100. if adminInfo.CurrentOrgId == 10694 || adminInfo.CurrentOrgId == 10697 {
  5101. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5102. ultrafiltration_rate = ultrafiltration_rate
  5103. }
  5104. }
  5105. }
  5106. // record.UltrafiltrationRate = ultrafiltration_rate
  5107. record.UltrafiltrationVolume = 0
  5108. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5109. if ultrafiltration_rate > 0 {
  5110. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5111. record.UltrafiltrationVolume = value
  5112. }
  5113. }
  5114. 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 {
  5115. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  5116. if adminInfo.CurrentOrgId != 10735 {
  5117. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5118. record.UltrafiltrationVolume = ultrafiltration_volume
  5119. }
  5120. if adminInfo.CurrentOrgId == 10735 {
  5121. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5122. record.UltrafiltrationVolume = ultrafiltration_volume
  5123. }
  5124. }
  5125. }
  5126. //长沙南雅
  5127. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  5128. if ultrafiltration_rate > 0 {
  5129. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5130. record.UltrafiltrationVolume = ultrafiltration_volume
  5131. }
  5132. }
  5133. if template.TemplateId == 47 || template.TemplateId == 54 {
  5134. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5135. }
  5136. if adminInfo.CurrentOrgId == 10697 || adminInfo.CurrentOrgId == 10694 {
  5137. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate * 1000)
  5138. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5139. }
  5140. this.ServeSuccessJSON(map[string]interface{}{
  5141. "monitor": record,
  5142. })
  5143. }
  5144. func (c *DialysisApiController) UploadDryWeight() {
  5145. patient_id, _ := c.GetInt64("id")
  5146. dry_weight, _ := c.GetFloat("dry_weight")
  5147. doctor_id, _ := c.GetInt64("doctor_id")
  5148. remark := c.GetString("remark")
  5149. adminUserInfo := c.GetAdminUserInfo()
  5150. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  5151. fmt.Println(err)
  5152. if err == gorm.ErrRecordNotFound {
  5153. dryWeight := &models.SgjPatientDryweight{
  5154. PatientId: patient_id,
  5155. DryWeight: dry_weight,
  5156. Remakes: remark,
  5157. Ctime: time.Now().Unix(),
  5158. Mtime: time.Now().Unix(),
  5159. Creator: doctor_id,
  5160. Status: 1,
  5161. UserOrgId: adminUserInfo.CurrentOrgId,
  5162. AdjustedValue: "/",
  5163. UserId: adminUserInfo.AdminUser.Id,
  5164. }
  5165. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5166. loc, _ := time.LoadLocation("Local")
  5167. nowTime := time.Now()
  5168. nowDay := nowTime.Format("2006-01-02")
  5169. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5170. redis := service.RedisClient()
  5171. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5172. redis.Set(keyOne, "", time.Second)
  5173. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5174. redis.Set(key, "", time.Second)
  5175. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5176. redis.Set(keyTwo, "", time.Second)
  5177. redis.Close()
  5178. if createErr == nil {
  5179. c.ServeSuccessJSON(map[string]interface{}{
  5180. "msg": "提交成功",
  5181. "weight": dryWeight,
  5182. })
  5183. }
  5184. } else {
  5185. dryWeight := &models.SgjPatientDryweight{
  5186. PatientId: patient_id,
  5187. DryWeight: dry_weight,
  5188. Remakes: remark,
  5189. Ctime: time.Now().Unix(),
  5190. Mtime: time.Now().Unix(),
  5191. Creator: doctor_id,
  5192. Status: 1,
  5193. UserOrgId: adminUserInfo.CurrentOrgId,
  5194. AdjustedValue: "/",
  5195. UserId: adminUserInfo.AdminUser.Id,
  5196. }
  5197. var value float64
  5198. value = dry_weight - weightAdjust.DryWeight
  5199. fmt.Println(value)
  5200. if value < 0 {
  5201. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5202. } else if value == 0 {
  5203. dryWeight.AdjustedValue = "/"
  5204. } else if value > 0 {
  5205. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5206. }
  5207. fmt.Println(value)
  5208. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5209. //康桥
  5210. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10721 {
  5211. timeNowStr := time.Now().Format("2006-01-02")
  5212. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5213. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5214. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5215. if beforAssesment.ID > 0 {
  5216. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5217. var dewater_amount float64
  5218. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5219. if adminUserInfo.CurrentOrgId != 10702 {
  5220. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5221. }
  5222. if adminUserInfo.CurrentOrgId == 10702 {
  5223. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  5224. }
  5225. //获取key,清空redis
  5226. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5227. redis := service.RedisClient()
  5228. //清空key 值
  5229. redis.Set(key, "", time.Second)
  5230. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  5231. //清空key 值
  5232. redis.Set(keyOne, "", time.Second)
  5233. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5234. //清空key 值
  5235. redis.Set(keyTwo, "", time.Second)
  5236. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5237. redis.Set(keySix, "", time.Second)
  5238. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5239. redis.Set(keySeven, "", time.Second)
  5240. }
  5241. }
  5242. loc, _ := time.LoadLocation("Local")
  5243. nowTime := time.Now()
  5244. nowDay := nowTime.Format("2006-01-02")
  5245. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5246. redis := service.RedisClient()
  5247. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5248. redis.Set(keyOne, "", time.Second)
  5249. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5250. redis.Set(key, "", time.Second)
  5251. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5252. redis.Set(keyTwo, "", time.Second)
  5253. redis.Close()
  5254. if createErr == nil {
  5255. c.ServeSuccessJSON(map[string]interface{}{
  5256. "msg": "提交成功",
  5257. "weight": dryWeight,
  5258. })
  5259. }
  5260. }
  5261. }
  5262. func (this *DialysisApiController) GetFuncPurview() {
  5263. adminUserInfo := this.GetAdminUserInfo()
  5264. user_id := adminUserInfo.AdminUser.Id
  5265. app_id := adminUserInfo.CurrentAppId
  5266. org_id := adminUserInfo.CurrentOrgId
  5267. create_url := this.GetString("create_url")
  5268. modify_url := this.GetString("modify_url")
  5269. modify_other_url := this.GetString("modify_other_url")
  5270. del_url := this.GetString("del_url")
  5271. del_other_url := this.GetString("del_other_url")
  5272. exce_url := this.GetString("exce_url")
  5273. check_url := this.GetString("check_url")
  5274. modify_exce_url := this.GetString("modify_exce_url")
  5275. module, _ := this.GetInt64("module", 0)
  5276. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  5277. var is_has_create bool
  5278. var is_has_modify bool
  5279. var is_has_modify_other bool
  5280. var is_has_del bool
  5281. var is_has_del_other bool
  5282. var is_has_exce bool
  5283. var is_has_check bool
  5284. var is_has_modify_exce bool
  5285. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  5286. if adminUserInfo.AdminUser.Id != org.Creator {
  5287. if app_role != nil {
  5288. if len(app_role.RoleIds) > 0 {
  5289. roles := strings.Split(app_role.RoleIds, ",")
  5290. var userRolePurviews string
  5291. for _, item := range roles {
  5292. role_id, _ := strconv.ParseInt(item, 10, 64)
  5293. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  5294. if len(userRolePurviews) == 0 {
  5295. userRolePurviews = purviews
  5296. } else {
  5297. userRolePurviews = userRolePurviews + "," + purviews
  5298. }
  5299. }
  5300. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  5301. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  5302. for _, item := range funcPurviews {
  5303. //for _, url := range strings.Split(item.Urlfor,","){
  5304. if strings.Split(item.Urlfor, ",")[1] == create_url {
  5305. is_has_create = true
  5306. }
  5307. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  5308. is_has_modify = true
  5309. }
  5310. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  5311. is_has_modify_other = true
  5312. }
  5313. if strings.Split(item.Urlfor, ",")[1] == del_url {
  5314. is_has_del = true
  5315. }
  5316. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  5317. is_has_del_other = true
  5318. }
  5319. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  5320. is_has_exce = true
  5321. }
  5322. if strings.Split(item.Urlfor, ",")[1] == check_url {
  5323. is_has_check = true
  5324. }
  5325. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  5326. is_has_modify_exce = true
  5327. }
  5328. }
  5329. } else {
  5330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  5331. return
  5332. }
  5333. this.ServeSuccessJSON(map[string]interface{}{
  5334. "is_has_create": is_has_create,
  5335. "is_has_modify": is_has_modify,
  5336. "is_has_modify_other": is_has_modify_other,
  5337. "is_has_del": is_has_del,
  5338. "is_has_del_other": is_has_del_other,
  5339. "is_has_exce": is_has_exce,
  5340. "is_has_check": is_has_check,
  5341. "is_has_modify_exce": is_has_modify_exce,
  5342. "module": module,
  5343. })
  5344. } else {
  5345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  5346. return
  5347. }
  5348. } else {
  5349. this.ServeSuccessJSON(map[string]interface{}{
  5350. "is_has_create": true,
  5351. "is_has_modify": true,
  5352. "is_has_modify_other": true,
  5353. "is_has_del": true,
  5354. "is_has_del_other": true,
  5355. "is_has_exce": true,
  5356. "is_has_check": true,
  5357. "is_has_modify_exce": true,
  5358. "module": true,
  5359. })
  5360. }
  5361. }
  5362. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  5363. patient_id, _ := this.GetInt64("patient_id", 0)
  5364. advice_date, _ := this.GetInt64("advice_date")
  5365. adminUserInfo := this.GetAdminUserInfo()
  5366. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5367. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5368. this.ServeSuccessJSON(map[string]interface{}{
  5369. "doctorAdvice": doctorAdvice,
  5370. "hisDoctorAdvice": hisDoctorAdvice,
  5371. })
  5372. }
  5373. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  5374. change_type, _ := this.GetInt64("type", 0)
  5375. record_date := this.GetString("record_time")
  5376. patient_id, _ := this.GetInt64("patient_id", 0)
  5377. timeLayout := "2006-01-02"
  5378. loc, _ := time.LoadLocation("Local")
  5379. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5380. record_time := theAdviceRecordTime.Unix()
  5381. adminUserInfo := this.GetAdminUserInfo()
  5382. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  5383. if err == nil {
  5384. if len(advices) == 0 {
  5385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5386. return
  5387. } else {
  5388. this.ServeSuccessJSON(map[string]interface{}{
  5389. "advices": advices,
  5390. "schedule": sch,
  5391. })
  5392. return
  5393. }
  5394. } else {
  5395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5396. return
  5397. }
  5398. }
  5399. func (c *DialysisApiController) GetDialysisGoods() {
  5400. schedualDate := c.GetString("schedule_date")
  5401. schedule_type, _ := c.GetInt64("schedule_type")
  5402. partition_id, _ := c.GetInt64("partition_id")
  5403. page, _ := c.GetInt("page")
  5404. limit, _ := c.GetInt("limit")
  5405. keywords := c.GetString("keywords")
  5406. patient_id, _ := c.GetInt64("patient_id")
  5407. good_type, _ := c.GetInt64("good_type")
  5408. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5409. if parseDateErr != nil && len(schedualDate) != 0 {
  5410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5411. return
  5412. }
  5413. schedualEndDate := int64(0)
  5414. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5415. if parseDateErr != nil && len(schedualDate) != 0 {
  5416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. schedualEndDate = endDate.Unix()
  5420. adminUser := c.GetAdminUserInfo()
  5421. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  5422. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  5423. if err == gorm.ErrRecordNotFound {
  5424. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5425. var ids []int64
  5426. for _, item := range list {
  5427. ids = append(ids, item.PatientId)
  5428. }
  5429. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5430. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5431. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5432. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5433. item.LastAutomaticReduceDetail = goodUser
  5434. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5435. }
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "dialysis_goods": dialysisGoods,
  5438. "good_type": goodTypes,
  5439. "total": total,
  5440. })
  5441. return
  5442. } else if err == nil {
  5443. //获取当天排班的每个患者的库存使用情况
  5444. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5445. var ids []int64
  5446. for _, item := range list {
  5447. ids = append(ids, item.PatientId)
  5448. }
  5449. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5450. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5451. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5452. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5453. fmt.Println(goodUser)
  5454. fmt.Println(lastGoodUserDetial)
  5455. item.LastAutomaticReduceDetail = goodUser
  5456. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5457. }
  5458. if err == nil {
  5459. c.ServeSuccessJSON(map[string]interface{}{
  5460. "dialysis_goods": dialysisGoods,
  5461. "good_type": goodTypes,
  5462. "total": total,
  5463. })
  5464. return
  5465. } else {
  5466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5467. return
  5468. }
  5469. } else if err != nil {
  5470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5471. return
  5472. }
  5473. }
  5474. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  5475. start_time := c.GetString("start_time")
  5476. end_time := c.GetString("end_time")
  5477. timeLayout := "2006-01-02"
  5478. loc, _ := time.LoadLocation("Local")
  5479. var theStartTime int64
  5480. if len(start_time) > 0 {
  5481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5482. if err != nil {
  5483. utils.ErrorLog(err.Error())
  5484. }
  5485. theStartTime = theTime.Unix()
  5486. }
  5487. var theEndtTime int64
  5488. if len(end_time) > 0 {
  5489. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5490. if err != nil {
  5491. utils.ErrorLog(err.Error())
  5492. }
  5493. theEndtTime = theTime.Unix()
  5494. }
  5495. adminUser := c.GetAdminUserInfo()
  5496. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  5497. if err == nil {
  5498. c.ServeSuccessJSON(map[string]interface{}{
  5499. "stock_out": outInfo,
  5500. })
  5501. return
  5502. } else {
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5504. return
  5505. }
  5506. }
  5507. func (c *DialysisApiController) GetRoleList() {
  5508. orgId := c.GetAdminUserInfo().CurrentOrgId
  5509. admin_user_id, _ := c.GetInt64("admin_user_id")
  5510. list, err := service.GetRoleList(orgId, admin_user_id)
  5511. if err == nil {
  5512. c.ServeSuccessJSON(map[string]interface{}{
  5513. "adminRole": list,
  5514. })
  5515. return
  5516. } else {
  5517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5518. return
  5519. }
  5520. }
  5521. func (c *DialysisApiController) GetInitPrintData() {
  5522. patient_id, _ := c.GetInt64("patient_id")
  5523. record_date, _ := c.GetInt64("record_date")
  5524. orgId := c.GetAdminUserInfo().CurrentOrgId
  5525. schedule, _ := service.GetPatientBySchedule(patient_id, record_date, orgId)
  5526. list, err := service.GetInitPrintData(patient_id, record_date, orgId, schedule.ModeId)
  5527. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5528. if err == nil {
  5529. c.ServeSuccessJSON(map[string]interface{}{
  5530. "list": list,
  5531. "assessmentAfterDislysis": assessmentAfterDislysis,
  5532. })
  5533. return
  5534. } else {
  5535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5536. return
  5537. }
  5538. }
  5539. func (c *DialysisApiController) GetInitPrintDataOne() {
  5540. patient_id, _ := c.GetInt64("patient_id")
  5541. start_time := c.GetString("record_date")
  5542. timeLayout := "2006-01-02"
  5543. loc, _ := time.LoadLocation("Local")
  5544. var theStartTime int64
  5545. if len(start_time) > 0 {
  5546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5547. if err != nil {
  5548. utils.ErrorLog(err.Error())
  5549. }
  5550. theStartTime = theTime.Unix()
  5551. }
  5552. orgId := c.GetAdminUserInfo().CurrentOrgId
  5553. schedule, _ := service.GetPatientBySchedule(patient_id, theStartTime, orgId)
  5554. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId, schedule.ModeId)
  5555. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5556. if err == nil {
  5557. c.ServeSuccessJSON(map[string]interface{}{
  5558. "list": list,
  5559. "assessmentAfterDislysis": assessmentAfterDislysis,
  5560. })
  5561. return
  5562. } else {
  5563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5564. return
  5565. }
  5566. }
  5567. // 新接口
  5568. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5569. keyword := this.GetString("keywords")
  5570. limit, _ := this.GetInt64("limit")
  5571. page, _ := this.GetInt64("page")
  5572. partition_id, _ := this.GetInt64("partition_id")
  5573. schedule_type, _ := this.GetInt64("schedule_type")
  5574. start_time := this.GetString("schedule_date")
  5575. advice_ids := this.GetString("ids")
  5576. var ids []string
  5577. if advice_ids != "" {
  5578. ids = strings.Split(advice_ids, ",")
  5579. }
  5580. timeLayout := "2006-01-02"
  5581. loc, _ := time.LoadLocation("Local")
  5582. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5583. orgId := this.GetAdminUserInfo().CurrentOrgId
  5584. _, config := service.FindXTHisRecordByOrgId(orgId)
  5585. goodType, _ := service.GetAllGoodType(orgId)
  5586. if config.IsOpen != 1 {
  5587. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5588. if err == nil {
  5589. this.ServeSuccessJSON(map[string]interface{}{
  5590. "list": list,
  5591. "total": total,
  5592. "config": config,
  5593. "goodType": goodType,
  5594. })
  5595. return
  5596. } else {
  5597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5598. return
  5599. }
  5600. }
  5601. if config.IsOpen == 1 {
  5602. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5603. if err == nil {
  5604. this.ServeSuccessJSON(map[string]interface{}{
  5605. "list": list,
  5606. "total": total,
  5607. "config": config,
  5608. "goodType": goodType,
  5609. })
  5610. return
  5611. }
  5612. }
  5613. }
  5614. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5615. keyword := this.GetString("keywords")
  5616. limit, _ := this.GetInt64("limit")
  5617. page, _ := this.GetInt64("page")
  5618. partition_id, _ := this.GetInt64("partition_id")
  5619. schedule_type, _ := this.GetInt64("schedule_type")
  5620. start_time := this.GetString("schedule_date")
  5621. ids := this.GetString("ids")
  5622. var idArray []string
  5623. if ids != "" {
  5624. idArray = strings.Split(ids, ",")
  5625. }
  5626. timeLayout := "2006-01-02"
  5627. loc, _ := time.LoadLocation("Local")
  5628. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5629. orgId := this.GetAdminUserInfo().CurrentOrgId
  5630. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5631. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5632. //获取长期医嘱
  5633. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5634. _, config := service.FindXTHisRecordByOrgId(orgId)
  5635. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5636. if err == nil {
  5637. this.ServeSuccessJSON(map[string]interface{}{
  5638. "list": list,
  5639. "total": total,
  5640. "adviceList": adviceList,
  5641. "config": config,
  5642. "drugList": drugList,
  5643. "tablelist": tablelist,
  5644. })
  5645. return
  5646. } else {
  5647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5648. return
  5649. }
  5650. }
  5651. func (this *DialysisApiController) SaveDialysisSetting() {
  5652. orgId := this.GetAdminUserInfo().CurrentOrgId
  5653. device_number_set, _ := this.GetInt64("device_number_set")
  5654. device_type_set, _ := this.GetInt64("device_type_set")
  5655. name_set, _ := this.GetInt64("name_set")
  5656. admission_number_set, _ := this.GetInt64("admission_number_set")
  5657. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5658. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5659. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5660. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5661. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5662. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5663. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5664. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5665. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5666. mode_id_set, _ := this.GetInt64("mode_id_set")
  5667. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5668. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5669. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5670. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5671. kalium_set, _ := this.GetInt64("kalium_set")
  5672. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5673. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5674. glucose_set, _ := this.GetInt64("glucose_set")
  5675. sodium_set, _ := this.GetInt64("sodium_set")
  5676. calcium_set, _ := this.GetInt64("calcium_set")
  5677. blood_access_set, _ := this.GetInt64("blood_access_set")
  5678. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5679. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5680. cuhong_set, _ := this.GetInt64("cuhong_set")
  5681. zuoka_set, _ := this.GetInt64("zuoka_set")
  5682. difenzi_set, _ := this.GetInt64("difenzi_set")
  5683. gansuna_set, _ := this.GetInt64("gansuna_set")
  5684. zhetangtie_set, _ := this.GetInt64("zhetangtie_set")
  5685. niaojimei_set, _ := this.GetInt64("niaojimei_set")
  5686. dialysis_strainer_set, _ := this.GetInt64("dialysis_strainer_set")
  5687. dialysisSetting := models.XtDialysisSetting{
  5688. Sodium: sodium_set,
  5689. Calcium: calcium_set,
  5690. BloodAccess: blood_access_set,
  5691. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5692. DisplaceLiquiPart: displace_liqui_part_set,
  5693. UserOrgId: orgId,
  5694. Status: 1,
  5695. DeviceNumber: device_number_set,
  5696. DeviceType: device_type_set,
  5697. Name: name_set,
  5698. AdmissionNumber: admission_number_set,
  5699. DialysisNo: dialysis_no_set,
  5700. WeightBefor: weight_befor_set,
  5701. DryWeight: dry_weight_set,
  5702. BloodPressure: blood_pressure_set,
  5703. UltrafiltrationVolume: ultrafiltration_volume_set,
  5704. InternalFistula: internal_fistula_set,
  5705. BloodFlowVolume: blood_flow_volume_set,
  5706. Anticoagulant: anticoagulant_set,
  5707. SealingFluidDispose: sealing_fluid_dispose_set,
  5708. ModeId: mode_id_set,
  5709. DialysisTime: dialysis_time_set,
  5710. DialysisDialyszers: dialysis_dialyszers_set,
  5711. DialysisIrrigation: dialysis_irrigation_set,
  5712. Gaijiliang: gaijiliang_set,
  5713. Kalium: kalium_set,
  5714. DisplaceLiquiValue: displace_liqui_value_set,
  5715. Bicarbonate: bicarbonate_set,
  5716. Glucose: glucose_set,
  5717. Ctime: time.Now().Unix(),
  5718. Mtime: time.Now().Unix(),
  5719. CuhongSet: cuhong_set,
  5720. ZuokaSet: zuoka_set,
  5721. DifenziSet: difenzi_set,
  5722. GansunaSet: gansuna_set,
  5723. ZhetangtieSet: zhetangtie_set,
  5724. NiaojimeiSet: niaojimei_set,
  5725. DialysisStrainerSet: dialysis_strainer_set,
  5726. }
  5727. err := service.SaveDialysisSetting(dialysisSetting)
  5728. if err == nil {
  5729. this.ServeSuccessJSON(map[string]interface{}{
  5730. "dialysisSetting": dialysisSetting,
  5731. })
  5732. return
  5733. } else {
  5734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5735. return
  5736. }
  5737. }
  5738. func (this *DialysisApiController) GetDialysisSetting() {
  5739. orgId := this.GetAdminUserInfo().CurrentOrgId
  5740. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5741. this.ServeSuccessJSON(map[string]interface{}{
  5742. "dialysisSett": dialysisSett,
  5743. })
  5744. return
  5745. }
  5746. func (this *DialysisApiController) GetDialysisParameterList() {
  5747. keyword := this.GetString("keywords")
  5748. limit, _ := this.GetInt64("limit")
  5749. page, _ := this.GetInt64("page")
  5750. //partition_id, _ := this.GetInt64("partition_id")
  5751. partion_type := this.GetString("partition_id")
  5752. idSplit := strings.Split(partion_type, ",")
  5753. schedule_type, _ := this.GetInt64("schedule_type")
  5754. start_time := this.GetString("schedule_date")
  5755. timeLayout := "2006-01-02"
  5756. loc, _ := time.LoadLocation("Local")
  5757. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5758. orgId := this.GetAdminUserInfo().CurrentOrgId
  5759. scheduids := this.GetString("ids")
  5760. var ids []string
  5761. if scheduids != "" {
  5762. ids = strings.Split(scheduids, ",")
  5763. }
  5764. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5765. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5766. if err == nil {
  5767. this.ServeSuccessJSON(map[string]interface{}{
  5768. "list": list,
  5769. "total": total,
  5770. "dialysisSett": dialysisSett,
  5771. })
  5772. return
  5773. } else {
  5774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5775. return
  5776. }
  5777. }
  5778. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5779. orgId := this.GetAdminUserInfo().CurrentOrgId
  5780. schedule_type, _ := this.GetInt64("schedule_type")
  5781. //partion_type, _ := this.GetInt64("partion_type")
  5782. start_time := this.GetString("selected_date")
  5783. partion_type := this.GetString("partion_type")
  5784. var ids []string
  5785. ids = strings.Split(partion_type, ",")
  5786. timeLayout := "2006-01-02"
  5787. loc, _ := time.LoadLocation("Local")
  5788. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5789. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5790. if err == nil {
  5791. this.ServeSuccessJSON(map[string]interface{}{
  5792. "list": list,
  5793. })
  5794. return
  5795. } else {
  5796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5797. return
  5798. }
  5799. }
  5800. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5801. orgId := this.GetAdminUserInfo().CurrentOrgId
  5802. schedule_type, _ := this.GetInt64("schedule_type")
  5803. //partion_type, _ := this.GetInt64("partion_type")
  5804. partion_type := this.GetString("partion_type")
  5805. var ids []string
  5806. ids = strings.Split(partion_type, ",")
  5807. start_time := this.GetString("selected_date")
  5808. timeLayout := "2006-01-02"
  5809. loc, _ := time.LoadLocation("Local")
  5810. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5811. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5812. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5813. //获取长期医嘱
  5814. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5815. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5816. _, config := service.FindXTHisRecordByOrgId(orgId)
  5817. if err == nil {
  5818. this.ServeSuccessJSON(map[string]interface{}{
  5819. "list": list,
  5820. "drug": drug,
  5821. "adviceList": adviceList,
  5822. "config": config,
  5823. "tablelist": tablelist,
  5824. })
  5825. return
  5826. } else {
  5827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5828. return
  5829. }
  5830. }
  5831. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5832. orgId := this.GetAdminUserInfo().CurrentOrgId
  5833. schedule_type, _ := this.GetInt64("schedule_type")
  5834. partion_type, _ := this.GetInt64("partion_type")
  5835. start_time := this.GetString("selected_date")
  5836. timeLayout := "2006-01-02"
  5837. loc, _ := time.LoadLocation("Local")
  5838. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5839. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5840. if err == nil {
  5841. this.ServeSuccessJSON(map[string]interface{}{
  5842. "list": list,
  5843. })
  5844. return
  5845. } else {
  5846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5847. return
  5848. }
  5849. }
  5850. func (this *DialysisApiController) SaveHisDialysis() {
  5851. var ids []string
  5852. advice_ids := this.GetString("ids")
  5853. ids = strings.Split(advice_ids, ",")
  5854. orgId := this.GetAdminUserInfo().CurrentOrgId
  5855. service.SaveHisDialysis(orgId, ids)
  5856. returnData := make(map[string]interface{}, 0)
  5857. returnData["msg"] = "ok"
  5858. this.ServeSuccessJSON(returnData)
  5859. return
  5860. }
  5861. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5862. orgId := this.GetAdminUserInfo().CurrentOrgId
  5863. schedule_type, _ := this.GetInt64("schedule_type")
  5864. //partion_type, _ := this.GetInt64("partion_type")
  5865. partion_type := this.GetString("partion_type")
  5866. var ids []string
  5867. ids = strings.Split(partion_type, ",")
  5868. start_time := this.GetString("selected_date")
  5869. timeLayout := "2006-01-02"
  5870. loc, _ := time.LoadLocation("Local")
  5871. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5872. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5873. this.ServeSuccessJSON(map[string]interface{}{
  5874. "list": list,
  5875. })
  5876. return
  5877. }
  5878. func (this *DialysisApiController) GetPatientSchedule() {
  5879. orgId := this.GetAdminUserInfo().CurrentOrgId
  5880. patient_id, _ := this.GetInt64("patient_id")
  5881. schedule_date, _ := this.GetInt64("schedule_date")
  5882. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5883. this.ServeSuccessJSON(map[string]interface{}{
  5884. "schedulePatient": schedulePatient,
  5885. })
  5886. }
  5887. func (c *DialysisApiController) GetSchedulePrintList() {
  5888. page, _ := c.GetInt64("page", 1)
  5889. limit, _ := c.GetInt64("limit", 10)
  5890. schedulType, _ := c.GetInt64("schedule_type", 0)
  5891. partitionType, _ := c.GetInt64("partition_type", 0)
  5892. keywords := c.GetString("keywords")
  5893. schedule_date := c.GetString("schedule_date")
  5894. timeLayout := "2006-01-02"
  5895. loc, _ := time.LoadLocation("Local")
  5896. var theStartTime int64
  5897. if len(schedule_date) > 0 {
  5898. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5899. if err != nil {
  5900. utils.ErrorLog(err.Error())
  5901. }
  5902. theStartTime = theTime.Unix()
  5903. }
  5904. adminUserInfo := c.GetAdminUserInfo()
  5905. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5906. for _, item := range list {
  5907. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5908. item.DialysisOrderTwenty = order
  5909. }
  5910. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5911. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5912. c.ServeSuccessJSON(map[string]interface{}{
  5913. "list": list,
  5914. "total": total,
  5915. "numberList": numberList,
  5916. "listOne": listOne,
  5917. })
  5918. }
  5919. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5920. orgId := this.GetAdminUserInfo().CurrentOrgId
  5921. list, _ := service.GetSolutionListByOrgId(orgId)
  5922. for _, item := range list {
  5923. //获取该模式最新的1条数据
  5924. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5925. //更新状态值
  5926. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5927. }
  5928. this.ServeSuccessJSON(map[string]interface{}{
  5929. "list": list,
  5930. })
  5931. }
  5932. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5933. orgId := this.GetAdminUserInfo().CurrentOrgId
  5934. is_open, _ := this.GetInt64("is_open")
  5935. idsStr := this.GetString("str")
  5936. recordIDStrs := strings.Split(idsStr, ",")
  5937. start_time := this.GetString("advice_date")
  5938. exec_time, _ := this.GetInt64("exec_time")
  5939. timeLayout := "2006-01-02"
  5940. loc, _ := time.LoadLocation("Local")
  5941. var startTime int64
  5942. if len(start_time) > 0 {
  5943. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5944. if err != nil {
  5945. //fmt.Println(err)
  5946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5947. return
  5948. }
  5949. startTime = theTime.Unix()
  5950. }
  5951. config, _ := service.GetDrugOpenConfigOne(orgId)
  5952. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5953. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5954. //his医嘱
  5955. if is_open == 1 {
  5956. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5957. //查找未执行医嘱
  5958. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5959. for _, item := range list {
  5960. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5961. this.ServeSuccessJSON(map[string]interface{}{
  5962. "msg": "3",
  5963. })
  5964. return
  5965. }
  5966. }
  5967. for _, item := range groupList {
  5968. for _, it := range list {
  5969. if item.DrugId == it.DrugId {
  5970. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5971. }
  5972. }
  5973. }
  5974. for _, item := range groupList {
  5975. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5976. var sum_out_count int64
  5977. for _, it := range item.ChildDoctorAdvice {
  5978. var prescribing_number int64
  5979. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5980. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5981. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5982. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5983. }
  5984. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5985. prescribing_number = parseIntPrescribingNumber
  5986. }
  5987. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5988. prescribing_number = parseIntPrescribingNumber
  5989. }
  5990. sum_out_count += prescribing_number
  5991. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5992. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5993. //库存不足
  5994. if sum_out_count > drugStockOut.FlushCount {
  5995. this.ServeSuccessJSON(map[string]interface{}{
  5996. "msg": "2",
  5997. "drug": medical,
  5998. })
  5999. return
  6000. }
  6001. }
  6002. }
  6003. creater := this.GetAdminUserInfo().AdminUser.Id
  6004. //执行出库逻辑
  6005. for _, item := range list {
  6006. hisadvice := &models.HisDoctorAdviceInfo{
  6007. ID: item.ID,
  6008. UserOrgId: item.UserOrgId,
  6009. PatientId: item.PatientId,
  6010. AdviceType: item.AdviceType,
  6011. AdviceDate: item.AdviceDate,
  6012. StartTime: item.StartTime,
  6013. AdviceName: item.AdviceName,
  6014. AdviceDesc: item.AdviceDesc,
  6015. ReminderDate: item.ReminderDate,
  6016. SingleDose: item.SingleDose,
  6017. SingleDoseUnit: item.SingleDoseUnit,
  6018. DrugSpec: item.DrugSpec,
  6019. DrugSpecUnit: item.DrugSpecUnit,
  6020. PrescribingNumber: item.PrescribingNumber,
  6021. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6022. DeliveryWay: item.DeliveryWay,
  6023. ExecutionFrequency: item.ExecutionFrequency,
  6024. AdviceDoctor: item.AdviceDoctor,
  6025. Status: 1,
  6026. CreatedTime: item.CreatedTime,
  6027. UpdatedTime: item.UpdatedTime,
  6028. AdviceAffirm: item.AdviceAffirm,
  6029. Remark: item.Remark,
  6030. StopTime: item.StopTime,
  6031. StopReason: item.StopReason,
  6032. StopDoctor: item.StopDoctor,
  6033. StopState: item.StopState,
  6034. ParentId: item.ParentId,
  6035. ExecutionTime: item.ExecutionTime,
  6036. ExecutionStaff: creater,
  6037. ExecutionState: item.ExecutionState,
  6038. Checker: item.Checker,
  6039. RecordDate: item.RecordDate,
  6040. DialysisOrderId: item.DialysisOrderId,
  6041. CheckTime: item.CheckTime,
  6042. CheckState: item.CheckState,
  6043. RemindType: item.RemindType,
  6044. FrequencyType: item.FrequencyType,
  6045. DayCount: item.DayCount,
  6046. WeekDay: item.WeekDay,
  6047. TemplateId: item.TemplateId,
  6048. Modifier: item.Modifier,
  6049. Way: item.Way,
  6050. DrugId: item.DrugId,
  6051. ExecutionFrequencyId: item.ExecutionFrequencyId,
  6052. }
  6053. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6054. if medical.IsUse == 2 {
  6055. if config.IsOpen != 1 {
  6056. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6057. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6058. }
  6059. //不通过药房发药
  6060. if pharmacyConfig.IsOpen != 1 {
  6061. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6062. }
  6063. //查询默认仓库
  6064. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6065. //查询默认仓库剩余多少库存
  6066. var sum_count int64
  6067. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6068. for _, its := range stockInfo {
  6069. if its.MaxUnit == medical.MaxUnit {
  6070. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6071. }
  6072. sum_count += its.StockMaxNumber + its.StockMinNumber
  6073. }
  6074. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6075. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6076. }
  6077. }
  6078. info := models.HisDoctorAdviceInfo{
  6079. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6080. ExecutionTime: exec_time,
  6081. ExecutionState: 1,
  6082. UpdatedTime: time.Now().Unix(),
  6083. }
  6084. //执行医嘱
  6085. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  6086. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6087. redis := service.RedisClient()
  6088. //清空key 值
  6089. redis.Set(key, "", time.Second)
  6090. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6091. redis.Set(keyTwo, "", time.Second)
  6092. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6093. redis.Set(keyThree, "", time.Second)
  6094. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6095. theTime := toTime.Format("2006-01-02")
  6096. fmt.Println("theTIME", theTime)
  6097. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6098. redis.Set(keyFour, "", time.Second)
  6099. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6100. redis.Set(keyFive, "", time.Second)
  6101. }
  6102. } else {
  6103. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  6104. //查找未执行医嘱
  6105. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  6106. for _, item := range groupList {
  6107. for _, it := range list {
  6108. if item.DrugId == it.DrugId {
  6109. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6110. }
  6111. }
  6112. }
  6113. for _, item := range groupList {
  6114. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6115. var sum_out_count int64
  6116. for _, it := range item.ChildDoctorAdvice {
  6117. var prescribing_number int64
  6118. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  6119. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6120. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6121. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6122. }
  6123. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6124. prescribing_number = parseIntPrescribingNumber
  6125. }
  6126. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6127. prescribing_number = parseIntPrescribingNumber
  6128. }
  6129. sum_out_count += prescribing_number
  6130. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6131. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6132. //库存不足
  6133. if sum_out_count > drugStockOut.FlushCount {
  6134. this.ServeSuccessJSON(map[string]interface{}{
  6135. "msg": "2",
  6136. "drug": medical,
  6137. })
  6138. return
  6139. }
  6140. }
  6141. }
  6142. for _, item := range list {
  6143. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6144. dadvice := &models.DoctorAdvice{
  6145. ID: item.ID,
  6146. UserOrgId: item.UserOrgId,
  6147. PatientId: item.PatientId,
  6148. AdviceType: item.AdviceType,
  6149. AdviceDate: item.AdviceDate,
  6150. StartTime: item.StartTime,
  6151. AdviceName: item.AdviceName,
  6152. AdviceDesc: item.AdviceDesc,
  6153. ReminderDate: item.ReminderDate,
  6154. SingleDose: item.SingleDose,
  6155. SingleDoseUnit: item.SingleDoseUnit,
  6156. DrugSpec: item.DrugSpec,
  6157. DrugSpecUnit: item.DrugSpecUnit,
  6158. PrescribingNumber: item.PrescribingNumber,
  6159. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6160. DeliveryWay: item.DeliveryWay,
  6161. ExecutionFrequency: item.ExecutionFrequency,
  6162. AdviceDoctor: item.AdviceDoctor,
  6163. Status: 1,
  6164. CreatedTime: item.CreatedTime,
  6165. UpdatedTime: item.UpdatedTime,
  6166. AdviceAffirm: item.AdviceAffirm,
  6167. Remark: item.Remark,
  6168. StopTime: item.StopTime,
  6169. StopReason: item.StopReason,
  6170. StopDoctor: item.StopDoctor,
  6171. StopState: item.StopState,
  6172. ParentId: item.ParentId,
  6173. ExecutionTime: item.ExecutionTime,
  6174. ExecutionStaff: item.ExecutionStaff,
  6175. ExecutionState: item.ExecutionState,
  6176. Checker: item.Checker,
  6177. RecordDate: item.ReminderDate,
  6178. DialysisOrderId: item.DialysisOrderId,
  6179. CheckTime: item.CheckTime,
  6180. CheckState: item.CheckState,
  6181. RemindType: item.RemindType,
  6182. FrequencyType: item.FrequencyType,
  6183. DayCount: item.DayCount,
  6184. WeekDay: item.WeekDay,
  6185. TemplateId: item.TemplateId,
  6186. Modifier: item.Modifier,
  6187. Way: item.Way,
  6188. DrugId: item.DrugId,
  6189. }
  6190. if medical.IsUse == 2 {
  6191. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6192. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6193. }
  6194. if pharmacyConfig.IsOpen != 1 {
  6195. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6196. }
  6197. //更新字典里面的库存
  6198. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6199. var sum_count int64
  6200. for _, its := range stockInfo {
  6201. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6202. if its.MaxUnit == baseDrug.MaxUnit {
  6203. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6204. }
  6205. sum_count += its.StockMaxNumber + its.StockMinNumber
  6206. }
  6207. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6208. //剩余库存
  6209. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6210. }
  6211. info := models.DoctorAdvice{
  6212. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6213. ExecutionTime: exec_time,
  6214. ExecutionState: 1,
  6215. UpdatedTime: time.Now().Unix(),
  6216. }
  6217. //执行医嘱
  6218. service.UpdateDoctorAdviceExecution(info, item.ID)
  6219. }
  6220. }
  6221. this.ServeSuccessJSON(map[string]interface{}{
  6222. "msg": "1",
  6223. })
  6224. return
  6225. }
  6226. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  6227. orgId := this.GetAdminUserInfo().CurrentOrgId
  6228. idsStr := this.GetString("str")
  6229. recordIDStrs := strings.Split(idsStr, ",")
  6230. start_time := this.GetString("advice_date")
  6231. timeLayout := "2006-01-02"
  6232. loc, _ := time.LoadLocation("Local")
  6233. var startTime int64
  6234. if len(start_time) > 0 {
  6235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6236. if err != nil {
  6237. //fmt.Println(err)
  6238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6239. return
  6240. }
  6241. startTime = theTime.Unix()
  6242. }
  6243. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6244. if config.IsOpen == 1 {
  6245. creater := this.GetAdminUserInfo().AdminUser.Id
  6246. //查询未核对的医嘱
  6247. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6248. for _, item := range advicelist {
  6249. if item.ExecutionStaff == creater {
  6250. this.ServeSuccessJSON(map[string]interface{}{
  6251. "msg": "2",
  6252. "advice": item,
  6253. })
  6254. return
  6255. }
  6256. service.CheckHisDoctorAdvice(item.ID, creater)
  6257. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6258. redis := service.RedisClient()
  6259. //清空key 值
  6260. redis.Set(key, "", time.Second)
  6261. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6262. redis.Set(keyTwo, "", time.Second)
  6263. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6264. redis.Set(keyThree, "", time.Second)
  6265. theTime := time.Now()
  6266. recordDate := theTime.Format("2006-01-02")
  6267. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6268. redis.Set(keyFour, "", time.Second)
  6269. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6270. redis.Set(keyFive, "", time.Second)
  6271. }
  6272. } else {
  6273. //查询未核对的医嘱
  6274. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6275. creater := this.GetAdminUserInfo().AdminUser.Id
  6276. for _, item := range advicelist {
  6277. if item.ExecutionStaff == creater {
  6278. this.ServeSuccessJSON(map[string]interface{}{
  6279. "msg": "2",
  6280. "advice": item,
  6281. })
  6282. return
  6283. }
  6284. service.CheckDoctorAdvice(item.ID, creater)
  6285. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6286. redis := service.RedisClient()
  6287. //清空key 值
  6288. redis.Set(key, "", time.Second)
  6289. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6290. redis.Set(keyTwo, "", time.Second)
  6291. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6292. redis.Set(keyThree, "", time.Second)
  6293. theTime := time.Now()
  6294. recordDate := theTime.Format("2006-01-02")
  6295. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6296. redis.Set(keyFour, "", time.Second)
  6297. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6298. redis.Set(keyFive, "", time.Second)
  6299. }
  6300. }
  6301. this.ServeSuccessJSON(map[string]interface{}{
  6302. "msg": "1",
  6303. })
  6304. return
  6305. }
  6306. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  6307. orgId := this.GetAdminUserInfo().CurrentOrgId
  6308. is_open, _ := this.GetInt64("is_open")
  6309. idsStr := this.GetString("str")
  6310. recordIDStrs := strings.Split(idsStr, ",")
  6311. start_time := this.GetString("advice_date")
  6312. timeLayout := "2006-01-02"
  6313. loc, _ := time.LoadLocation("Local")
  6314. var startTime int64
  6315. if len(start_time) > 0 {
  6316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6317. if err != nil {
  6318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6319. return
  6320. }
  6321. startTime = theTime.Unix()
  6322. }
  6323. if is_open == 1 {
  6324. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6325. } else {
  6326. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6327. }
  6328. this.ServeSuccessJSON(map[string]interface{}{
  6329. "msg": "1",
  6330. })
  6331. return
  6332. }
  6333. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  6334. advice_id, _ := this.GetInt64("advice_id")
  6335. start_time := this.GetString("advice_date")
  6336. orgId := this.GetAdminUserInfo().CurrentOrgId
  6337. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6338. exec_time, _ := this.GetInt64("exec_time")
  6339. //his医嘱
  6340. if config.IsOpen == 1 {
  6341. //查询医嘱
  6342. advice, _ := service.GetHisDocById(advice_id, orgId)
  6343. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  6344. this.ServeSuccessJSON(map[string]interface{}{
  6345. "msg": "3",
  6346. })
  6347. return
  6348. }
  6349. medical, _ := service.GetBaseDrugMedical(orgId)
  6350. var prescribing_number int64
  6351. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6352. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6353. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6354. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6355. }
  6356. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6357. prescribing_number = parseIntPrescribingNumber
  6358. }
  6359. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6360. prescribing_number = parseIntPrescribingNumber
  6361. }
  6362. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6363. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6364. //库存不足
  6365. if prescribing_number > drugStockOut.FlushCount {
  6366. this.ServeSuccessJSON(map[string]interface{}{
  6367. "msg": "2",
  6368. "drug": medical,
  6369. })
  6370. return
  6371. }
  6372. info := models.HisDoctorAdviceInfo{
  6373. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6374. ExecutionTime: exec_time,
  6375. ExecutionState: 1,
  6376. UpdatedTime: time.Now().Unix(),
  6377. }
  6378. //执行医嘱
  6379. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  6380. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  6381. redis := service.RedisClient()
  6382. //清空key 值
  6383. redis.Set(key, "", time.Second)
  6384. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  6385. redis.Set(keyTwo, "", time.Second)
  6386. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6387. redis.Set(keyThree, "", time.Second)
  6388. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6389. theTime := toTime.Format("2006-01-02")
  6390. fmt.Println("theTIME", theTime)
  6391. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6392. redis.Set(keyFour, "", time.Second)
  6393. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6394. redis.Set(keyFive, "", time.Second)
  6395. //出库
  6396. if prescribing_number <= drugStockOut.FlushCount {
  6397. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6398. //执行出库逻辑
  6399. hisadvice := &models.HisDoctorAdviceInfo{
  6400. ID: advice.ID,
  6401. UserOrgId: advice.UserOrgId,
  6402. PatientId: advice.PatientId,
  6403. AdviceType: advice.AdviceType,
  6404. AdviceDate: advice.AdviceDate,
  6405. StartTime: advice.StartTime,
  6406. AdviceName: advice.AdviceName,
  6407. AdviceDesc: advice.AdviceDesc,
  6408. ReminderDate: advice.ReminderDate,
  6409. SingleDose: advice.SingleDose,
  6410. SingleDoseUnit: advice.SingleDoseUnit,
  6411. DrugSpec: advice.DrugSpec,
  6412. DrugSpecUnit: advice.DrugSpecUnit,
  6413. PrescribingNumber: advice.PrescribingNumber,
  6414. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6415. DeliveryWay: advice.DeliveryWay,
  6416. ExecutionFrequency: advice.ExecutionFrequency,
  6417. AdviceDoctor: advice.AdviceDoctor,
  6418. Status: 1,
  6419. CreatedTime: advice.CreatedTime,
  6420. UpdatedTime: advice.UpdatedTime,
  6421. AdviceAffirm: advice.AdviceAffirm,
  6422. Remark: advice.Remark,
  6423. StopTime: advice.StopTime,
  6424. StopReason: advice.StopReason,
  6425. StopDoctor: advice.StopDoctor,
  6426. StopState: advice.StopState,
  6427. ParentId: advice.ParentId,
  6428. ExecutionTime: advice.ExecutionTime,
  6429. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6430. ExecutionState: advice.ExecutionState,
  6431. Checker: advice.Checker,
  6432. RecordDate: advice.RecordDate,
  6433. DialysisOrderId: advice.DialysisOrderId,
  6434. CheckTime: advice.CheckTime,
  6435. CheckState: advice.CheckState,
  6436. RemindType: advice.RemindType,
  6437. FrequencyType: advice.FrequencyType,
  6438. DayCount: advice.DayCount,
  6439. WeekDay: advice.WeekDay,
  6440. TemplateId: advice.TemplateId,
  6441. Modifier: advice.Modifier,
  6442. Way: advice.Way,
  6443. DrugId: advice.DrugId,
  6444. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  6445. }
  6446. if medical.IsUse == 2 {
  6447. if config.IsOpen != 1 {
  6448. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6449. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6450. }
  6451. //不通过药房发药
  6452. if pharmacyConfig.IsOpen != 1 {
  6453. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6454. }
  6455. //查询默认仓库
  6456. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  6457. //查询默认仓库剩余多少库存
  6458. var sum_count int64
  6459. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6460. for _, its := range stockInfo {
  6461. if its.MaxUnit == medical.MaxUnit {
  6462. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6463. }
  6464. sum_count += its.StockMaxNumber + its.StockMinNumber
  6465. }
  6466. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6467. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6468. }
  6469. }
  6470. }
  6471. this.ServeSuccessJSON(map[string]interface{}{
  6472. "msg": "1",
  6473. })
  6474. return
  6475. }
  6476. if config.IsOpen == 2 || config.IsOpen == 0 {
  6477. advice, _ := service.GetBloodDocById(advice_id, orgId)
  6478. medical, _ := service.GetBaseDrugMedical(orgId)
  6479. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6480. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6481. var prescribing_number int64
  6482. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6483. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6484. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6485. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6486. }
  6487. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6488. prescribing_number = parseIntPrescribingNumber
  6489. }
  6490. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6491. prescribing_number = parseIntPrescribingNumber
  6492. }
  6493. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6494. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6495. //库存不足
  6496. if prescribing_number > drugStockOut.FlushCount {
  6497. this.ServeSuccessJSON(map[string]interface{}{
  6498. "msg": "2",
  6499. "drug": medical,
  6500. })
  6501. return
  6502. }
  6503. info := models.DoctorAdvice{
  6504. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6505. ExecutionTime: exec_time,
  6506. ExecutionState: 1,
  6507. UpdatedTime: time.Now().Unix(),
  6508. }
  6509. //执行医嘱
  6510. service.UpdateDoctorAdviceExecution(info, advice.ID)
  6511. dadvice := &models.DoctorAdvice{
  6512. ID: advice.ID,
  6513. UserOrgId: advice.UserOrgId,
  6514. PatientId: advice.PatientId,
  6515. AdviceType: advice.AdviceType,
  6516. AdviceDate: advice.AdviceDate,
  6517. StartTime: advice.StartTime,
  6518. AdviceName: advice.AdviceName,
  6519. AdviceDesc: advice.AdviceDesc,
  6520. ReminderDate: advice.ReminderDate,
  6521. SingleDose: advice.SingleDose,
  6522. SingleDoseUnit: advice.SingleDoseUnit,
  6523. DrugSpec: advice.DrugSpec,
  6524. DrugSpecUnit: advice.DrugSpecUnit,
  6525. PrescribingNumber: advice.PrescribingNumber,
  6526. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6527. DeliveryWay: advice.DeliveryWay,
  6528. ExecutionFrequency: advice.ExecutionFrequency,
  6529. AdviceDoctor: advice.AdviceDoctor,
  6530. Status: 1,
  6531. CreatedTime: advice.CreatedTime,
  6532. UpdatedTime: advice.UpdatedTime,
  6533. AdviceAffirm: advice.AdviceAffirm,
  6534. Remark: advice.Remark,
  6535. StopTime: advice.StopTime,
  6536. StopReason: advice.StopReason,
  6537. StopDoctor: advice.StopDoctor,
  6538. StopState: advice.StopState,
  6539. ParentId: advice.ParentId,
  6540. ExecutionTime: advice.ExecutionTime,
  6541. ExecutionStaff: advice.ExecutionStaff,
  6542. ExecutionState: advice.ExecutionState,
  6543. Checker: advice.Checker,
  6544. RecordDate: advice.ReminderDate,
  6545. DialysisOrderId: advice.DialysisOrderId,
  6546. CheckTime: advice.CheckTime,
  6547. CheckState: advice.CheckState,
  6548. RemindType: advice.RemindType,
  6549. FrequencyType: advice.FrequencyType,
  6550. DayCount: advice.DayCount,
  6551. WeekDay: advice.WeekDay,
  6552. TemplateId: advice.TemplateId,
  6553. Modifier: advice.Modifier,
  6554. Way: advice.Way,
  6555. DrugId: advice.DrugId,
  6556. }
  6557. if medical.IsUse == 2 {
  6558. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6559. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6560. }
  6561. if pharmacyConfig.IsOpen != 1 {
  6562. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6563. }
  6564. //更新字典里面的库存
  6565. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6566. var sum_count int64
  6567. for _, its := range stockInfo {
  6568. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6569. if its.MaxUnit == baseDrug.MaxUnit {
  6570. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6571. }
  6572. sum_count += its.StockMaxNumber + its.StockMinNumber
  6573. }
  6574. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6575. //剩余库存
  6576. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6577. }
  6578. }
  6579. this.ServeSuccessJSON(map[string]interface{}{
  6580. "msg": "1",
  6581. })
  6582. return
  6583. }
  6584. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6585. orgId := this.GetAdminUserInfo().CurrentOrgId
  6586. schedule_type, _ := this.GetInt64("schedule_type")
  6587. //partion_type, _ := this.GetInt64("partion_type")
  6588. partion_type := this.GetString("partion_type")
  6589. var ids []string
  6590. ids = strings.Split(partion_type, ",")
  6591. start_time := this.GetString("selected_date")
  6592. timeLayout := "2006-01-02"
  6593. loc, _ := time.LoadLocation("Local")
  6594. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6595. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6596. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6597. _, config := service.FindXTHisRecordByOrgId(orgId)
  6598. appId := this.GetAdminUserInfo().CurrentAppId
  6599. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6600. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6601. if err == nil {
  6602. this.ServeSuccessJSON(map[string]interface{}{
  6603. "list": list,
  6604. "drug": drug,
  6605. "config": config,
  6606. "doctorList": doctorList,
  6607. "manufacturerList": manufacturerList,
  6608. })
  6609. return
  6610. } else {
  6611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6612. return
  6613. }
  6614. }
  6615. func (this *DialysisApiController) GetDialysisProject() {
  6616. orgId := this.GetAdminUserInfo().CurrentOrgId
  6617. schedule_type, _ := this.GetInt64("schedule_type")
  6618. partion_type := this.GetString("partion_type")
  6619. var ids []string
  6620. ids = strings.Split(partion_type, ",")
  6621. start_time := this.GetString("selected_date")
  6622. timeLayout := "2006-01-02"
  6623. loc, _ := time.LoadLocation("Local")
  6624. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6625. list, err := service.GetDialysisProjectSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6626. if err == nil {
  6627. this.ServeSuccessJSON(map[string]interface{}{
  6628. "list": list,
  6629. })
  6630. return
  6631. } else {
  6632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6633. return
  6634. }
  6635. }
  6636. func (this *DialysisApiController) GetMobileScheduleList() {
  6637. orgId := this.GetAdminUserInfo().CurrentOrgId
  6638. schedule, _ := service.GetMobileScheduleList(orgId)
  6639. if len(schedule) > 0 {
  6640. for _, its := range schedule {
  6641. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6642. //its.DialysisPrescription = prescription
  6643. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6644. //its.MonitoringRecord = monitor
  6645. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6646. //its.XtAssessmentAfterDislysis = after
  6647. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6648. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6649. }
  6650. }
  6651. this.ServeSuccessJSON(map[string]interface{}{
  6652. "schedule": schedule,
  6653. })
  6654. return
  6655. }
  6656. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6657. week_day, _ := this.GetInt64("week_day")
  6658. orgId := this.GetAdminUserInfo().CurrentOrgId
  6659. informaitonSetting := models.XtDialysisInformaitonSetting{
  6660. WeekDay: week_day,
  6661. UserOrgId: orgId,
  6662. Status: 1,
  6663. Ctime: time.Now().Unix(),
  6664. Mtime: 0,
  6665. }
  6666. information, _ := service.GetInformationSettingByOrgId(orgId)
  6667. if information.ID == 0 {
  6668. service.CreateInformationSetting(informaitonSetting)
  6669. }
  6670. if information.ID > 0 {
  6671. service.UpdateInformationSettingById(orgId, week_day)
  6672. }
  6673. this.ServeSuccessJSON(map[string]interface{}{
  6674. "informaitonSetting": informaitonSetting,
  6675. })
  6676. return
  6677. }
  6678. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6679. orgId := this.GetAdminUserInfo().CurrentOrgId
  6680. limit, _ := this.GetInt64("limit")
  6681. page, _ := this.GetInt64("page")
  6682. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6683. //未审核
  6684. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6685. //全部
  6686. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6687. patients, _ := service.GetAllpatientThirty(orgId)
  6688. appId := this.GetAdminUserInfo().CurrentAppId
  6689. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6690. this.ServeSuccessJSON(map[string]interface{}{
  6691. "informaitonSetting": informationSetting,
  6692. "infor": infor,
  6693. "total": total,
  6694. "totalOne": totalOne,
  6695. "inforList": inforList,
  6696. "patients": patients,
  6697. "adminList": role,
  6698. })
  6699. return
  6700. }
  6701. func (this *DialysisApiController) CheckDialysisInformation() {
  6702. id, _ := this.GetInt64("id")
  6703. application_status, _ := this.GetInt64("application_status")
  6704. timeNow := time.Now().Unix()
  6705. checker := this.GetAdminUserInfo().AdminUser.Id
  6706. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6707. this.ServeSuccessJSON(map[string]interface{}{
  6708. "information": information,
  6709. })
  6710. return
  6711. }
  6712. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6713. page, _ := this.GetInt64("page", 1)
  6714. limit, _ := this.GetInt64("limit", 10)
  6715. schedulType, _ := this.GetInt64("schedul_type", 0)
  6716. startTime, _ := this.GetInt64("schedul_time", 0)
  6717. partitionType, _ := this.GetInt64("partition_type", 0)
  6718. keywords := this.GetString("keywords")
  6719. start_time, _ := this.GetInt64("start_time")
  6720. end_time, _ := this.GetInt64("end_time")
  6721. adminUserInfo := this.GetAdminUserInfo()
  6722. if len(keywords) > 0 {
  6723. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6724. if err == nil {
  6725. this.ServeSuccessJSON(map[string]interface{}{
  6726. "schedule": dialysisSchedule,
  6727. "total": total,
  6728. })
  6729. } else {
  6730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6731. }
  6732. } else {
  6733. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6734. if err == nil {
  6735. this.ServeSuccessJSON(map[string]interface{}{
  6736. "schedule": dialysisSchedule,
  6737. "total": total,
  6738. })
  6739. } else {
  6740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6741. }
  6742. }
  6743. }
  6744. func (this *DialysisApiController) SaveInformation() {
  6745. patient_id, _ := this.GetInt64("patient_id")
  6746. record_date, _ := this.GetInt64("record_date")
  6747. startTime := this.GetString("selected_date")
  6748. timeLayout := "2006-01-02 15:04"
  6749. loc, _ := time.LoadLocation("Local")
  6750. if len(startTime) == 0 {
  6751. utils.ErrorLog("len(start_time) == 0")
  6752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6753. return
  6754. }
  6755. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6756. if err != nil {
  6757. utils.ErrorLog(err.Error())
  6758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6759. return
  6760. }
  6761. StartTime := theTime.Unix()
  6762. fmt.Println("startime-------------", StartTime)
  6763. module, _ := this.GetInt64("module")
  6764. remark := this.GetString("remark")
  6765. orgId := this.GetAdminUserInfo().CurrentOrgId
  6766. creater := this.GetAdminUserInfo().AdminUser.Id
  6767. information := models.XtDialysisInformation{
  6768. Module: module,
  6769. PatientId: patient_id,
  6770. RecordDate: record_date,
  6771. ApplicationDate: StartTime,
  6772. Creater: creater,
  6773. ApplicationStatus: 2,
  6774. Checker: 0,
  6775. CheckTime: 0,
  6776. Remark: remark,
  6777. UserOrgId: orgId,
  6778. Ctime: time.Now().Unix(),
  6779. Status: 1,
  6780. Mtime: 0,
  6781. }
  6782. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6783. if infor.ID == 0 {
  6784. err := service.CreatedDialysisInformation(information)
  6785. if err == nil {
  6786. this.ServeSuccessJSON(map[string]interface{}{
  6787. "information": information,
  6788. })
  6789. return
  6790. }
  6791. }
  6792. if infor.ID > 0 {
  6793. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6794. if err == nil {
  6795. this.ServeSuccessJSON(map[string]interface{}{
  6796. "information": information,
  6797. })
  6798. return
  6799. }
  6800. }
  6801. }
  6802. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6803. orgId := this.GetAdminUserInfo().CurrentOrgId
  6804. schedule_type, _ := this.GetInt64("schedule_type")
  6805. partion_type := this.GetString("partion_type")
  6806. var ids []string
  6807. ids = strings.Split(partion_type, ",")
  6808. start_time := this.GetString("selected_date")
  6809. timeLayout := "2006-01-02"
  6810. loc, _ := time.LoadLocation("Local")
  6811. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6812. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6813. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6814. _, config := service.FindXTHisRecordByOrgId(orgId)
  6815. appId := this.GetAdminUserInfo().CurrentAppId
  6816. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6817. if err == nil {
  6818. this.ServeSuccessJSON(map[string]interface{}{
  6819. "list": list,
  6820. "drug": drug,
  6821. "config": config,
  6822. "doctorList": doctorList,
  6823. })
  6824. return
  6825. } else {
  6826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6827. return
  6828. }
  6829. }
  6830. func (this *DialysisApiController) GetPatientList() {
  6831. orgId := this.GetAdminUserInfo().CurrentOrgId
  6832. keyWord := this.GetString("keyword")
  6833. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  6834. if err == nil {
  6835. this.ServeSuccessJSON(map[string]interface{}{
  6836. "patientList": patientList,
  6837. })
  6838. return
  6839. } else {
  6840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6841. return
  6842. }
  6843. }
  6844. func (this *DialysisApiController) GetPrescriptionLogList() {
  6845. patient_id, _ := this.GetInt64("patient_id")
  6846. record_date := this.GetString("record_date")
  6847. page, _ := this.GetInt64("page")
  6848. limit, _ := this.GetInt64("limit")
  6849. orgId := this.GetAdminUserInfo().CurrentOrgId
  6850. timeLayout := "2006-01-02"
  6851. loc, _ := time.LoadLocation("Local")
  6852. var recordDateTime int64
  6853. if len(record_date) > 0 {
  6854. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6855. if err != nil {
  6856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6857. return
  6858. }
  6859. recordDateTime = theTime.Unix()
  6860. }
  6861. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  6862. patients, _ := service.GetAllPatientLog(orgId)
  6863. role, _ := service.GetAllDoctorLog(orgId)
  6864. if err == nil {
  6865. this.ServeSuccessJSON(map[string]interface{}{
  6866. "prescriptionlogList": prescriptionlogList,
  6867. "total": total,
  6868. "patients": patients,
  6869. "role": role,
  6870. })
  6871. return
  6872. } else {
  6873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6874. return
  6875. }
  6876. }
  6877. func (this *DialysisApiController) GetBeforLogList() {
  6878. patient_id, _ := this.GetInt64("patient_id")
  6879. record_date := this.GetString("record_date")
  6880. page, _ := this.GetInt64("page")
  6881. limit, _ := this.GetInt64("limit")
  6882. orgId := this.GetAdminUserInfo().CurrentOrgId
  6883. timeLayout := "2006-01-02"
  6884. loc, _ := time.LoadLocation("Local")
  6885. var recordDateTime int64
  6886. if len(record_date) > 0 {
  6887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6888. if err != nil {
  6889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6890. return
  6891. }
  6892. recordDateTime = theTime.Unix()
  6893. }
  6894. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  6895. patients, _ := service.GetAllPatientLog(orgId)
  6896. role, _ := service.GetAllDoctorLog(orgId)
  6897. if err == nil {
  6898. this.ServeSuccessJSON(map[string]interface{}{
  6899. "beforLogList": beforLogList,
  6900. "total": total,
  6901. "patients": patients,
  6902. "role": role,
  6903. })
  6904. return
  6905. } else {
  6906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6907. return
  6908. }
  6909. }
  6910. func (this *DialysisApiController) GetDocLogList() {
  6911. patient_id, _ := this.GetInt64("patient_id")
  6912. record_date := this.GetString("record_date")
  6913. page, _ := this.GetInt64("page")
  6914. limit, _ := this.GetInt64("limit")
  6915. orgId := this.GetAdminUserInfo().CurrentOrgId
  6916. timeLayout := "2006-01-02"
  6917. loc, _ := time.LoadLocation("Local")
  6918. var recordDateTime int64
  6919. if len(record_date) > 0 {
  6920. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6921. if err != nil {
  6922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6923. return
  6924. }
  6925. recordDateTime = theTime.Unix()
  6926. }
  6927. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  6928. patients, _ := service.GetAllPatientLog(orgId)
  6929. role, _ := service.GetAllDoctorLog(orgId)
  6930. if err == nil {
  6931. this.ServeSuccessJSON(map[string]interface{}{
  6932. "adviceLogList": adviceLogList,
  6933. "total": total,
  6934. "patients": patients,
  6935. "role": role,
  6936. })
  6937. return
  6938. } else {
  6939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6940. return
  6941. }
  6942. }
  6943. func (this *DialysisApiController) GetMonitorLogList() {
  6944. patient_id, _ := this.GetInt64("patient_id")
  6945. record_date := this.GetString("record_date")
  6946. page, _ := this.GetInt64("page")
  6947. limit, _ := this.GetInt64("limit")
  6948. orgId := this.GetAdminUserInfo().CurrentOrgId
  6949. timeLayout := "2006-01-02"
  6950. loc, _ := time.LoadLocation("Local")
  6951. var recordDateTime int64
  6952. if len(record_date) > 0 {
  6953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6954. if err != nil {
  6955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6956. return
  6957. }
  6958. recordDateTime = theTime.Unix()
  6959. }
  6960. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  6961. patients, _ := service.GetAllPatientLog(orgId)
  6962. role, _ := service.GetAllDoctorLog(orgId)
  6963. if err == nil {
  6964. this.ServeSuccessJSON(map[string]interface{}{
  6965. "monitorLogList": monitorLogList,
  6966. "total": total,
  6967. "patients": patients,
  6968. "role": role,
  6969. })
  6970. return
  6971. } else {
  6972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6973. return
  6974. }
  6975. }
  6976. func (this *DialysisApiController) GetAfterLogList() {
  6977. patient_id, _ := this.GetInt64("patient_id")
  6978. record_date := this.GetString("record_date")
  6979. page, _ := this.GetInt64("page")
  6980. limit, _ := this.GetInt64("limit")
  6981. orgId := this.GetAdminUserInfo().CurrentOrgId
  6982. timeLayout := "2006-01-02"
  6983. loc, _ := time.LoadLocation("Local")
  6984. var recordDateTime int64
  6985. if len(record_date) > 0 {
  6986. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6987. if err != nil {
  6988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6989. return
  6990. }
  6991. recordDateTime = theTime.Unix()
  6992. }
  6993. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  6994. patients, _ := service.GetAllPatientLog(orgId)
  6995. role, _ := service.GetAllDoctorLog(orgId)
  6996. if err == nil {
  6997. this.ServeSuccessJSON(map[string]interface{}{
  6998. "afterLogList": afterLogList,
  6999. "total": total,
  7000. "patients": patients,
  7001. "role": role,
  7002. })
  7003. return
  7004. } else {
  7005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7006. return
  7007. }
  7008. }
  7009. func (this *DialysisApiController) SaveGatherSetting() {
  7010. orgId := this.GetAdminUserInfo().CurrentOrgId
  7011. is_index_number, _ := this.GetInt64("is_index_number")
  7012. fmt.Println("this,23o2332232323232332", is_index_number)
  7013. is_zone, _ := this.GetInt64("is_zone")
  7014. is_number, _ := this.GetInt64("is_number")
  7015. is_birth, _ := this.GetInt64("is_birth")
  7016. is_age, _ := this.GetInt64("is_age")
  7017. is_name, _ := this.GetInt64("is_name")
  7018. is_mode_type, _ := this.GetInt64("is_mode_type")
  7019. is_prescription_status, _ := this.GetInt64("is_prescription_status")
  7020. is_admission_number, _ := this.GetInt64("is_admission_number")
  7021. is_dialysis_no, _ := this.GetInt64("is_dialysis_no")
  7022. is_dry_weight, _ := this.GetInt64("is_dry_weight")
  7023. is_dialysis_dialyszers, _ := this.GetInt64("is_dialysis_dialyszers")
  7024. is_dialysis_strainer, _ := this.GetInt64("is_dialysis_strainer")
  7025. is_dialysis_irrigation, _ := this.GetInt64("is_dialysis_irrigation")
  7026. is_calcium, _ := this.GetInt64("is_calcium")
  7027. is_kalium, _ := this.GetInt64("is_kalium")
  7028. is_change_nurse, _ := this.GetInt64("is_change_nurse")
  7029. is_puncture_needle, _ := this.GetInt64("is_puncture_needle")
  7030. is_anticoagulant, _ := this.GetInt64("is_anticoagulant")
  7031. is_tube, _ := this.GetInt64("is_tube")
  7032. is_cuhong, _ := this.GetInt64("is_cuhong")
  7033. is_zuoka, _ := this.GetInt64("is_zuoka")
  7034. is_zhetangtie, _ := this.GetInt64("is_zhetangtie")
  7035. is_paligu, _ := this.GetInt64("is_paligu")
  7036. is_guhuachun, _ := this.GetInt64("is_guhuachun")
  7037. is_niaojimei, _ := this.GetInt64("is_niaojimei")
  7038. is_putaosuangai, _ := this.GetInt64("is_putaosuangai")
  7039. is_jiaguan, _ := this.GetInt64("is_jiaguan")
  7040. is_xiongxiewutai, _ := this.GetInt64("is_xiongxiewutai")
  7041. gatherSetting := models.XtDialysisGatherSetting{
  7042. UserOrgId: orgId,
  7043. IndexNumber: is_index_number,
  7044. Zone: is_zone,
  7045. Number: is_number,
  7046. Birth: is_birth,
  7047. Name: is_name,
  7048. Age: is_age,
  7049. ModeType: is_mode_type,
  7050. PrescriptionStatus: is_prescription_status,
  7051. AdmissionNumber: is_admission_number,
  7052. DialysisNo: is_dialysis_no,
  7053. DryWeight: is_dry_weight,
  7054. DialysisDialyszers: is_dialysis_dialyszers,
  7055. DialysisStrainer: is_dialysis_strainer,
  7056. DialysisIrrigation: is_dialysis_irrigation,
  7057. Calcium: is_calcium,
  7058. Kalium: is_kalium,
  7059. ChangeNurse: is_change_nurse,
  7060. PunctureNeedle: is_puncture_needle,
  7061. Anticoagulant: is_anticoagulant,
  7062. Tube: is_tube,
  7063. Cuhong: is_cuhong,
  7064. Zuoka: is_zuoka,
  7065. Zhetangtie: is_zhetangtie,
  7066. Paligu: is_paligu,
  7067. Guhuachun: is_guhuachun,
  7068. Niaojimei: is_niaojimei,
  7069. Putaosuangai: is_putaosuangai,
  7070. Jiaguan: is_jiaguan,
  7071. Xiongxiewutai: is_xiongxiewutai,
  7072. Ctime: time.Now().Unix(),
  7073. Mtime: time.Now().Unix(),
  7074. Status: 1,
  7075. }
  7076. //查询该机构有没有设置
  7077. gatherSettingOne, _ := service.GetGatherSettingByOrgId(orgId)
  7078. if gatherSettingOne.ID == 0 {
  7079. service.CreateGather(gatherSetting)
  7080. } else {
  7081. gatherSetting.ID = gatherSettingOne.ID
  7082. service.SaveGather(gatherSetting)
  7083. }
  7084. this.ServeSuccessJSON(map[string]interface{}{
  7085. "gatherSetting": gatherSetting,
  7086. })
  7087. return
  7088. }
  7089. func (this *DialysisApiController) GetGatherSetting() {
  7090. orgId := this.GetAdminUserInfo().CurrentOrgId
  7091. gatherSetting, _ := service.GetGatherSetting(orgId)
  7092. this.ServeSuccessJSON(map[string]interface{}{
  7093. "gatherSetting": gatherSetting,
  7094. })
  7095. return
  7096. }
  7097. func (this *DialysisApiController) GetDialysisGatherList() {
  7098. keyword := this.GetString("keywords")
  7099. limit, _ := this.GetInt64("limit")
  7100. page, _ := this.GetInt64("page")
  7101. partion_type := this.GetString("partition_id")
  7102. idSplit := strings.Split(partion_type, ",")
  7103. schedule_type, _ := this.GetInt64("schedule_type")
  7104. start_time := this.GetString("schedule_date")
  7105. timeLayout := "2006-01-02"
  7106. loc, _ := time.LoadLocation("Local")
  7107. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7108. orgId := this.GetAdminUserInfo().CurrentOrgId
  7109. scheduids := this.GetString("ids")
  7110. var ids []string
  7111. if scheduids != "" {
  7112. ids = strings.Split(scheduids, ",")
  7113. }
  7114. list, total, _ := service.GetDialysisGatherList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  7115. gatherSetting, _ := service.GetGatherSetting(orgId)
  7116. this.ServeSuccessJSON(map[string]interface{}{
  7117. "list": list,
  7118. "total": total,
  7119. "gatherSetting": gatherSetting,
  7120. })
  7121. return
  7122. }
  7123. func (this *DialysisApiController) GetPatientDialysisRecordList() {
  7124. patient_id, _ := this.GetInt64("patient_id")
  7125. timeLayout := "2006-01-02"
  7126. loc, _ := time.LoadLocation("Local")
  7127. start_time := this.GetString("start_time")
  7128. end_time := this.GetString("end_time")
  7129. var startdateunix int64
  7130. if len(start_time) > 0 {
  7131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7132. if err != nil {
  7133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7134. return
  7135. }
  7136. startdateunix = theTime.Unix()
  7137. }
  7138. var enddateunix int64
  7139. if len(end_time) > 0 {
  7140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7141. if err != nil {
  7142. utils.ErrorLog(err.Error())
  7143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7144. return
  7145. }
  7146. enddateunix = theTime.Unix()
  7147. }
  7148. org_id := this.GetAdminUserInfo().CurrentOrgId
  7149. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7150. list, _ := service.GetPatientDialysisRecordList(patient_id, startdateunix, enddateunix)
  7151. this.ServeSuccessJSON(map[string]interface{}{
  7152. "list": list,
  7153. })
  7154. return
  7155. } else {
  7156. list, _ := service.GetPatientDialysisRecordListOne(patient_id, startdateunix, enddateunix)
  7157. this.ServeSuccessJSON(map[string]interface{}{
  7158. "list": list,
  7159. })
  7160. }
  7161. return
  7162. }
  7163. func (this *DialysisApiController) GetPatientRecordList() {
  7164. patient_id, _ := this.GetInt64("patient_id")
  7165. orgId := this.GetAdminUserInfo().CurrentOrgId
  7166. beforList, _ := service.GetPatientBeforRecordList(patient_id, orgId)
  7167. afterList, _ := service.GetPatientAfterRecordList(patient_id, orgId)
  7168. monitorList, _ := service.GetMonitorRecordByGroup(patient_id, orgId)
  7169. this.ServeSuccessJSON(map[string]interface{}{
  7170. "beforList": beforList,
  7171. "afterList": afterList,
  7172. "monitorList": monitorList,
  7173. })
  7174. }
  7175. func (this *DialysisApiController) GetDialysisTotalCount() {
  7176. timeLayout := "2006-01-02"
  7177. loc, _ := time.LoadLocation("Local")
  7178. start_time := this.GetString("start_time")
  7179. end_time := this.GetString("end_time")
  7180. patient_id, _ := this.GetInt64("patient_id")
  7181. var startdateunix int64
  7182. if len(start_time) > 0 {
  7183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7184. if err != nil {
  7185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7186. return
  7187. }
  7188. startdateunix = theTime.Unix()
  7189. }
  7190. var enddateunix int64
  7191. if len(end_time) > 0 {
  7192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7193. if err != nil {
  7194. utils.ErrorLog(err.Error())
  7195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7196. return
  7197. }
  7198. enddateunix = theTime.Unix()
  7199. }
  7200. orgId := this.GetAdminUserInfo().CurrentOrgId
  7201. order, _ := service.GetDialysisTotalCountByTime(orgId, startdateunix, enddateunix, patient_id)
  7202. this.ServeSuccessJSON(map[string]interface{}{
  7203. "order": order,
  7204. })
  7205. }
  7206. func (this *DialysisApiController) GetPatientBefor() {
  7207. timeLayout := "2006-01-02"
  7208. loc, _ := time.LoadLocation("Local")
  7209. record_date := this.GetString("record_date")
  7210. patient_id, _ := this.GetInt64("patient_id")
  7211. user_org_id := this.GetAdminUserInfo().CurrentOrgId
  7212. var startdateunix int64
  7213. if len(record_date) > 0 {
  7214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7215. if err != nil {
  7216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7217. return
  7218. }
  7219. startdateunix = theTime.Unix()
  7220. }
  7221. patientBefor, _ := service.GetPatientBefor(patient_id, startdateunix, user_org_id)
  7222. prescription, _ := service.GetDialysisPrescribeOneList(patient_id, startdateunix, user_org_id)
  7223. this.ServeSuccessJSON(map[string]interface{}{
  7224. "patientBefor": patientBefor,
  7225. "prescription": prescription,
  7226. })
  7227. }