dialysis_api_controller.go 307KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362
  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. fmt.Println(recordDateStr)
  2001. if patient <= 0 {
  2002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2003. return
  2004. }
  2005. adminUserInfo := c.GetAdminUserInfo()
  2006. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2007. if patientInfo.ID == 0 {
  2008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2009. return
  2010. }
  2011. if len(recordDateStr) == 0 {
  2012. recordDateStr = time.Now().Format("2006-01-02")
  2013. }
  2014. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2015. if parseDateErr != nil {
  2016. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2018. return
  2019. }
  2020. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", record_time)
  2021. fmt.Println("startDate0000000000000000000000000000", startDate.Unix())
  2022. // data := make(map[string]interface{}, 0)
  2023. var data models.AssessmentAfterDislysis
  2024. var err error
  2025. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2026. fmt.Println(err)
  2027. if err != nil {
  2028. c.ErrorLog("数据解析错误:%v", err)
  2029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2030. return
  2031. }
  2032. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2033. assessment.DialysisOrderId = data.DialysisOrderId
  2034. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2035. assessment.Status = 1
  2036. assessment.WeightAfter = data.WeightAfter
  2037. assessment.WeightLoss = data.WeightLoss
  2038. assessment.Temperature = data.Temperature
  2039. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2040. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2041. assessment.PulseFrequency = data.PulseFrequency
  2042. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2043. assessment.ActualDisplacement = data.ActualDisplacement
  2044. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2045. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2046. assessment.Cruor = data.Cruor
  2047. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2048. assessment.DialysisIntakes = data.DialysisIntakes
  2049. assessment.InternalFistula = data.InternalFistula
  2050. assessment.BloodAccessPartId = data.BloodAccessPartId
  2051. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2052. assessment.Catheter = data.Catheter
  2053. assessment.Complication = data.Complication
  2054. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2055. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2056. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2057. assessment.PatientGose = data.PatientGose
  2058. assessment.InpatientDepartment = data.InpatientDepartment
  2059. assessment.ObservationContent = data.ObservationContent
  2060. assessment.ObservationContentOther = data.ObservationContentOther
  2061. assessment.Remark = data.Remark
  2062. assessment.BreathingRate = data.BreathingRate
  2063. assessment.DialysisProcess = data.DialysisProcess
  2064. assessment.InAdvanceMinute = data.InAdvanceMinute
  2065. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2066. assessment.InAdvanceReason = data.InAdvanceReason
  2067. assessment.HemostasisOpera = data.HemostasisOpera
  2068. assessment.HemostasisMinute = data.HemostasisMinute
  2069. assessment.TremorNoise = data.TremorNoise
  2070. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2071. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2072. assessment.ArterialTube = data.ArterialTube
  2073. assessment.IntravenousTube = data.IntravenousTube
  2074. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2075. assessment.Dialyzer = data.Dialyzer
  2076. assessment.IsEat = data.IsEat
  2077. assessment.CvcA = data.CvcA
  2078. assessment.CvcV = data.CvcV
  2079. assessment.Channel = data.Channel
  2080. assessment.ReturnBlood = data.ReturnBlood
  2081. assessment.RehydrationVolume = data.RehydrationVolume
  2082. assessment.DialysisDuring = data.DialysisDuring
  2083. assessment.StrokeVolume = data.StrokeVolume
  2084. assessment.BloodFlow = data.BloodFlow
  2085. assessment.SealingFluidDispose = data.SealingFluidDispose
  2086. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  2087. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  2088. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  2089. assessment.SettingPressure = data.SettingPressure
  2090. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  2091. assessment.DiastolicPressure = data.DiastolicPressure
  2092. assessment.AdditionalWeight = data.AdditionalWeight
  2093. assessment.OtherComplication = data.OtherComplication
  2094. assessment.Ktv = data.Ktv
  2095. assessment.Urr = data.Urr
  2096. assessment.Hypertenison = data.Hypertenison
  2097. assessment.Hypopiesia = data.Hypopiesia
  2098. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  2099. assessment.Lapse = data.Lapse
  2100. assessment.Consciousness = data.Consciousness
  2101. assessment.Fallrisk = data.Fallrisk
  2102. assessment.MachineRun = data.MachineRun
  2103. assessment.AfterUrea = data.AfterUrea
  2104. assessment.PipCoagulation = data.PipCoagulation
  2105. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  2106. assessment.TransfusionVolume = data.TransfusionVolume
  2107. assessment.Condenser = data.Condenser
  2108. assessment.LastAfterWeight = data.LastAfterWeight
  2109. assessment.DisplaceLiquiValue = data.DisplaceLiquiValue
  2110. assessment.RecordTime = startDate.Unix()
  2111. assessment.SymptomAfterDialysisRemark = data.SymptomAfterDialysisRemark
  2112. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2113. if assessment.ID > 0 {
  2114. if appRole.UserType == 2 || appRole.UserType == 1 {
  2115. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2116. assessment.AssessmentTime = time.Now().Unix()
  2117. } else {
  2118. if assessment.Creater == 0 {
  2119. assessment.Modifier = adminUserInfo.AdminUser.Id
  2120. assessment.Creater = adminUserInfo.AdminUser.Id
  2121. } else {
  2122. assessment.Modifier = adminUserInfo.AdminUser.Id
  2123. }
  2124. }
  2125. assessment.UpdatedTime = time.Now().Unix()
  2126. // 查询信息规挡的设置天数
  2127. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2128. if infor.ID > 0 {
  2129. var cha_time int64
  2130. timeNowStr := time.Now().Format("2006-01-02")
  2131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2132. //今日的日期减去设置的日期
  2133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2134. if cha_time >= recordDate.Unix() {
  2135. //查询审核是否允许
  2136. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 9)
  2137. //申请状态不允许的情况 拒绝修改
  2138. if infor.ApplicationStatus != 1 {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2140. return
  2141. }
  2142. }
  2143. }
  2144. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2145. //记录日志
  2146. byterequest, _ := json.Marshal(assessment)
  2147. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2148. UserOrgId: assessment.UserOrgId,
  2149. PatientId: assessment.PatientId,
  2150. RecordDate: assessment.AssessmentDate,
  2151. Status: 1,
  2152. ErrLog: string(byterequest),
  2153. AdminUserId: adminUserInfo.AdminUser.Id,
  2154. Ctime: time.Now().Unix(),
  2155. Mtime: 0,
  2156. Source: "电脑端保存透后评估",
  2157. }
  2158. service.CreateAfterDialysisLog(afterDialysisLog)
  2159. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2160. redis := service.RedisClient()
  2161. //清空key 值
  2162. redis.Set(key, "", time.Second)
  2163. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2164. redis.Set(keyThree, "", time.Second)
  2165. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2166. redis.Set(keyTwo, "", time.Second)
  2167. defer redis.Close()
  2168. } else {
  2169. if appRole.UserType == 2 || appRole.UserType == 1 {
  2170. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2171. assessment.AssessmentTime = time.Now().Unix()
  2172. } else {
  2173. assessment.Creater = adminUserInfo.AdminUser.Id
  2174. }
  2175. assessment.CreatedTime = time.Now().Unix()
  2176. assessment.UpdatedTime = time.Now().Unix()
  2177. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2178. assessment.PatientId = patient
  2179. assessment.AssessmentDate = recordDate.Unix()
  2180. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2181. //记录日志
  2182. byterequest, _ := json.Marshal(assessment)
  2183. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2184. UserOrgId: assessment.UserOrgId,
  2185. PatientId: assessment.PatientId,
  2186. RecordDate: assessment.AssessmentDate,
  2187. Status: 1,
  2188. ErrLog: string(byterequest),
  2189. AdminUserId: adminUserInfo.AdminUser.Id,
  2190. Ctime: time.Now().Unix(),
  2191. Mtime: 0,
  2192. Source: "电脑端修改保存透后评估",
  2193. }
  2194. service.CreateAfterDialysisLog(afterDialysisLog)
  2195. finish := models.XtDialysisFinish{
  2196. IsFinish: 1,
  2197. UserOrgId: adminUserInfo.CurrentOrgId,
  2198. Status: 1,
  2199. Ctime: time.Now().Unix(),
  2200. Mtime: 0,
  2201. Module: 9,
  2202. RecordDate: recordDate.Unix(),
  2203. Sourse: 1,
  2204. PatientId: patient,
  2205. }
  2206. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  2207. if dialysisFinish.ID == 0 {
  2208. service.CreateDialysisFinish(finish)
  2209. }
  2210. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2211. redis := service.RedisClient()
  2212. //清空key 值
  2213. redis.Set(key, "", time.Second)
  2214. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2215. redis.Set(keyThree, "", time.Second)
  2216. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2217. redis.Set(keyTwo, "", time.Second)
  2218. defer redis.Close()
  2219. }
  2220. if err != nil {
  2221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2222. return
  2223. }
  2224. c.ServeSuccessJSON(map[string]interface{}{
  2225. "AssessmentAfterDislysis": &assessment,
  2226. })
  2227. }
  2228. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2229. patient, _ := c.GetInt64("patient", 0)
  2230. recordDateStr := c.GetString("record_date")
  2231. if patient <= 0 {
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. adminUserInfo := c.GetAdminUserInfo()
  2236. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2237. if patientInfo.ID == 0 {
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2239. return
  2240. }
  2241. if len(recordDateStr) == 0 {
  2242. recordDateStr = time.Now().Format("2006-01-02")
  2243. }
  2244. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2245. if parseDateErr != nil {
  2246. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2248. return
  2249. }
  2250. weight_before, _ := c.GetFloat("weight_before", 0)
  2251. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2252. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2253. temperature, _ := c.GetFloat("temperature", 0)
  2254. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2255. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2256. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2257. last_post_dialysis := c.GetString("last_post_dialysis")
  2258. dialysis_interphase := c.GetString("dialysis_interphase")
  2259. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2260. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2261. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2262. bloodAccessPartId := c.GetString("blood_access_part_id")
  2263. internalFistula := c.GetString("internal_fistula")
  2264. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2265. catheter := c.GetString("catheter")
  2266. catheter_bend, _ := c.GetInt("catheter_bend")
  2267. complication := c.GetString("complication")
  2268. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2269. hemorrhage := c.GetString("hemorrhage")
  2270. hemorrhage_other := c.GetString("hemorrhage_other")
  2271. remark := c.GetString("remark")
  2272. puncture_method := c.GetString("puncture_method")
  2273. dialysis_count := c.GetString("dialysis_count")
  2274. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2275. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2276. ductus_arantii := c.GetString("ductus_arantii")
  2277. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2278. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2279. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2280. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2281. puncture_way := c.GetString("puncture_way")
  2282. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2283. internal_fistula_other := c.GetString("internal_fistula_other")
  2284. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2285. breathing_rate := c.GetString("breathing_rate")
  2286. is_infect, _ := c.GetInt64("is_infect", 0)
  2287. exposed, _ := c.GetFloat("exposed", 0)
  2288. skin := c.GetString("skin")
  2289. skin_other := c.GetString("skin_other")
  2290. infect_other := c.GetString("infect_other")
  2291. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2292. machine_type := c.GetString("machine_type")
  2293. puncture_needle := c.GetString("puncture_needle")
  2294. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2295. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  2296. phinholing := c.GetString("pinholing")
  2297. catheter_suture := c.GetString("catheter_suture")
  2298. catheter_suture_other := c.GetString("catheter_suture_other")
  2299. edema := c.GetString("edema")
  2300. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2301. special_treatment := c.GetString("special_treatment")
  2302. catheter_maintenance := c.GetString("catheter_maintenance")
  2303. thrombusType := c.GetString("thromubus_type")
  2304. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  2305. thrombus_a := c.GetString("thromubus_a")
  2306. thrombus_av := c.GetString("thrombus_av")
  2307. thrombus_v := c.GetString("thromubus_v")
  2308. dehydration := c.GetString("dehydration")
  2309. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  2310. period, _ := c.GetInt64("period")
  2311. estimated_food_intake := c.GetString("estimated_food_intake")
  2312. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  2313. urea_befor := c.GetString("urea_befor")
  2314. suction := c.GetString("suction")
  2315. weight_befor_remake := c.GetString("weight_befor_remake")
  2316. height := c.GetString("height")
  2317. age := c.GetString("age")
  2318. his_department := c.GetString("his_department")
  2319. his_bed := c.GetString("his_bed")
  2320. point_puncture := c.GetString("point_puncture")
  2321. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  2322. skin_site_catheterization := c.GetString("skin_site_catheterization")
  2323. pathway_formation_time := c.GetString("pathway_formation_time")
  2324. timeLayout := "2006-01-02"
  2325. loc, _ := time.LoadLocation("Local")
  2326. var startTime int64
  2327. if len(pathway_formation_time) > 0 {
  2328. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2329. startTime = theTime.Unix()
  2330. }
  2331. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  2332. lien_necessary, _ := c.GetInt64("lien_necessary")
  2333. befor_symptoms := c.GetString("befor_symptoms")
  2334. warsh_count := c.GetString("warsh_count")
  2335. washing_time := c.GetString("washing_time")
  2336. puncture_needle_direction := c.GetString("puncture_needle_direction")
  2337. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2338. DialysisCount: dialysis_count,
  2339. EmergencyTreatment: emergency_treatment,
  2340. EmergencyTreatmentOther: emergency_treatment_other,
  2341. DuctusArantii: ductus_arantii,
  2342. VenousCatheterization: venous_catheterization,
  2343. VenousCatheterizationPart: venous_catheterization_part,
  2344. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2345. PunctureWay: puncture_way,
  2346. BloodAccessInternalFistula: blood_access_internal_fistula,
  2347. BloodAccessNoise: blood_access_noise,
  2348. InternalFistulaOther: internal_fistula_other,
  2349. Evaluator: adminUserInfo.AdminUser.Id,
  2350. UserOrgId: adminUserInfo.CurrentOrgId,
  2351. PatientId: patient,
  2352. AssessmentDate: recordDate.Unix(),
  2353. Temperature: temperature,
  2354. PulseFrequency: pulse_frequency,
  2355. SystolicBloodPressure: systolic_blood_pressure,
  2356. DiastolicBloodPressure: diastolic_blood_pressure,
  2357. WeightBefore: weight_before,
  2358. DryWeight: dry_weight,
  2359. AdditionalWeight: additional_weight,
  2360. DialysisInterphase: dialysis_interphase,
  2361. LastPostDialysis: last_post_dialysis,
  2362. SymptomBeforeDialysis: symptom_before_dialysis,
  2363. InternalFistula: internalFistula,
  2364. InternalFistulaSkin: internal_fistula_skin,
  2365. Catheter: catheter,
  2366. CatheterBend: catheter_bend,
  2367. Complication: complication,
  2368. CreatedTime: time.Now().Unix(),
  2369. Status: 1,
  2370. Remark: remark,
  2371. IsHemorrhage: is_hemorrhage,
  2372. Hemorrhage: hemorrhage,
  2373. HemorrhageOther: hemorrhage_other,
  2374. BloodAccessPartId: bloodAccessPartId,
  2375. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2376. PunctureMethod: puncture_method,
  2377. BreathingRate: breathing_rate,
  2378. IsInfect: is_infect,
  2379. Exposed: exposed,
  2380. Skin: skin,
  2381. SkinOther: skin_other,
  2382. InfectOther: infect_other,
  2383. DuctusArantiiOther: ductus_arantii_other,
  2384. MachineType: machine_type,
  2385. PunctureNeedle: puncture_needle,
  2386. HumorExcessiveSymptom: humor_excessive_symptom,
  2387. Phinholing: phinholing,
  2388. CatheterSuture: catheter_suture,
  2389. CatheterSutureOther: catheter_suture_other,
  2390. Edema: edema,
  2391. UrineVolume: urine_volume,
  2392. SpecialTreatment: special_treatment,
  2393. CatheterMaintenance: catheter_maintenance,
  2394. ThromubusType: thrombusInt,
  2395. ThrombusAv: thrombus_av,
  2396. ThromubusA: thrombus_a,
  2397. ThromubusV: thrombus_v,
  2398. Dehydration: dehydration,
  2399. PreDialysisDrugs: pre_dialysis_drugs,
  2400. Period: period,
  2401. EstimatedFoodIntake: estimated_food_intake,
  2402. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2403. UreaBefor: urea_befor,
  2404. Suction: suction,
  2405. WeightBeforRemake: weight_befor_remake,
  2406. Height: height,
  2407. Age: age,
  2408. HisDepartment: his_department,
  2409. HisBed: his_bed,
  2410. PointPuncture: point_puncture,
  2411. CatheterEvaluationProgram: catheter_evaluation_program,
  2412. SkinSiteCatheterization: skin_site_catheterization,
  2413. PathwayFormationTime: startTime,
  2414. WhetherUnobstructed: whether_unobstructed,
  2415. LienNecessary: lien_necessary,
  2416. BeforSymptoms: befor_symptoms,
  2417. WarshCount: warsh_count,
  2418. WashingTime: washing_time,
  2419. PunctureNeedleDirection: puncture_needle_direction,
  2420. }
  2421. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2422. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2423. if evaluation.ID == 0 { //新增
  2424. if appRole.UserType == 2 || appRole.UserType == 1 {
  2425. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2426. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2427. } else {
  2428. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2429. }
  2430. // 查询信息规挡的设置天数
  2431. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2432. if infor.ID > 0 && infor.WeekDay > 0 {
  2433. var cha_time int64
  2434. timeNowStr := time.Now().Format("2006-01-02")
  2435. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2436. //今日的日期减去设置的日期
  2437. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2438. if cha_time >= recordDate.Unix() {
  2439. //查询审核是否允许
  2440. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2441. //申请状态不允许的情况 拒绝修改
  2442. if infor.ApplicationStatus != 1 {
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2444. return
  2445. }
  2446. }
  2447. }
  2448. if adminUserInfo.CurrentOrgId == 10644 {
  2449. assessmentBeforeDislysis.PunctureNeedle = ""
  2450. }
  2451. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2452. //记录日志
  2453. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2454. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2455. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2456. AdminUserId: adminUserInfo.AdminUser.Id,
  2457. ErrLog: string(byterequest),
  2458. PatientId: assessmentBeforeDislysis.PatientId,
  2459. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2460. Ctime: time.Now().Unix(),
  2461. Mtime: 0,
  2462. Status: 1,
  2463. Source: "电脑端保存透前评估",
  2464. }
  2465. service.CreateBeforLog(beforeDislysisLog)
  2466. //创建步骤表
  2467. finish := models.XtDialysisFinish{
  2468. IsFinish: 1,
  2469. UserOrgId: adminUserInfo.CurrentOrgId,
  2470. Status: 1,
  2471. Ctime: time.Now().Unix(),
  2472. Mtime: 0,
  2473. Module: 3,
  2474. RecordDate: recordDate.Unix(),
  2475. Sourse: 1,
  2476. PatientId: patient,
  2477. }
  2478. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2479. if dialysisFinish.ID == 0 {
  2480. service.CreateDialysisFinish(finish)
  2481. }
  2482. 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 == 10731 || adminUserInfo.CurrentOrgId == 10727 {
  2483. var dewater_amount float64
  2484. dewater_amount = 0
  2485. if dry_weight > 0 {
  2486. dewater_amount = weight_before - dry_weight - additional_weight
  2487. 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 {
  2488. dewater_amount = dewater_amount * 1000
  2489. }
  2490. if dewater_amount <= 0 {
  2491. dewater_amount = 0
  2492. }
  2493. } else {
  2494. dewater_amount = 0
  2495. }
  2496. // 计算透析处方的相关超滤量
  2497. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2498. var lastDialysisPrescribe *models.DialysisPrescription
  2499. var dialysisSolution *models.DialysisSolution
  2500. var dialysisPrescribe *models.DialysisPrescription
  2501. var mode_id int64
  2502. if schedual != nil {
  2503. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2504. if dialysisPrescribe == nil {
  2505. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2506. }
  2507. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2508. // 获取透析模版
  2509. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2510. mode_id = schedual.ModeId
  2511. } else {
  2512. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2513. // 获取透析模版
  2514. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2515. // 获取透析模版
  2516. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2517. if dialysisPrescribe == nil && dialysisSolution != nil {
  2518. mode_id = dialysisSolution.ModeId
  2519. }
  2520. if dialysisPrescribe == nil && dialysisSolution == nil {
  2521. mode_id = 0
  2522. }
  2523. }
  2524. // 插入透析处方
  2525. if dialysisPrescribe == nil && dialysisSolution != nil {
  2526. var newprescribe models.DialysisPrescription
  2527. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2528. newprescribe.PatientId = patient
  2529. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2530. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2531. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2532. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2533. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2534. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2535. newprescribe.ModeId = dialysisSolution.ModeId
  2536. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2537. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2538. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2539. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2540. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2541. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2542. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2543. newprescribe.Glucose = dialysisSolution.Glucose
  2544. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2545. newprescribe.Kalium = dialysisSolution.Kalium
  2546. newprescribe.Sodium = dialysisSolution.Sodium
  2547. newprescribe.Calcium = dialysisSolution.Calcium
  2548. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2549. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2550. newprescribe.Conductivity = dialysisSolution.Conductivity
  2551. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2552. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2553. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2554. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2555. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2556. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2557. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2558. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2559. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2560. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2561. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2562. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2563. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2564. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2565. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2566. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2567. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2568. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2569. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2570. newprescribe.CreatedTime = time.Now().Unix()
  2571. newprescribe.UpdatedTime = time.Now().Unix()
  2572. newprescribe.RecordDate = recordDate.Unix()
  2573. newprescribe.DewaterAmount = dewater_amount
  2574. newprescribe.TargetUltrafiltration = dewater_amount
  2575. newprescribe.PrescriptionWater = dewater_amount
  2576. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2577. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  2578. newprescribe.Status = 1
  2579. if adminUserInfo.CurrentOrgId == 10579 {
  2580. newprescribe.Modifier = 0
  2581. newprescribe.PrescriptionDoctor = 0
  2582. newprescribe.Creater = 0
  2583. }
  2584. err := service.AddSigleRecord(&newprescribe)
  2585. //记录日志
  2586. byterequest, _ := json.Marshal(newprescribe)
  2587. prescriptionLog := models.XtDialysisPrescriptionLog{
  2588. UserOrgId: newprescribe.UserOrgId,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. ErrLog: string(byterequest),
  2592. AdminUserId: adminUserInfo.AdminUser.Id,
  2593. RecordDate: newprescribe.RecordDate,
  2594. PatientId: newprescribe.PatientId,
  2595. Source: "电脑端透前评估保存",
  2596. Status: 1,
  2597. }
  2598. service.CreatePrescriptionLog(prescriptionLog)
  2599. if err != nil {
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2601. }
  2602. }
  2603. if dialysisPrescribe == nil && dialysisSolution == nil {
  2604. if lastDialysisPrescribe != nil {
  2605. var newprescribe models.DialysisPrescription
  2606. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2607. newprescribe.PatientId = patient
  2608. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2609. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2610. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2611. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2612. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2613. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2614. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2615. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2616. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2617. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2618. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2619. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2620. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2621. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2622. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2623. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2624. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2625. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2626. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2627. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2628. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2629. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2630. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2631. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2632. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2633. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2634. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2635. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2636. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2637. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2638. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2639. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2640. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2641. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2642. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2643. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2644. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2645. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2646. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2647. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2648. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  2649. newprescribe.CreatedTime = time.Now().Unix()
  2650. newprescribe.UpdatedTime = time.Now().Unix()
  2651. newprescribe.RecordDate = recordDate.Unix()
  2652. newprescribe.DewaterAmount = dewater_amount
  2653. newprescribe.PrescriptionWater = dewater_amount
  2654. newprescribe.TargetUltrafiltration = dewater_amount
  2655. newprescribe.Status = 1
  2656. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2657. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2658. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2659. if adminUserInfo.CurrentOrgId == 10579 {
  2660. newprescribe.Modifier = 0
  2661. newprescribe.PrescriptionDoctor = 0
  2662. newprescribe.Creater = 0
  2663. }
  2664. err := service.AddSigleRecord(&newprescribe)
  2665. //记录日志
  2666. byterequest, _ := json.Marshal(newprescribe)
  2667. prescriptionLog := models.XtDialysisPrescriptionLog{
  2668. UserOrgId: newprescribe.UserOrgId,
  2669. Ctime: time.Now().Unix(),
  2670. Mtime: 0,
  2671. ErrLog: string(byterequest),
  2672. AdminUserId: adminUserInfo.AdminUser.Id,
  2673. RecordDate: newprescribe.RecordDate,
  2674. PatientId: newprescribe.PatientId,
  2675. Source: "电脑端透前评估保存",
  2676. Status: 1,
  2677. }
  2678. service.CreatePrescriptionLog(prescriptionLog)
  2679. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2680. redis := service.RedisClient()
  2681. defer redis.Close()
  2682. //清空key 值
  2683. redis.Set(key, "", time.Second)
  2684. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2685. redis.Set(keyOne, "", time.Second)
  2686. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2687. redis.Set(keyThree, "", time.Second)
  2688. if err != nil {
  2689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2690. }
  2691. } else {
  2692. var newprescribe models.DialysisPrescription
  2693. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2694. newprescribe.PatientId = patient
  2695. newprescribe.ModeId = mode_id
  2696. newprescribe.CreatedTime = time.Now().Unix()
  2697. newprescribe.UpdatedTime = time.Now().Unix()
  2698. newprescribe.RecordDate = recordDate.Unix()
  2699. newprescribe.DewaterAmount = dewater_amount
  2700. newprescribe.TargetUltrafiltration = dewater_amount
  2701. newprescribe.Status = 1
  2702. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2703. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2704. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2705. if adminUserInfo.CurrentOrgId == 10579 {
  2706. newprescribe.Modifier = 0
  2707. newprescribe.PrescriptionDoctor = 0
  2708. newprescribe.Creater = 0
  2709. }
  2710. err := service.AddSigleRecord(&newprescribe)
  2711. //记录日志
  2712. byterequest, _ := json.Marshal(newprescribe)
  2713. prescriptionLog := models.XtDialysisPrescriptionLog{
  2714. UserOrgId: newprescribe.UserOrgId,
  2715. Ctime: time.Now().Unix(),
  2716. Mtime: 0,
  2717. ErrLog: string(byterequest),
  2718. AdminUserId: adminUserInfo.AdminUser.Id,
  2719. RecordDate: newprescribe.RecordDate,
  2720. PatientId: newprescribe.PatientId,
  2721. Source: "电脑端透前评估保存",
  2722. Status: 1,
  2723. }
  2724. service.CreatePrescriptionLog(prescriptionLog)
  2725. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2726. redis := service.RedisClient()
  2727. defer redis.Close()
  2728. //清空key 值
  2729. redis.Set(key, "", time.Second)
  2730. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2731. redis.Set(keyOne, "", time.Second)
  2732. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2733. redis.Set(keyThree, "", time.Second)
  2734. if err != nil {
  2735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2736. }
  2737. }
  2738. }
  2739. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  2740. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  2741. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2742. if len(monitorList) > 0 {
  2743. var ultrafiltration_rate float64
  2744. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2745. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2746. var replacement_rate float64
  2747. //乘10 除10是为了保留一位小数
  2748. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2749. var firstOpeateTime = monitorList[0].OperateTime
  2750. for _, item := range monitorList {
  2751. //超滤率
  2752. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2753. //置换率
  2754. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2755. //超滤量
  2756. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2757. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2758. //置换量
  2759. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2760. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2761. }
  2762. }
  2763. }
  2764. }
  2765. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2766. redis := service.RedisClient()
  2767. //清空key 值
  2768. redis.Set(key, "", time.Second)
  2769. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2770. redis.Set(keyOne, "", time.Second)
  2771. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2772. redis.Set(keyTwo, "", time.Second)
  2773. defer redis.Close()
  2774. if err == nil {
  2775. c.ServeSuccessJSON(map[string]interface{}{
  2776. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2777. })
  2778. } else {
  2779. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2781. }
  2782. } else { //修改
  2783. //if appRole.UserType == 3 {
  2784. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2785. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2786. // if getPermissionErr != nil {
  2787. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2788. // return
  2789. // } else if headNursePermission == nil {
  2790. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2791. // return
  2792. // }
  2793. // }
  2794. //}
  2795. if appRole.UserType == 2 || appRole.UserType == 1 {
  2796. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2797. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2798. } else {
  2799. if evaluation.Creater == 0 {
  2800. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2801. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2802. } else {
  2803. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2804. }
  2805. }
  2806. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2807. assessmentBeforeDislysis.ID = evaluation.ID
  2808. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2809. //
  2810. //新增逻辑
  2811. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2812. var dewater_amount float64
  2813. dewater_amount = 0
  2814. if evaluation.DryWeight > 0 {
  2815. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2816. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 || adminUserInfo.CurrentOrgId == 10551 {
  2817. if adminUserInfo.CurrentOrgId != 10551 {
  2818. dewater_amount = dewater_amount * 1000
  2819. }
  2820. }
  2821. if dewater_amount <= 0 {
  2822. dewater_amount = 0
  2823. }
  2824. } else {
  2825. dewater_amount = 0
  2826. }
  2827. // 计算透析处方的相关超滤量
  2828. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2829. var lastDialysisPrescribe *models.DialysisPrescription
  2830. var dialysisSolution *models.DialysisSolution
  2831. var dialysisPrescribe *models.DialysisPrescription
  2832. var mode_id int64
  2833. if schedual != nil {
  2834. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2835. if dialysisPrescribe == nil {
  2836. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2837. }
  2838. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2839. // 获取透析模版
  2840. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2841. mode_id = schedual.ModeId
  2842. } else {
  2843. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2844. // 获取透析模版
  2845. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2846. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2847. if dialysisPrescribe == nil && dialysisSolution != nil {
  2848. mode_id = dialysisSolution.ModeId
  2849. }
  2850. if dialysisPrescribe == nil && dialysisSolution == nil {
  2851. mode_id = 0
  2852. }
  2853. }
  2854. // 插入透析处方
  2855. if dialysisPrescribe == nil && dialysisSolution != nil {
  2856. var newprescribe models.DialysisPrescription
  2857. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2858. newprescribe.PatientId = patient
  2859. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2860. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2861. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2862. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2863. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2864. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2865. newprescribe.ModeId = dialysisSolution.ModeId
  2866. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2867. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2868. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2869. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2870. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2871. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2872. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2873. newprescribe.Glucose = dialysisSolution.Glucose
  2874. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2875. newprescribe.Kalium = dialysisSolution.Kalium
  2876. newprescribe.Sodium = dialysisSolution.Sodium
  2877. newprescribe.Calcium = dialysisSolution.Calcium
  2878. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2879. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2880. newprescribe.Conductivity = dialysisSolution.Conductivity
  2881. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2882. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2883. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2884. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2885. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2886. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2887. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2888. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2889. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2890. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2891. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2892. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2893. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2894. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2895. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2896. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2897. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2898. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2899. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2900. newprescribe.CreatedTime = time.Now().Unix()
  2901. newprescribe.UpdatedTime = time.Now().Unix()
  2902. newprescribe.RecordDate = recordDate.Unix()
  2903. newprescribe.DewaterAmount = dewater_amount
  2904. newprescribe.TargetUltrafiltration = dewater_amount
  2905. newprescribe.PrescriptionWater = dewater_amount
  2906. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2907. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  2908. newprescribe.Status = 1
  2909. if adminUserInfo.CurrentOrgId == 10579 {
  2910. newprescribe.Modifier = 0
  2911. newprescribe.PrescriptionDoctor = 0
  2912. newprescribe.Creater = 0
  2913. }
  2914. err := service.AddSigleRecord(&newprescribe)
  2915. //记录日志
  2916. byterequest, _ := json.Marshal(newprescribe)
  2917. prescriptionLog := models.XtDialysisPrescriptionLog{
  2918. UserOrgId: newprescribe.UserOrgId,
  2919. Ctime: time.Now().Unix(),
  2920. Mtime: 0,
  2921. ErrLog: string(byterequest),
  2922. AdminUserId: adminUserInfo.AdminUser.Id,
  2923. RecordDate: newprescribe.RecordDate,
  2924. PatientId: newprescribe.PatientId,
  2925. Source: "电脑端透前评估保存",
  2926. Status: 1,
  2927. }
  2928. service.CreatePrescriptionLog(prescriptionLog)
  2929. if err != nil {
  2930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2931. }
  2932. }
  2933. if dialysisPrescribe == nil && dialysisSolution == nil {
  2934. if lastDialysisPrescribe != nil {
  2935. var newprescribe models.DialysisPrescription
  2936. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2937. newprescribe.PatientId = patient
  2938. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2939. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2940. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2941. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2942. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2943. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2944. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2945. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2946. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2947. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2948. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2949. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2950. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2951. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2952. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2953. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2954. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2955. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2956. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2957. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2958. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2959. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2960. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2961. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2962. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2963. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2964. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2965. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2966. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2967. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2968. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2969. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2970. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2971. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2972. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2973. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2974. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2975. newprescribe.CreatedTime = time.Now().Unix()
  2976. newprescribe.UpdatedTime = time.Now().Unix()
  2977. newprescribe.RecordDate = recordDate.Unix()
  2978. newprescribe.DewaterAmount = dewater_amount
  2979. newprescribe.TargetUltrafiltration = dewater_amount
  2980. newprescribe.PrescriptionWater = dewater_amount
  2981. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2982. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2983. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2984. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2985. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  2986. newprescribe.Status = 1
  2987. if adminUserInfo.CurrentOrgId == 10579 {
  2988. newprescribe.Modifier = 0
  2989. newprescribe.PrescriptionDoctor = 0
  2990. newprescribe.Creater = 0
  2991. }
  2992. err := service.AddSigleRecord(&newprescribe)
  2993. //记录日志
  2994. byterequest, _ := json.Marshal(newprescribe)
  2995. prescriptionLog := models.XtDialysisPrescriptionLog{
  2996. UserOrgId: newprescribe.UserOrgId,
  2997. Ctime: time.Now().Unix(),
  2998. Mtime: 0,
  2999. ErrLog: string(byterequest),
  3000. AdminUserId: adminUserInfo.AdminUser.Id,
  3001. RecordDate: newprescribe.RecordDate,
  3002. PatientId: newprescribe.PatientId,
  3003. Source: "电脑端透前评估保存",
  3004. Status: 1,
  3005. }
  3006. service.CreatePrescriptionLog(prescriptionLog)
  3007. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3008. redis := service.RedisClient()
  3009. defer redis.Close()
  3010. //清空key 值
  3011. redis.Set(key, "", time.Second)
  3012. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3013. redis.Set(keyOne, "", time.Second)
  3014. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3015. redis.Set(keyThree, "", time.Second)
  3016. if err != nil {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3018. }
  3019. } else {
  3020. var newprescribe models.DialysisPrescription
  3021. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3022. newprescribe.PatientId = patient
  3023. newprescribe.ModeId = mode_id
  3024. newprescribe.CreatedTime = time.Now().Unix()
  3025. newprescribe.UpdatedTime = time.Now().Unix()
  3026. newprescribe.RecordDate = recordDate.Unix()
  3027. newprescribe.DewaterAmount = dewater_amount
  3028. newprescribe.TargetUltrafiltration = dewater_amount
  3029. newprescribe.Status = 1
  3030. err := service.AddSigleRecord(&newprescribe)
  3031. //记录日志
  3032. byterequest, _ := json.Marshal(newprescribe)
  3033. prescriptionLog := models.XtDialysisPrescriptionLog{
  3034. UserOrgId: newprescribe.UserOrgId,
  3035. Ctime: time.Now().Unix(),
  3036. Mtime: 0,
  3037. ErrLog: string(byterequest),
  3038. AdminUserId: adminUserInfo.AdminUser.Id,
  3039. RecordDate: newprescribe.RecordDate,
  3040. PatientId: newprescribe.PatientId,
  3041. Source: "电脑端透前评估保存",
  3042. Status: 1,
  3043. }
  3044. service.CreatePrescriptionLog(prescriptionLog)
  3045. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3046. redis := service.RedisClient()
  3047. defer redis.Close()
  3048. //清空key 值
  3049. redis.Set(key, "", time.Second)
  3050. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3051. redis.Set(keyOne, "", time.Second)
  3052. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3053. redis.Set(keyThree, "", time.Second)
  3054. if err != nil {
  3055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3056. }
  3057. }
  3058. }
  3059. // 查询信息规挡的设置天数
  3060. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3061. if infor.ID > 0 {
  3062. var cha_time int64
  3063. timeNowStr := time.Now().Format("2006-01-02")
  3064. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3065. //今日的日期减去设置的日期
  3066. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3067. if cha_time >= recordDate.Unix() {
  3068. //查询审核是否允许
  3069. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  3070. //申请状态不允许的情况 拒绝修改
  3071. if infor.ApplicationStatus != 1 {
  3072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3073. return
  3074. }
  3075. }
  3076. }
  3077. //针对孝昌康桥超滤率计算问题
  3078. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 || adminUserInfo.CurrentOrgId == 10723 || adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10726 {
  3079. if assessmentBeforeDislysis.ID == 0 {
  3080. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3081. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3082. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3083. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3084. }
  3085. }
  3086. if assessmentBeforeDislysis.ID > 0 {
  3087. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3088. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3089. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3090. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3091. }
  3092. }
  3093. }
  3094. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  3095. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  3096. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3097. if len(monitorList) > 0 {
  3098. var ultrafiltration_rate float64
  3099. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3100. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  3101. var replacement_rate float64
  3102. //乘10 除10是为了保留一位小数
  3103. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3104. var firstOpeateTime = monitorList[0].OperateTime
  3105. for _, item := range monitorList {
  3106. //超滤率
  3107. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  3108. //置换率
  3109. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  3110. //超滤量
  3111. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  3112. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  3113. //置换量
  3114. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  3115. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  3116. }
  3117. }
  3118. }
  3119. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3120. //创建步骤表
  3121. finish := models.XtDialysisFinish{
  3122. IsFinish: 1,
  3123. UserOrgId: adminUserInfo.CurrentOrgId,
  3124. Status: 1,
  3125. Ctime: time.Now().Unix(),
  3126. Mtime: 0,
  3127. Module: 3,
  3128. RecordDate: recordDate.Unix(),
  3129. Sourse: 1,
  3130. PatientId: patient,
  3131. }
  3132. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  3133. if dialysisFinish.ID == 0 {
  3134. service.CreateDialysisFinish(finish)
  3135. }
  3136. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  3137. redis := service.RedisClient()
  3138. //清空key 值
  3139. redis.Set(key, "", time.Second)
  3140. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  3141. redis.Set(keyOne, "", time.Second)
  3142. defer redis.Close()
  3143. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3144. redis.Set(keyTwo, "", time.Second)
  3145. if err == nil {
  3146. c.ServeSuccessJSON(map[string]interface{}{
  3147. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3148. })
  3149. } else {
  3150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3151. }
  3152. }
  3153. }
  3154. func (c *DialysisApiController) PostTreatmentSummary() {
  3155. patient, _ := c.GetInt64("patient", 0)
  3156. recordDateStr := c.GetString("record_date")
  3157. if patient <= 0 {
  3158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3159. return
  3160. }
  3161. adminUserInfo := c.GetAdminUserInfo()
  3162. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3163. if patientInfo.ID == 0 {
  3164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3165. return
  3166. }
  3167. if len(recordDateStr) == 0 {
  3168. recordDateStr = time.Now().Format("2006-01-02")
  3169. }
  3170. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3171. if parseDateErr != nil {
  3172. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3174. return
  3175. }
  3176. mission := c.GetString("mission")
  3177. dialysis_summary := c.GetString("dialysis_summary")
  3178. nursingRecord := c.GetString("nursing_record")
  3179. specialRecord := c.GetString("special_record")
  3180. sj_nurse := adminUserInfo.AdminUser.Id
  3181. zl_nurse := adminUserInfo.AdminUser.Id
  3182. hd_nurse := adminUserInfo.AdminUser.Id
  3183. xj_nurse := adminUserInfo.AdminUser.Id
  3184. zl_doctor := adminUserInfo.AdminUser.Id
  3185. treatmentSummary := models.TreatmentSummary{
  3186. UserOrgId: adminUserInfo.CurrentOrgId,
  3187. PatientId: patient,
  3188. AssessmentDate: recordDate.Unix(),
  3189. Mission: mission,
  3190. DialysisSummary: dialysis_summary,
  3191. SjNurse: sj_nurse,
  3192. ZlNurse: zl_nurse,
  3193. HdNurse: hd_nurse,
  3194. XjNurse: xj_nurse,
  3195. ZlDoctor: zl_doctor,
  3196. Status: 1,
  3197. CreatedTime: time.Now().Unix(),
  3198. NursingRecord: nursingRecord,
  3199. SpecialRecord: specialRecord,
  3200. }
  3201. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3202. if tempTreatmentSummary.ID == 0 { //新增
  3203. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3204. // 查询信息规挡的设置天数
  3205. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3206. if infor.ID > 0 && infor.WeekDay > 0 {
  3207. var cha_time int64
  3208. timeNowStr := time.Now().Format("2006-01-02")
  3209. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3210. //今日的日期减去设置的日期
  3211. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3212. if cha_time >= recordDate.Unix() {
  3213. //查询审核是否允许
  3214. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3215. //申请状态不允许的情况 拒绝修改
  3216. if infor.ApplicationStatus != 1 {
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3218. return
  3219. }
  3220. }
  3221. }
  3222. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3223. finish := models.XtDialysisFinish{
  3224. IsFinish: 1,
  3225. UserOrgId: adminUserInfo.CurrentOrgId,
  3226. Status: 1,
  3227. Ctime: time.Now().Unix(),
  3228. Mtime: 0,
  3229. Module: 10,
  3230. RecordDate: recordDate.Unix(),
  3231. Sourse: 1,
  3232. PatientId: patient,
  3233. }
  3234. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  3235. if dialysisFinish.ID == 0 {
  3236. service.CreateDialysisFinish(finish)
  3237. }
  3238. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3239. redis := service.RedisClient()
  3240. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3241. redis.Set(keyOne, "", time.Second)
  3242. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3243. redis.Set(keyThree, "", time.Second)
  3244. defer redis.Close()
  3245. //清空key 值
  3246. redis.Set(key, "", time.Second)
  3247. if err == nil {
  3248. c.ServeSuccessJSON(map[string]interface{}{
  3249. "summary": treatmentSummary,
  3250. })
  3251. } else {
  3252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3253. }
  3254. } else { //修改
  3255. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3256. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3257. // if getPermissionErr != nil {
  3258. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3259. // return
  3260. // } else if headNursePermission == nil {
  3261. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3262. // return
  3263. // }
  3264. //}
  3265. // 查询信息规挡的设置天数
  3266. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3267. if infor.ID > 0 && infor.WeekDay > 0 {
  3268. var cha_time int64
  3269. timeNowStr := time.Now().Format("2006-01-02")
  3270. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3271. //今日的日期减去设置的日期
  3272. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3273. if cha_time >= recordDate.Unix() {
  3274. //查询审核是否允许
  3275. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3276. //申请状态不允许的情况 拒绝修改
  3277. if infor.ApplicationStatus != 1 {
  3278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3279. return
  3280. }
  3281. }
  3282. }
  3283. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3284. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3285. treatmentSummary.UpdatedTime = time.Now().Unix()
  3286. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3287. treatmentSummary.ID = tempTreatmentSummary.ID
  3288. err := service.UpdateSummeRecord(&treatmentSummary)
  3289. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3290. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3291. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3292. //清空key 值
  3293. redis := service.RedisClient()
  3294. redis.Set(key, "", time.Second)
  3295. redis.Set(keyOne, "", time.Second)
  3296. redis.Set(keyThree, "", time.Second)
  3297. defer redis.Close()
  3298. if err == nil {
  3299. c.ServeSuccessJSON(map[string]interface{}{
  3300. "summary": treatmentSummary,
  3301. })
  3302. } else {
  3303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3304. }
  3305. }
  3306. }
  3307. func (c *DialysisApiController) GetDeviceList() {
  3308. adminUserInfo := c.GetAdminUserInfo()
  3309. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3310. c.ServeSuccessJSON(map[string]interface{}{
  3311. "device": device,
  3312. })
  3313. }
  3314. func (c *DialysisApiController) GetAllDeviceZone() {
  3315. adminUserInfo := c.GetAdminUserInfo()
  3316. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3317. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  3318. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  3319. if err == nil {
  3320. c.ServeSuccessJSON(map[string]interface{}{
  3321. "zone": zone,
  3322. "dics": dics,
  3323. "efs": efs,
  3324. })
  3325. }
  3326. }
  3327. func (c *DialysisApiController) GetDialysisWatch() {
  3328. page, _ := c.GetInt64("page", 1)
  3329. limit, _ := c.GetInt64("limit", 10)
  3330. schedulType, _ := c.GetInt64("schedul_type", 0)
  3331. startTime, _ := c.GetInt64("schedul_time", 0)
  3332. partitionType, _ := c.GetInt64("partition_type", 0)
  3333. keywords := c.GetString("keywords")
  3334. start_time, _ := c.GetInt64("start_time")
  3335. end_time, _ := c.GetInt64("end_time")
  3336. adminUserInfo := c.GetAdminUserInfo()
  3337. if len(keywords) > 0 {
  3338. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3339. if err == nil {
  3340. c.ServeSuccessJSON(map[string]interface{}{
  3341. "schedule": dialysisSchedule,
  3342. "total": total,
  3343. })
  3344. } else {
  3345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3346. }
  3347. } else {
  3348. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3349. for _, item := range dialysisSchedule {
  3350. patients, _ := service.GetMonitorPatients(item.PatientId)
  3351. item.MonitorPatients = patients
  3352. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  3353. item.DialysisOrder = orderObj
  3354. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  3355. item.Prescription = prescription
  3356. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  3357. item.AssessmentBeforeDislysis = evaluation
  3358. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  3359. item.AssessmentAfterDislysis = afterdislysis
  3360. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  3361. item.MonitoringRecord = monitorRecord
  3362. }
  3363. if err == nil {
  3364. c.ServeSuccessJSON(map[string]interface{}{
  3365. "schedule": dialysisSchedule,
  3366. "total": total,
  3367. })
  3368. } else {
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. }
  3371. }
  3372. }
  3373. //func (c *DialysisApiController) GetDialysisWatch() {
  3374. // page, _ := c.GetInt64("page", 1)
  3375. // limit, _ := c.GetInt64("limit", 10)
  3376. // schedulType, _ := c.GetInt64("schedul_type", 0)
  3377. // startTime, _ := c.GetInt64("schedul_time", 0)
  3378. // partitionType, _ := c.GetInt64("partition_type", 0)
  3379. // keywords := c.GetString("keywords")
  3380. //
  3381. // adminUserInfo := c.GetAdminUserInfo()
  3382. // if len(keywords) > 0 {
  3383. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3384. //
  3385. // //获取所有床位号
  3386. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  3387. //
  3388. // //获取透析处方
  3389. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  3390. // //获取透前评估
  3391. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3392. // //获取上机
  3393. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3394. // //获取透后
  3395. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3396. //
  3397. // //获取透后监测
  3398. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3399. //
  3400. // //获取所有的患者
  3401. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3402. //
  3403. // //获取所有透析模式
  3404. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3405. //
  3406. // for key, scheduals := range dialysisSchedule {
  3407. // // 获取患者信息
  3408. // for _, patient := range patients {
  3409. // if scheduals.PatientId == patient.ID {
  3410. // dialysisSchedule[key].MonitorPatients = patient
  3411. // break
  3412. // }
  3413. // }
  3414. // // 床位信息
  3415. // for _, device := range numberList {
  3416. // if scheduals.BedId == device.ID {
  3417. // dialysisSchedule[key].DeviceNumber = device
  3418. // break
  3419. // }
  3420. // }
  3421. //
  3422. // // 医嘱信息
  3423. // for _, prescription := range prescriptions {
  3424. // if scheduals.PatientId == prescription.PatientId {
  3425. // dialysisSchedule[key].Prescription = prescription
  3426. // break
  3427. // }
  3428. // }
  3429. //
  3430. // // 透前评估
  3431. // for _, assessmentBefore := range assessmentBefores {
  3432. // if scheduals.PatientId == assessmentBefore.PatientId {
  3433. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3434. // break
  3435. // }
  3436. // }
  3437. //
  3438. // // 透析上下机
  3439. // for _, dialysisOrder := range dialysisOrders {
  3440. // if scheduals.PatientId == dialysisOrder.PatientId {
  3441. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3442. // break
  3443. // }
  3444. // }
  3445. //
  3446. // records := make([]*models.MonitoringRecord, 0)
  3447. // // 透析监测
  3448. // for _, it := range monitorlist {
  3449. // records := append(records, it)
  3450. // if scheduals.PatientId == it.PatientId {
  3451. // dialysisSchedule[key].MonitoringRecord = records
  3452. // }
  3453. // }
  3454. //
  3455. // // 透后评估
  3456. // for _, afterDislysis := range AssessmentAfterDislysis {
  3457. // if scheduals.PatientId == afterDislysis.PatientId {
  3458. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3459. // break
  3460. // }
  3461. // }
  3462. //
  3463. // //透析模式
  3464. // for _, treatment := range treatments {
  3465. // if scheduals.ModeId == treatment.ID {
  3466. // dialysisSchedule[key].TreatmentMode = treatment
  3467. // break
  3468. // }
  3469. // }
  3470. // }
  3471. // //获取所有床位号
  3472. // if err == nil {
  3473. // c.ServeSuccessJSON(map[string]interface{}{
  3474. // "schedule": dialysisSchedule,
  3475. // "total": total,
  3476. // })
  3477. // } else {
  3478. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3479. // }
  3480. //
  3481. // } else {
  3482. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3483. // if err == nil {
  3484. // c.ServeSuccessJSON(map[string]interface{}{
  3485. // "schedule": dialysisSchedule,
  3486. // "total": total,
  3487. // })
  3488. // } else {
  3489. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3490. // }
  3491. // }
  3492. //}
  3493. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3494. patientId, _ := c.GetInt64("id", 0)
  3495. record_date, _ := c.GetInt64("record_date", 0)
  3496. adminUserInfo := c.GetAdminUserInfo()
  3497. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3498. var dialysisStatus int64
  3499. if dialysisOrder == nil { //没有透析记录
  3500. dialysisStatus = 0 //未透析
  3501. } else {
  3502. dialysisStatus = dialysisOrder.Stage
  3503. }
  3504. //用户基本信息
  3505. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3506. //接诊评估
  3507. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3508. //透前评估
  3509. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3510. //临时医嘱
  3511. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3512. //双人核对
  3513. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3514. //透析监测
  3515. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3516. //透后评估
  3517. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3518. //透析小结
  3519. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3520. //透析处方
  3521. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3522. if dialysisPrescription.ID == 0 {
  3523. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3524. c.ServeSuccessJSON(map[string]interface{}{
  3525. "patientInfo": schedualPatientInfo,
  3526. "dialysisPrescription": solution,
  3527. "receiverTreatmentAccess": receiverTreatmentAccess,
  3528. "predialysisEvaluation": PredialysisEvaluation,
  3529. "doctorAdvice": DoctorAdvice,
  3530. "doubleCheck": DoubleCheck,
  3531. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3532. "treatmentSummary": TreatmentSummary,
  3533. "monitorRecord": Record,
  3534. "dialysisStatus": dialysisStatus,
  3535. "dialysisOrder": dialysisOrder,
  3536. "isSolution": 1,
  3537. })
  3538. } else {
  3539. c.ServeSuccessJSON(map[string]interface{}{
  3540. "patientInfo": schedualPatientInfo,
  3541. "dialysisPrescription": dialysisPrescription,
  3542. "receiverTreatmentAccess": receiverTreatmentAccess,
  3543. "predialysisEvaluation": PredialysisEvaluation,
  3544. "doctorAdvice": DoctorAdvice,
  3545. "doubleCheck": DoubleCheck,
  3546. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3547. "treatmentSummary": TreatmentSummary,
  3548. "monitorRecord": Record,
  3549. "dialysisStatus": dialysisStatus,
  3550. "dialysisOrder": dialysisOrder,
  3551. "isSolution": 2,
  3552. })
  3553. }
  3554. }
  3555. func (c *DialysisApiController) CreateDoctorAdvice() {
  3556. patient, _ := c.GetInt64("id", 0)
  3557. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3558. record_date, _ := c.GetInt64("record_date", 0)
  3559. if patient <= 0 {
  3560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3561. return
  3562. }
  3563. adminUserInfo := c.GetAdminUserInfo()
  3564. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3565. if patientInfo.ID == 0 {
  3566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3567. return
  3568. }
  3569. var advice models.DoctorAdvice
  3570. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3571. if code > 0 {
  3572. c.ServeFailJSONWithSGJErrorCode(code)
  3573. return
  3574. }
  3575. if advice.ParentId > 0 {
  3576. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3577. if old.ID == 0 || old.PatientId != patient {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3579. return
  3580. }
  3581. if old.StopState == 1 || old.ExecutionState == 1 {
  3582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3583. return
  3584. }
  3585. if old.ParentId > 0 {
  3586. advice.ParentId = old.ParentId
  3587. }
  3588. advice.StartTime = old.StartTime
  3589. advice.AdviceDoctor = old.AdviceDoctor
  3590. advice.DeliveryWay = old.DeliveryWay
  3591. advice.ExecutionFrequency = old.ExecutionFrequency
  3592. }
  3593. advice.RecordDate = record_date
  3594. advice.DialysisOrderId = dialysis_id
  3595. advice.Status = 1
  3596. advice.CreatedTime = time.Now().Unix()
  3597. advice.UpdatedTime = time.Now().Unix()
  3598. advice.StopState = 2
  3599. advice.ExecutionState = 2
  3600. advice.AdviceType = 2
  3601. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3602. advice.PatientId = patient
  3603. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3604. err := service.CreateDoctorAdvice(&advice)
  3605. if err != nil {
  3606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3607. return
  3608. }
  3609. for _, subAdvice := range subAdivice {
  3610. subAdvice.ParentId = advice.ID
  3611. subAdvice.PatientId = patient
  3612. subAdvice.RecordDate = record_date
  3613. subAdvice.CreatedTime = time.Now().Unix()
  3614. subAdvice.UpdatedTime = time.Now().Unix()
  3615. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3616. }
  3617. service.CreateSubDoctorAdvice(subAdivice)
  3618. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3619. c.ServeSuccessJSON(map[string]interface{}{
  3620. "msg": "ok",
  3621. "advice": advice,
  3622. "subAdvice": subAdivices,
  3623. })
  3624. return
  3625. }
  3626. func (c *DialysisApiController) EditDoctorAdvice() {
  3627. patient, _ := c.GetInt64("patient", 0)
  3628. id, _ := c.GetInt64("id", 0)
  3629. parent_id, _ := c.GetInt64("parent_id", 0)
  3630. execution_time := c.GetString("execution_time")
  3631. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3632. // checker, _ := c.GetInt64("checker", 0)
  3633. if id <= 0 || patient <= 0 {
  3634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3635. return
  3636. }
  3637. adminUserInfo := c.GetAdminUserInfo()
  3638. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3639. if advice.ID == 0 || advice.PatientId != patient {
  3640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3641. return
  3642. }
  3643. if len(execution_time) <= 0 {
  3644. utils.ErrorLog("execution_time")
  3645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3646. return
  3647. }
  3648. execution_staff := adminUserInfo.AdminUser.Id
  3649. checker := adminUserInfo.AdminUser.Id
  3650. timeLayout2 := "2006-01-02 15:04"
  3651. loc, _ := time.LoadLocation("Local")
  3652. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3653. if errs != nil {
  3654. utils.ErrorLog(errs.Error())
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3656. return
  3657. }
  3658. advices := models.DoctorAdvice{
  3659. ExecutionStaff: execution_staff,
  3660. ExecutionTime: theTime.Unix(),
  3661. Checker: checker,
  3662. UpdatedTime: time.Now().Unix(),
  3663. }
  3664. var err error
  3665. if parent_id > 0 {
  3666. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3667. } else {
  3668. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3669. }
  3670. if err != nil {
  3671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3672. return
  3673. }
  3674. c.ServeSuccessJSON(map[string]interface{}{
  3675. "msg": "ok",
  3676. "advice": advice,
  3677. })
  3678. return
  3679. }
  3680. func (c *DialysisApiController) GetDoctorAdvice() {
  3681. patient, _ := c.GetInt64("patient_id", 0)
  3682. parent_id, _ := c.GetInt64("parent_id", 0)
  3683. adviceId, _ := c.GetInt64("id", 0)
  3684. if patient <= 0 {
  3685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3686. return
  3687. }
  3688. dminUserInfo := c.GetAdminUserInfo()
  3689. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3690. if patientInfo.ID == 0 {
  3691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3692. return
  3693. }
  3694. var subAdvice []*models.DoctorAdvice
  3695. var advice models.DoctorAdvice
  3696. if parent_id > 0 {
  3697. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3698. if advice.ID == 0 || advice.PatientId != patient {
  3699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3700. return
  3701. }
  3702. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3703. } else {
  3704. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3705. if advice.ID == 0 || advice.PatientId != patient {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3707. return
  3708. }
  3709. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3710. }
  3711. c.ServeSuccessJSON(map[string]interface{}{
  3712. "msg": "ok",
  3713. "advice": advice,
  3714. "subAdvice": subAdvice,
  3715. })
  3716. }
  3717. func (this *DialysisApiController) DelMonitor() {
  3718. recordID, _ := this.GetInt64("record_id")
  3719. patientID, _ := this.GetInt64("patient_id")
  3720. if recordID <= 0 || patientID <= 0 {
  3721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3722. return
  3723. }
  3724. adminInfo := this.GetAdminUserInfo()
  3725. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3726. if getPatientErr != nil {
  3727. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3729. return
  3730. } else if patient == nil {
  3731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3732. return
  3733. }
  3734. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3735. if getMonitorErr != nil {
  3736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3737. return
  3738. }
  3739. //if monitor != nil {
  3740. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3741. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3742. // if getPermissionErr != nil {
  3743. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3744. // return
  3745. // } else if headNursePermission == nil {
  3746. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3747. // return
  3748. // }
  3749. // }
  3750. //}
  3751. // 查询信息规挡的设置天数
  3752. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3753. if infor.ID > 0 && infor.WeekDay > 0 {
  3754. var cha_time int64
  3755. timeNowStr := time.Now().Format("2006-01-02")
  3756. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3757. //今日的日期减去设置的日期
  3758. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3759. if cha_time >= monitor.MonitoringDate {
  3760. //查询审核是否允许
  3761. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3762. //申请状态不允许的情况 拒绝修改
  3763. if infor.ApplicationStatus != 1 {
  3764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3765. return
  3766. }
  3767. }
  3768. }
  3769. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3770. //记录日志
  3771. byterequest, _ := json.Marshal(monitor)
  3772. monitorRecordLog := models.XtMonitorRecordLog{
  3773. RecordDate: monitor.MonitoringDate,
  3774. PatientId: monitor.PatientId,
  3775. Module: 3,
  3776. AdminUserId: adminInfo.AdminUser.Id,
  3777. Ctime: time.Now().Unix(),
  3778. Mtime: 0,
  3779. Status: 1,
  3780. UserOrgId: monitor.UserOrgId,
  3781. ErrLog: string(byterequest),
  3782. Source: "电脑端删除监测",
  3783. }
  3784. service.CreateMonitorRecordLog(monitorRecordLog)
  3785. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3786. redis := service.RedisClient()
  3787. //清空key 值
  3788. redis.Set(key, "", time.Second)
  3789. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3790. redis.Set(keyOne, "", time.Second)
  3791. defer redis.Close()
  3792. if err != nil {
  3793. this.ErrorLog("删除透析监测记录失败:%v", err)
  3794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3795. return
  3796. }
  3797. this.ServeSuccessJSON(map[string]interface{}{
  3798. "record_id": monitor.ID,
  3799. })
  3800. }
  3801. func (c *DialysisApiController) CreateMonitor() {
  3802. patient, _ := c.GetInt64("id", 0)
  3803. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3804. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3805. operate_time, _ := c.GetInt64("operate_time", 0)
  3806. // monitoring_time := c.GetString("monitoring_time")
  3807. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3808. breathing_rated := c.GetString("breathing_rated")
  3809. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3810. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3811. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3812. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3813. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3814. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3815. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3816. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3817. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3818. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3819. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3820. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3821. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3822. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3823. temperature, _ := c.GetFloat("temperature", 0)
  3824. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3825. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3826. conductivity, _ := c.GetFloat("conductivity", 0)
  3827. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3828. heparin, _ := c.GetFloat("heparin", 0)
  3829. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3830. ktv, _ := c.GetFloat("ktv", 0)
  3831. symptom := c.GetString("symptom")
  3832. dispose := c.GetString("dispose")
  3833. result := c.GetString("results")
  3834. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3835. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3836. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3837. replacement_speed, _ := c.GetFloat("replacement_speed")
  3838. dicarbonate, _ := c.GetFloat("dicarbonate")
  3839. monitoring_date = monitoring_date / 1000
  3840. // operate_time = operate_time / 1000
  3841. if patient <= 0 {
  3842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3843. return
  3844. }
  3845. adminUserInfo := c.GetAdminUserInfo()
  3846. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3847. if patientInfo.ID == 0 {
  3848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3849. return
  3850. }
  3851. monitorRecord := models.MonitoringRecord{
  3852. PatientId: patient,
  3853. MonitoringDate: monitoring_date,
  3854. DialysisOrderId: dialysis_order_id,
  3855. OperateTime: operate_time,
  3856. // MonitoringTime: monitoring_time,
  3857. PulseFrequency: pulse_frequency,
  3858. BreathingRate: breathing_rated,
  3859. SystolicBloodPressure: systolic_blood_pressure,
  3860. DiastolicBloodPressure: diastolic_blood_pressure,
  3861. BloodPressureType: blood_pressure_type,
  3862. BloodFlowVolume: blood_flow_volume,
  3863. VenousPressure: venous_pressure,
  3864. VenousPressureType: venous_pressure_type,
  3865. TransmembranePressure: transmembrane_pressure,
  3866. TransmembranePressureType: transmembrane_pressure_type,
  3867. UltrafiltrationRate: ultrafiltration_rate,
  3868. UltrafiltrationVolume: ultrafiltration_volume,
  3869. SodiumConcentration: sodium_concentration,
  3870. ArterialPressure: arterial_pressure,
  3871. ArterialPressureType: arterial_pressure_type,
  3872. DialysateTemperature: dialysate_temperature,
  3873. Temperature: temperature,
  3874. ReplacementRate: replacement_rate,
  3875. DisplacementQuantity: displacement_quantity,
  3876. Ktv: ktv,
  3877. Symptom: symptom,
  3878. Dispose: dispose,
  3879. Result: result,
  3880. MonitoringNurse: monitoring_nurse,
  3881. Status: 1,
  3882. CreatedTime: time.Now().Unix(),
  3883. UpdatedTime: time.Now().Unix(),
  3884. UserOrgId: adminUserInfo.CurrentOrgId,
  3885. Conductivity: conductivity,
  3886. DisplacementFlowQuantity: displacement_flow_quantity,
  3887. Heparin: heparin,
  3888. DialysateFlow: dialysate_flow,
  3889. MonitorAnticoagulant: monitor_anticoagulant,
  3890. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3891. ReplacementSpeed: replacement_speed,
  3892. Dicarbonate: dicarbonate,
  3893. }
  3894. // 查询信息规挡的设置天数
  3895. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3896. if infor.ID > 0 && infor.WeekDay > 0 {
  3897. var cha_time int64
  3898. timeNowStr := time.Now().Format("2006-01-02")
  3899. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3900. //今日的日期减去设置的日期
  3901. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3902. if cha_time >= monitoring_date {
  3903. //查询审核是否允许
  3904. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  3905. //申请状态不允许的情况 拒绝修改
  3906. if infor.ApplicationStatus != 1 {
  3907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3908. return
  3909. }
  3910. }
  3911. }
  3912. err := service.CreateMonitor(&monitorRecord)
  3913. finish := models.XtDialysisFinish{
  3914. IsFinish: 1,
  3915. UserOrgId: adminUserInfo.CurrentOrgId,
  3916. Status: 1,
  3917. Ctime: time.Now().Unix(),
  3918. Mtime: 0,
  3919. Module: 7,
  3920. RecordDate: monitoring_date,
  3921. Sourse: 1,
  3922. PatientId: patient,
  3923. }
  3924. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3925. if dialysisFinish.ID == 0 {
  3926. service.CreateDialysisFinish(finish)
  3927. }
  3928. redis := service.RedisClient()
  3929. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3930. redis.Set(key, "", time.Second)
  3931. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3932. redis.Set(keyOne, "", time.Second)
  3933. redis.Close()
  3934. if err != nil {
  3935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3936. return
  3937. }
  3938. c.ServeSuccessJSON(map[string]interface{}{
  3939. "msg": "ok",
  3940. "monitor": monitorRecord,
  3941. })
  3942. return
  3943. }
  3944. // 已弃用
  3945. // func (c *DialysisApiController) CreateRecordData() {
  3946. // patient, _ := c.GetInt64("id", 0)
  3947. // status, _ := c.GetInt64("status", 0)
  3948. // now := time.Now()
  3949. // year, month, day := now.Date()
  3950. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3951. // todayTimeStamp := today_time.Unix()
  3952. // if patient <= 0 {
  3953. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3954. // return
  3955. // }
  3956. // adminUserInfo := c.GetAdminUserInfo()
  3957. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3958. // if patientInfo.ID == 0 {
  3959. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3960. // return
  3961. // }
  3962. // record := &models.DialysisOrder{
  3963. // DialysisDate: todayTimeStamp,
  3964. // UserOrgId: adminUserInfo.CurrentOrgId,
  3965. // PatientId: patient,
  3966. // Stage: status,
  3967. // Status: 1,
  3968. // CreatedTime: time.Now().Unix(),
  3969. // UpdatedTime: time.Now().Unix(),
  3970. // }
  3971. // if status == 1 {
  3972. // //创建透析记录
  3973. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3974. // if err == nil {
  3975. // c.ServeSuccessJSON(map[string]interface{}{
  3976. // "dialysisOrder": record,
  3977. // })
  3978. // } else {
  3979. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3980. // }
  3981. // } else {
  3982. // record_id, _ := c.GetInt64("record_id", 0)
  3983. // //修改透析记录状态
  3984. // errs := service.ModifyDialysisRecord(record_id)
  3985. // //结束时候透析次数加1
  3986. // service.UpdateSolutionByPatientId(patient)
  3987. // if errs == nil {
  3988. // c.ServeSuccessJSON(map[string]interface{}{
  3989. // "dialysisOrder": record,
  3990. // })
  3991. // } else {
  3992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3993. // }
  3994. // }
  3995. // }
  3996. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3997. dataBody := make(map[string]interface{}, 0)
  3998. err := json.Unmarshal(data, &dataBody)
  3999. if err != nil {
  4000. utils.ErrorLog(err.Error())
  4001. code = enums.ErrorCodeParamWrong
  4002. return
  4003. }
  4004. timeLayout := "2006-01-02 "
  4005. timeLayout2 := "2006-01-02 15:04"
  4006. loc, _ := time.LoadLocation("Local")
  4007. if action == "create" {
  4008. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4009. utils.ErrorLog("advice_type")
  4010. code = enums.ErrorCodeParamWrong
  4011. return
  4012. }
  4013. adviceType := int64(dataBody["advice_type"].(float64))
  4014. if adviceType != 1 && adviceType != 2 {
  4015. utils.ErrorLog("advice_type != 1&&2")
  4016. code = enums.ErrorCodeParamWrong
  4017. return
  4018. }
  4019. advice.AdviceType = adviceType
  4020. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4021. utils.ErrorLog("advice_date")
  4022. code = enums.ErrorCodeParamWrong
  4023. return
  4024. }
  4025. adviceDate, _ := dataBody["advice_date"].(string)
  4026. if len(adviceDate) == 0 {
  4027. utils.ErrorLog("len(adviceDate) == 0")
  4028. code = enums.ErrorCodeParamWrong
  4029. return
  4030. }
  4031. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4032. if err != nil {
  4033. utils.ErrorLog(err.Error())
  4034. code = enums.ErrorCodeParamWrong
  4035. return
  4036. }
  4037. advice.AdviceDate = theTime.Unix()
  4038. }
  4039. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4040. utils.ErrorLog("start_time")
  4041. code = enums.ErrorCodeParamWrong
  4042. return
  4043. }
  4044. startDate, _ := dataBody["start_time"].(string)
  4045. if len(startDate) == 0 {
  4046. utils.ErrorLog("len(startDate) == 0")
  4047. code = enums.ErrorCodeParamWrong
  4048. return
  4049. }
  4050. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  4051. if err != nil {
  4052. utils.ErrorLog(err.Error())
  4053. code = enums.ErrorCodeParamWrong
  4054. return
  4055. }
  4056. advice.StartTime = theTime.Unix()
  4057. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4058. utils.ErrorLog("advice_name")
  4059. code = enums.ErrorCodeParamWrong
  4060. return
  4061. }
  4062. adviceName, _ := dataBody["advice_name"].(string)
  4063. if len(adviceName) == 0 {
  4064. utils.ErrorLog("len(advice_name) == 0")
  4065. code = enums.ErrorCodeParamWrong
  4066. return
  4067. }
  4068. advice.AdviceName = adviceName
  4069. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  4070. utils.ErrorLog("delivery_way")
  4071. code = enums.ErrorCodeParamWrong
  4072. return
  4073. }
  4074. deliveryWay, _ := dataBody["delivery_way"].(string)
  4075. if len(deliveryWay) == 0 {
  4076. utils.ErrorLog("len(deliveryWay) == 0")
  4077. code = enums.ErrorCodeParamWrong
  4078. return
  4079. }
  4080. advice.DeliveryWay = deliveryWay
  4081. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  4082. utils.ErrorLog("execution_frequency")
  4083. code = enums.ErrorCodeParamWrong
  4084. return
  4085. }
  4086. execution_frequency, _ := dataBody["execution_frequency"].(string)
  4087. if len(execution_frequency) == 0 {
  4088. utils.ErrorLog("len(execution_frequency) == 0")
  4089. code = enums.ErrorCodeParamWrong
  4090. return
  4091. }
  4092. advice.ExecutionFrequency = execution_frequency
  4093. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4094. adviceDsc, _ := dataBody["advice_desc"].(string)
  4095. advice.AdviceDesc = adviceDsc
  4096. }
  4097. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4098. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4099. advice.DrugSpecUnit = drugSpecUnit
  4100. }
  4101. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4102. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4103. advice.SingleDose = singleDose
  4104. }
  4105. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4106. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4107. advice.SingleDoseUnit = singleDoseUnit
  4108. }
  4109. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4110. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4111. advice.PrescribingNumber = prescribingNumber
  4112. }
  4113. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4114. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4115. advice.PrescribingNumberUnit = prescribingNumberUnit
  4116. }
  4117. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  4118. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  4119. if len(thisContagions) > 0 {
  4120. for _, item := range thisContagions {
  4121. items := item.(map[string]interface{})
  4122. advice_name, _ := items["advice_name"].(string)
  4123. advice_desc, _ := items["advice_desc"].(string)
  4124. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  4125. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  4126. single_dose_unit, _ := items["single_dose_unit"].(string)
  4127. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  4128. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  4129. advice := &models.DoctorAdvice{
  4130. AdviceName: advice_name,
  4131. AdviceDesc: advice_desc,
  4132. SingleDose: single_dose,
  4133. SingleDoseUnit: single_dose_unit,
  4134. DrugSpecUnit: drug_spec_unit,
  4135. PrescribingNumber: prescribing_number,
  4136. PrescribingNumberUnit: prescribing_number_unit,
  4137. }
  4138. subAdvice = append(subAdvice, advice)
  4139. }
  4140. }
  4141. }
  4142. return
  4143. }
  4144. func (c *DialysisApiController) GetDialysisOrder() {
  4145. //xtno := c.GetString("xtno")
  4146. xtdate := c.GetString("xtdate")
  4147. patient_id, _ := c.GetInt64("patient_id")
  4148. timeLayout := "2006-01-02"
  4149. loc, _ := time.LoadLocation("Local")
  4150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4151. if err != nil {
  4152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4153. return
  4154. }
  4155. xttime := theTime.Unix()
  4156. operatorIDs := make([]int64, 0)
  4157. adminUserInfo := c.GetAdminUserInfo()
  4158. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4159. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  4160. //透析单
  4161. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4162. if dialysisOrder != nil {
  4163. if dialysisOrder.FinishNurse > 0 {
  4164. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4165. }
  4166. if dialysisOrder.StartNurse > 0 {
  4167. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4168. }
  4169. }
  4170. //透前评估
  4171. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4172. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  4173. //透后评估
  4174. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4175. if AssessmentAfterDislysis.Modifier > 0 {
  4176. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4177. }
  4178. //上次透前评估
  4179. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4180. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4181. //透析处方
  4182. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4183. if dialysisPrescription.PrescriptionDoctor > 0 {
  4184. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4185. }
  4186. //获取病人的透析模式
  4187. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4188. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4189. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4190. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4191. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4192. //获取透析处方
  4193. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4194. //获取临时医嘱
  4195. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4196. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4197. //获取医嘱内容
  4198. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4199. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4200. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4201. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4202. //获取上次的透后体重
  4203. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4204. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4205. //获取透析次数
  4206. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4207. if len(DoctorAdvice) > 0 {
  4208. for _, item := range DoctorAdvice {
  4209. if item.AdviceDoctor > 0 {
  4210. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4211. }
  4212. if item.ExecutionStaff > 0 {
  4213. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4214. }
  4215. if item.Checker > 0 {
  4216. operatorIDs = append(operatorIDs, item.Checker)
  4217. }
  4218. }
  4219. }
  4220. //透析监测
  4221. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4222. //透析检测
  4223. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4224. //透析小结
  4225. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4226. //接诊评估
  4227. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4228. if receiverTreatmentAccess.Condition == 1 {
  4229. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  4230. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4231. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  4232. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  4233. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  4234. }
  4235. }
  4236. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4237. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  4238. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4239. patientInfo.TotalDialysis = dialysis_count
  4240. }
  4241. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  4242. if xttime <= 1703952000 {
  4243. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4244. patientInfo.TotalDialysis = dialysis_count
  4245. }
  4246. if xttime >= 1704038400 {
  4247. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4248. patientInfo.TotalDialysis = dialysis_count
  4249. }
  4250. }
  4251. //相关操作对应的操作人
  4252. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  4253. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4254. //fmt.Println("operators------------------------------------", operators)
  4255. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  4256. //获取当前日期月份的第一天
  4257. firstmonth := service.GetFirstDateOfMonth(theTime)
  4258. firstMonthDate := firstmonth.Unix()
  4259. //获取当前月份的病人透析次数
  4260. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  4261. var hisAdvice []*models.HisDoctorAdviceInfo
  4262. var his_advices_one []*models.HisDoctorAdviceInfo
  4263. //获取his数据
  4264. hisAdvice, _ = service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4265. //针对茂名舒和
  4266. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4267. if len(hisAdvice) > 0 {
  4268. for _, item := range hisAdvice {
  4269. drug, _ := service.GetDrugIsShow(item.DrugId, adminUserInfo.CurrentOrgId)
  4270. if drug.IsShow == 1 {
  4271. his_advices_one = append(his_advices_one, item)
  4272. }
  4273. }
  4274. }
  4275. } else {
  4276. if len(hisAdvice) > 0 {
  4277. for _, item := range hisAdvice {
  4278. his_advices_one = append(his_advices_one, item)
  4279. }
  4280. }
  4281. }
  4282. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4283. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4284. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  4285. var projects []*models.HisPrescriptionProject
  4286. projects, _ = service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4287. var projectsOne []*models.HisPrescriptionProject
  4288. //针对茂名舒和
  4289. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4290. if len(projects) > 0 {
  4291. for _, item := range projects {
  4292. if item.Type == 2 {
  4293. if item.HisProject.IsShow == 1 {
  4294. projectsOne = append(projectsOne, item)
  4295. }
  4296. }
  4297. if item.Type == 3 {
  4298. if item.GoodInfo.IsShow == 1 {
  4299. projectsOne = append(projectsOne, item)
  4300. }
  4301. }
  4302. }
  4303. }
  4304. } else {
  4305. for _, item := range projects {
  4306. projectsOne = append(projectsOne, item)
  4307. }
  4308. }
  4309. //获取诊断
  4310. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4311. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  4312. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4313. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  4314. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4315. // for _, item := range projects {
  4316. // var advice *models.HisDoctorAdviceInfo
  4317. // advice.ID = item.ID
  4318. // advice.Checker = item.Checker
  4319. // advice.CheckTime = item.CheckTime
  4320. // advice.CheckState = item.CheckState
  4321. // advice.ExecutionState = item.ExecutionState
  4322. // advice.ExecutionStaff = item.ExecutionStaff
  4323. // advice.PrescribingNumber = float64(item.Count)
  4324. // advice.PrescribingNumberUnit = item.Unit
  4325. // advice.AdviceDoctor = item.Doctor
  4326. // if item.Type == 3 {
  4327. // advice.AdviceName = item.GoodInfo.GoodName
  4328. // } else if item.Type == 2 {
  4329. // advice.AdviceName = item.HisProject.ProjectName
  4330. // }
  4331. // advice.StartTime = item.StartTime
  4332. // hisAdvice = append(hisAdvice, advice)
  4333. // }
  4334. //}
  4335. if config.IsOpen == 1 {
  4336. c.ServeSuccessJSON(map[string]interface{}{
  4337. "xtdate": xtdate,
  4338. "users": adminUser,
  4339. "patientInfo": patientInfo,
  4340. "PredialysisEvaluation": PredialysisEvaluation,
  4341. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4342. "dialysisPrescription": dialysisPrescription,
  4343. "advices": his_advices_one,
  4344. "monitors": Record,
  4345. "summary": TreatmentSummary,
  4346. "receiverTreatmentAccess": receiverTreatmentAccess,
  4347. "dialysisOrder": dialysisOrder,
  4348. "operators": operators,
  4349. "org_template_info": templateInfo,
  4350. "check": check,
  4351. "schedule": schedule,
  4352. "dialysisway": dialysisway,
  4353. "order": order,
  4354. "doctorAdvice": doctorAdvice,
  4355. "doctor": doctor,
  4356. "nurse": nurse,
  4357. "doctorAdevieInfo": doctorAdevieInfo,
  4358. "total": total,
  4359. "startNuse": startNuse,
  4360. "DoctorName": DoctorName,
  4361. "assessmentAfterDislysis": assessmentAfterDislysis,
  4362. "predialysName": predialysName,
  4363. "FinishNuse": FinishNuse,
  4364. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4365. "dialysiscount": dialysiscount,
  4366. "last_order": lastOrder,
  4367. "project_config": project_config,
  4368. "projects": projectsOne,
  4369. "prescriptionInfo": prescriptionInfo,
  4370. "patientDiagnose": patientDiagnose,
  4371. "lastSchedule": lastSchedule,
  4372. "numberList": numberList,
  4373. })
  4374. }
  4375. if config.IsOpen == 0 || config.IsOpen == 2 {
  4376. c.ServeSuccessJSON(map[string]interface{}{
  4377. "xtdate": xtdate,
  4378. "users": adminUser,
  4379. "patientInfo": patientInfo,
  4380. "PredialysisEvaluation": PredialysisEvaluation,
  4381. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4382. "dialysisPrescription": dialysisPrescription,
  4383. "advices": DoctorAdvice,
  4384. "monitors": Record,
  4385. "summary": TreatmentSummary,
  4386. "receiverTreatmentAccess": receiverTreatmentAccess,
  4387. "dialysisOrder": dialysisOrder,
  4388. "operators": operators,
  4389. "org_template_info": templateInfo,
  4390. "check": check,
  4391. "schedule": schedule,
  4392. "dialysisway": dialysisway,
  4393. "order": order,
  4394. "doctorAdvice": doctorAdvice,
  4395. "doctor": doctor,
  4396. "nurse": nurse,
  4397. "doctorAdevieInfo": doctorAdevieInfo,
  4398. "total": total,
  4399. "startNuse": startNuse,
  4400. "DoctorName": DoctorName,
  4401. "assessmentAfterDislysis": assessmentAfterDislysis,
  4402. "predialysName": predialysName,
  4403. "FinishNuse": FinishNuse,
  4404. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4405. "dialysiscount": dialysiscount,
  4406. "last_order": lastOrder,
  4407. "project_config": project_config,
  4408. "projects": projects,
  4409. "prescriptionInfo": prescriptionInfo,
  4410. "patientDiagnose": patientDiagnose,
  4411. "lastSchedule": lastSchedule,
  4412. "numberList": numberList,
  4413. })
  4414. }
  4415. }
  4416. func (c *DialysisApiController) GetLongAdvice() {
  4417. patient_id, _ := c.GetInt64("patient_id")
  4418. adminUserInfo := c.GetAdminUserInfo()
  4419. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4420. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4421. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4422. c.ServeSuccessJSON(map[string]interface{}{
  4423. "status": "1",
  4424. })
  4425. return
  4426. } else { //开启推送提醒
  4427. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4428. var advice_three []*models.DoctorAdvice
  4429. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4430. recordDateStr := time.Now().Format("2006-01-02")
  4431. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4432. nowtime := recordDate.Unix()
  4433. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4434. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4435. for _, advice := range advices {
  4436. if advice.FrequencyType == 3 {
  4437. t := time.Now()
  4438. week := int(t.Weekday())
  4439. switch week {
  4440. case 1:
  4441. if strings.Index(advice.WeekDay, "周一") == -1 {
  4442. advice_three = append(advice_three, advice)
  4443. }
  4444. break
  4445. case 2:
  4446. if strings.Index(advice.WeekDay, "周二") == -1 {
  4447. advice_three = append(advice_three, advice)
  4448. }
  4449. break
  4450. case 3:
  4451. if strings.Index(advice.WeekDay, "周三") == -1 {
  4452. advice_three = append(advice_three, advice)
  4453. }
  4454. break
  4455. case 4:
  4456. if strings.Index(advice.WeekDay, "周四") == -1 {
  4457. advice_three = append(advice_three, advice)
  4458. }
  4459. break
  4460. case 5:
  4461. if strings.Index(advice.WeekDay, "周五") == -1 {
  4462. advice_three = append(advice_three, advice)
  4463. }
  4464. break
  4465. case 6:
  4466. if strings.Index(advice.WeekDay, "周六") == -1 {
  4467. advice_three = append(advice_three, advice)
  4468. }
  4469. break
  4470. case 0:
  4471. if strings.Index(advice.WeekDay, "周日") == -1 {
  4472. advice_three = append(advice_three, advice)
  4473. }
  4474. break
  4475. }
  4476. }
  4477. }
  4478. for _, advice := range advices_two {
  4479. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4480. now := p.Unix()
  4481. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4482. dayStr2 := "-" + dayStr
  4483. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4484. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4485. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4486. for _, ad := range advices {
  4487. advice_three = append(advice_three, ad)
  4488. }
  4489. }
  4490. if err == nil {
  4491. c.ServeSuccessJSON(map[string]interface{}{
  4492. "status": "2",
  4493. "advices": advices,
  4494. "advices_two": RemoveRepeatedElement(advice_three),
  4495. "is_open_remind": config.IsOpenRemind,
  4496. })
  4497. }
  4498. }
  4499. }
  4500. func (c *DialysisApiController) GetLongAdviceOne() {
  4501. patient_id, _ := c.GetInt64("patient_id")
  4502. schedule_date := c.GetString("schedule_date")
  4503. adminUserInfo := c.GetAdminUserInfo()
  4504. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4505. timeLayout := "2006-01-02"
  4506. loc, _ := time.LoadLocation("Local")
  4507. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4508. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4509. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4510. c.ServeSuccessJSON(map[string]interface{}{
  4511. "status": "1",
  4512. })
  4513. return
  4514. } else { //开启推送提醒
  4515. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4516. var advice_three []*models.DoctorAdvice
  4517. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4518. //recordDateStr := time.Now().Format("2006-01-02")
  4519. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4520. //
  4521. //nowtime := recordDate.Unix()
  4522. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4523. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4524. for _, advice := range advices {
  4525. if advice.FrequencyType == 3 {
  4526. t := time.Now()
  4527. week := int(t.Weekday())
  4528. switch week {
  4529. case 1:
  4530. if strings.Index(advice.WeekDay, "周一") == -1 {
  4531. advice_three = append(advice_three, advice)
  4532. }
  4533. break
  4534. case 2:
  4535. if strings.Index(advice.WeekDay, "周二") == -1 {
  4536. advice_three = append(advice_three, advice)
  4537. }
  4538. break
  4539. case 3:
  4540. if strings.Index(advice.WeekDay, "周三") == -1 {
  4541. advice_three = append(advice_three, advice)
  4542. }
  4543. break
  4544. case 4:
  4545. if strings.Index(advice.WeekDay, "周四") == -1 {
  4546. advice_three = append(advice_three, advice)
  4547. }
  4548. break
  4549. case 5:
  4550. if strings.Index(advice.WeekDay, "周五") == -1 {
  4551. advice_three = append(advice_three, advice)
  4552. }
  4553. break
  4554. case 6:
  4555. if strings.Index(advice.WeekDay, "周六") == -1 {
  4556. advice_three = append(advice_three, advice)
  4557. }
  4558. break
  4559. case 0:
  4560. if strings.Index(advice.WeekDay, "周日") == -1 {
  4561. advice_three = append(advice_three, advice)
  4562. }
  4563. break
  4564. }
  4565. }
  4566. }
  4567. for _, advice := range advices_two {
  4568. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4569. now := p.Unix()
  4570. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4571. dayStr2 := "-" + dayStr
  4572. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4573. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4574. fmt.Println("oldTime--------------------------", oldTime)
  4575. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4576. fmt.Println("advices-------------------------", advices)
  4577. for _, ad := range advices {
  4578. advice_three = append(advice_three, ad)
  4579. }
  4580. }
  4581. if err == nil {
  4582. c.ServeSuccessJSON(map[string]interface{}{
  4583. "status": "2",
  4584. "advices": advices,
  4585. "advices_two": RemoveRepeatedElement(advice_three),
  4586. "is_open_remind": config.IsOpenRemind,
  4587. })
  4588. }
  4589. }
  4590. }
  4591. func (c *DialysisApiController) GetLongAdviceTwo() {
  4592. patient_id, _ := c.GetInt64("patient_id")
  4593. schedule_date, _ := c.GetInt64("schedule_date")
  4594. adminUserInfo := c.GetAdminUserInfo()
  4595. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4596. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4597. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4598. c.ServeSuccessJSON(map[string]interface{}{
  4599. "status": "1",
  4600. })
  4601. return
  4602. } else { //开启推送提醒
  4603. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4604. var advice_three []*models.DoctorAdvice
  4605. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4606. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4607. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4608. for _, advice := range advices {
  4609. if advice.FrequencyType == 3 {
  4610. t := time.Now()
  4611. week := int(t.Weekday())
  4612. switch week {
  4613. case 1:
  4614. if strings.Index(advice.WeekDay, "周一") == -1 {
  4615. advice_three = append(advice_three, advice)
  4616. }
  4617. break
  4618. case 2:
  4619. if strings.Index(advice.WeekDay, "周二") == -1 {
  4620. advice_three = append(advice_three, advice)
  4621. }
  4622. break
  4623. case 3:
  4624. if strings.Index(advice.WeekDay, "周三") == -1 {
  4625. advice_three = append(advice_three, advice)
  4626. }
  4627. break
  4628. case 4:
  4629. if strings.Index(advice.WeekDay, "周四") == -1 {
  4630. advice_three = append(advice_three, advice)
  4631. }
  4632. break
  4633. case 5:
  4634. if strings.Index(advice.WeekDay, "周五") == -1 {
  4635. advice_three = append(advice_three, advice)
  4636. }
  4637. break
  4638. case 6:
  4639. if strings.Index(advice.WeekDay, "周六") == -1 {
  4640. advice_three = append(advice_three, advice)
  4641. }
  4642. break
  4643. case 0:
  4644. if strings.Index(advice.WeekDay, "周日") == -1 {
  4645. advice_three = append(advice_three, advice)
  4646. }
  4647. break
  4648. }
  4649. }
  4650. }
  4651. for _, advice := range advices_two {
  4652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4653. now := p.Unix()
  4654. fmt.Println("now-------------------------", now)
  4655. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4656. dayStr2 := "-" + dayStr
  4657. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4658. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4659. fmt.Println("oldTime--------------------------", oldTime)
  4660. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4661. for _, ad := range advices {
  4662. advice_three = append(advice_three, ad)
  4663. }
  4664. }
  4665. if err == nil {
  4666. c.ServeSuccessJSON(map[string]interface{}{
  4667. "status": "2",
  4668. "advices": advices,
  4669. "advices_two": RemoveRepeatedElement(advice_three),
  4670. "is_open_remind": config.IsOpenRemind,
  4671. })
  4672. }
  4673. }
  4674. }
  4675. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4676. newArr = make([]*models.DoctorAdvice, 0)
  4677. for i := 0; i < len(arr); i++ {
  4678. repeat := false
  4679. for j := i + 1; j < len(arr); j++ {
  4680. if arr[i].ID == arr[j].ID {
  4681. repeat = true
  4682. break
  4683. }
  4684. }
  4685. if !repeat {
  4686. newArr = append(newArr, arr[i])
  4687. }
  4688. }
  4689. return
  4690. }
  4691. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4692. patient, _ := c.GetInt64("id", 0)
  4693. groupNo, _ := c.GetInt64("groupno", 0)
  4694. if patient <= 0 {
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. return
  4697. }
  4698. adminUserInfo := c.GetAdminUserInfo()
  4699. dataBody := make(map[string]interface{}, 0)
  4700. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4701. if err != nil {
  4702. utils.ErrorLog(err.Error())
  4703. return
  4704. }
  4705. utils.ErrorLog("%v", dataBody)
  4706. timeLayout := "2006-01-02 15:04"
  4707. loc, _ := time.LoadLocation("Local")
  4708. timeLayout2 := "2006-01-02"
  4709. loc2, _ := time.LoadLocation("Local")
  4710. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4711. utils.ErrorLog("advice_type")
  4712. return
  4713. }
  4714. adviceType := int64(2)
  4715. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4716. utils.ErrorLog("advice_date")
  4717. return
  4718. }
  4719. adviceDate, _ := dataBody["advice_date"].(string)
  4720. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4721. AdviceDate := theTime.Unix()
  4722. RecordDate := theTime.Unix()
  4723. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4724. utils.ErrorLog("start_time")
  4725. return
  4726. }
  4727. startTime, _ := dataBody["start_time"].(string)
  4728. if len(startTime) == 0 {
  4729. utils.ErrorLog("len(start_time) == 0")
  4730. return
  4731. }
  4732. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4733. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4734. //if err != nil {
  4735. // utils.ErrorLog(err.Error())
  4736. // return
  4737. //}
  4738. StartTime := theTimeUnix.Unix()
  4739. fmt.Println("startTIME", StartTime)
  4740. Remark := ""
  4741. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4742. remark, _ := dataBody["remark"].(string)
  4743. Remark = remark
  4744. }
  4745. var advices []*models.GroupAdvice
  4746. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4747. utils.ErrorLog("advices")
  4748. return
  4749. }
  4750. adviceNames := dataBody["advices"].([]interface{})
  4751. for _, adviceNameMap := range adviceNames {
  4752. adviceNameM := adviceNameMap.(map[string]interface{})
  4753. var advice models.GroupAdvice
  4754. advice.Remark = Remark
  4755. advice.AdviceType = adviceType
  4756. advice.StartTime = StartTime
  4757. if advice.StartTime < 0 {
  4758. advice.StartTime = time.Now().Unix()
  4759. }
  4760. advice.AdviceDate = AdviceDate
  4761. advice.RecordDate = RecordDate
  4762. advice.Status = 1
  4763. advice.CreatedTime = time.Now().Unix()
  4764. advice.UpdatedTime = time.Now().Unix()
  4765. advice.StopState = 2
  4766. advice.ExecutionState = 2
  4767. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4768. advice.PatientId = patient
  4769. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4770. advice.IsSettle = 2
  4771. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4772. utils.ErrorLog("advice_name")
  4773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4774. return
  4775. }
  4776. adviceName, _ := adviceNameM["advice_name"].(string)
  4777. if len(adviceName) == 0 {
  4778. utils.ErrorLog("len(advice_name) == 0")
  4779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4780. return
  4781. }
  4782. advice.AdviceName = adviceName
  4783. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4784. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4785. advice.DrugSpec = drugSpec
  4786. }
  4787. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4788. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4789. advice.AdviceDesc = adviceDesc
  4790. }
  4791. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4792. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4793. advice.DrugSpecUnit = drugSpecUnit
  4794. }
  4795. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4796. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4797. // advice.SingleDose = singleDose
  4798. //}
  4799. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4800. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4801. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4802. }
  4803. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4804. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4805. advice.SingleDoseUnit = singleDoseUnit
  4806. }
  4807. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4808. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4809. // advice.PrescribingNumber = prescribingNumber
  4810. //}
  4811. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4812. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4813. }
  4814. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4815. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4816. advice.PrescribingNumberUnit = prescribingNumberUnit
  4817. }
  4818. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4819. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4820. advice.DeliveryWay = deliveryWay
  4821. }
  4822. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4823. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4824. advice.ExecutionFrequency = executionFrequency
  4825. }
  4826. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4827. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4828. advice.FrequencyType = frequency_type
  4829. }
  4830. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4831. day_count := int64(adviceNameM["day_count"].(float64))
  4832. advice.DayCount = day_count
  4833. }
  4834. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4835. way := int64(adviceNameM["way"].(float64))
  4836. advice.Way = way
  4837. }
  4838. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4839. drug_id := int64(adviceNameM["drug_id"].(float64))
  4840. advice.DrugId = drug_id
  4841. }
  4842. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4843. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4844. advice.DrugNameId = drug_name_id
  4845. }
  4846. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4847. week_day, _ := adviceNameM["week_day"].(string)
  4848. advice.WeekDay = week_day
  4849. }
  4850. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4851. template_id, _ := adviceNameM["template_id"].(string)
  4852. advice.TemplateId = template_id
  4853. }
  4854. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4855. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4856. advice.ExecutionFrequency = executionFrequency
  4857. }
  4858. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4859. children := adviceNameM["child"].([]interface{})
  4860. if len(children) > 0 {
  4861. for _, childrenMap := range children {
  4862. childMap := childrenMap.(map[string]interface{})
  4863. var child models.GroupAdvice
  4864. child.Remark = Remark
  4865. child.AdviceType = adviceType
  4866. child.StartTime = StartTime
  4867. if child.StartTime < 0 {
  4868. child.StartTime = time.Now().Unix()
  4869. }
  4870. child.AdviceDate = AdviceDate
  4871. child.RecordDate = RecordDate
  4872. child.Status = 1
  4873. child.CreatedTime = time.Now().Unix()
  4874. child.UpdatedTime = time.Now().Unix()
  4875. child.StopState = 2
  4876. child.ExecutionState = 2
  4877. child.UserOrgId = adminUserInfo.CurrentOrgId
  4878. child.PatientId = patient
  4879. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4880. child.IsSettle = 2
  4881. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4882. utils.ErrorLog("child advice_name")
  4883. return
  4884. }
  4885. childAdviceName, _ := childMap["advice_name"].(string)
  4886. if len(childAdviceName) == 0 {
  4887. utils.ErrorLog("len(child advice_name) == 0")
  4888. return
  4889. }
  4890. child.AdviceName = childAdviceName
  4891. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4892. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4893. child.AdviceDesc = childAdviceDesc
  4894. }
  4895. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4896. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4897. child.DrugSpec = childDrugSpec
  4898. }
  4899. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4900. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4901. child.DrugSpecUnit = childDrugSpecUnit
  4902. }
  4903. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4904. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4905. child.SingleDose = childSingleDose
  4906. }
  4907. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4908. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4909. child.SingleDose = childMap["single_dose"].(float64)
  4910. }
  4911. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4912. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4913. child.Remark = childMap["remark"].(string)
  4914. }
  4915. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4916. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4917. child.DrugId = int64(childMap["drug_id"].(float64))
  4918. }
  4919. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4920. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4921. child.SingleDoseUnit = childSingleDoseUnit
  4922. }
  4923. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4924. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4925. child.PrescribingNumber = childPrescribingNumber
  4926. }
  4927. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4928. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4929. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4930. }
  4931. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4932. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4933. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4934. }
  4935. child.DeliveryWay = advice.DeliveryWay
  4936. child.ExecutionFrequency = advice.ExecutionFrequency
  4937. advice.Children = append(advice.Children, &child)
  4938. }
  4939. }
  4940. }
  4941. advices = append(advices, &advice)
  4942. }
  4943. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4944. for _, item := range advices {
  4945. //记录日志
  4946. byterequest, _ := json.Marshal(item)
  4947. adviceLog := models.XtDoctorAdviceLog{
  4948. UserOrgId: item.UserOrgId,
  4949. PatientId: item.PatientId,
  4950. AdminUserId: adminUserInfo.AdminUser.Id,
  4951. Module: 1,
  4952. ErrLog: string(byterequest),
  4953. Status: 1,
  4954. Ctime: time.Now().Unix(),
  4955. Mtime: 0,
  4956. Source: "电脑端医嘱推送",
  4957. RecordDate: item.AdviceDate,
  4958. }
  4959. service.CreateDoctorAdviceLog(adviceLog)
  4960. }
  4961. //创建步骤表
  4962. finish := models.XtDialysisFinish{
  4963. IsFinish: 1,
  4964. UserOrgId: adminUserInfo.CurrentOrgId,
  4965. Status: 1,
  4966. Ctime: time.Now().Unix(),
  4967. Mtime: 0,
  4968. Module: 4,
  4969. RecordDate: AdviceDate,
  4970. Sourse: 1,
  4971. PatientId: patient,
  4972. }
  4973. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4974. if dialysisFinish.ID == 0 {
  4975. service.CreateDialysisFinish(finish)
  4976. }
  4977. redis := service.RedisClient()
  4978. formatAdviceDate := theTime.Format("2006-01-02")
  4979. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4980. redis.Set(key, "", time.Second)
  4981. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4982. redis.Set(keyOne, "", time.Second)
  4983. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4984. redis.Set(keyFour, "", time.Second)
  4985. defer redis.Close()
  4986. if err != nil {
  4987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4988. return
  4989. }
  4990. c.ServeSuccessJSON(map[string]interface{}{
  4991. "msg": "ok",
  4992. "advices": list,
  4993. })
  4994. return
  4995. }
  4996. func (c *DialysisApiController) GetSolution() {
  4997. patient_id, _ := c.GetInt64("patient_id")
  4998. mode_id, _ := c.GetInt64("mode_id")
  4999. adminUserInfo := c.GetAdminUserInfo()
  5000. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5001. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5002. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  5003. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  5004. if err != nil {
  5005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5006. return
  5007. }
  5008. c.ServeSuccessJSON(map[string]interface{}{
  5009. "solution": solution,
  5010. "prescription": prescription,
  5011. "system_prescription": system_prescription,
  5012. "dialysisPrescription": dialysisPrescription,
  5013. })
  5014. }
  5015. func (c *DialysisApiController) GetSchedule() {
  5016. schedual_type, _ := c.GetInt64("schedual_type")
  5017. adminUserInfo := c.GetAdminUserInfo()
  5018. //timeLayout := "2006-01-02 15:04:05"
  5019. //
  5020. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  5021. //loc, _ := time.LoadLocation("Local")
  5022. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5023. //scheduleTime := theStartTime.Unix()
  5024. scheduleTime, _ := c.GetInt64("record_date")
  5025. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  5026. c.ServeSuccessJSON(map[string]interface{}{
  5027. "number": deviceNumber,
  5028. })
  5029. }
  5030. func (this *DialysisApiController) GetTodayMonitor() {
  5031. thisTime := time.Now()
  5032. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5033. timeLayout := "2006-01-02 15:04:05"
  5034. loc, _ := time.LoadLocation("Local")
  5035. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5036. theAssessmentDateTime := theStartTime.Unix()
  5037. patientID, _ := this.GetInt64("patient_id")
  5038. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5039. adminInfo := this.GetAdminUserInfo()
  5040. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5041. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5042. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  5043. var ultrafiltration_rate float64
  5044. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5045. //针对福建医师汇 获取透前评估预增脱水量
  5046. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5047. fmt.Println("透前评估数据", evaluation)
  5048. if prescription.ID > 0 {
  5049. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5050. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5051. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  5052. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5053. record.UltrafiltrationRate = ultrafiltration_rate
  5054. }
  5055. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  5056. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5057. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5058. record.UltrafiltrationRate = ultrafiltration_rate
  5059. }
  5060. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  5061. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5062. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5063. record.UltrafiltrationRate = ultrafiltration_rate
  5064. }
  5065. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  5066. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5067. record.UltrafiltrationRate = ultrafiltration_rate
  5068. }
  5069. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  5070. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5071. record.UltrafiltrationRate = ultrafiltration_rate
  5072. }
  5073. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  5074. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5075. record.UltrafiltrationRate = ultrafiltration_rate
  5076. }
  5077. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  5078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5079. record.UltrafiltrationRate = ultrafiltration_rate
  5080. }
  5081. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  5082. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5083. record.UltrafiltrationRate = ultrafiltration_rate
  5084. }
  5085. // 只针对方济医院
  5086. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5087. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5088. ultrafiltration_rate = value
  5089. record.UltrafiltrationRate = ultrafiltration_rate
  5090. }
  5091. //长沙南雅
  5092. 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 {
  5093. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  5094. record.UltrafiltrationRate = ultrafiltration_rate
  5095. }
  5096. if adminInfo.CurrentOrgId == 10694 || adminInfo.CurrentOrgId == 10697 {
  5097. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5098. ultrafiltration_rate = ultrafiltration_rate
  5099. }
  5100. }
  5101. }
  5102. // record.UltrafiltrationRate = ultrafiltration_rate
  5103. record.UltrafiltrationVolume = 0
  5104. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5105. if ultrafiltration_rate > 0 {
  5106. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5107. record.UltrafiltrationVolume = value
  5108. }
  5109. }
  5110. 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 {
  5111. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  5112. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5113. record.UltrafiltrationVolume = ultrafiltration_volume
  5114. }
  5115. }
  5116. //长沙南雅
  5117. 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 {
  5118. if ultrafiltration_rate > 0 {
  5119. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5120. record.UltrafiltrationVolume = ultrafiltration_volume
  5121. }
  5122. }
  5123. if template.TemplateId == 47 || template.TemplateId == 54 {
  5124. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5125. }
  5126. if adminInfo.CurrentOrgId == 10697 || adminInfo.CurrentOrgId == 10694 {
  5127. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate * 1000)
  5128. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5129. }
  5130. this.ServeSuccessJSON(map[string]interface{}{
  5131. "monitor": record,
  5132. })
  5133. }
  5134. func (c *DialysisApiController) UploadDryWeight() {
  5135. patient_id, _ := c.GetInt64("id")
  5136. dry_weight, _ := c.GetFloat("dry_weight")
  5137. doctor_id, _ := c.GetInt64("doctor_id")
  5138. remark := c.GetString("remark")
  5139. adminUserInfo := c.GetAdminUserInfo()
  5140. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  5141. fmt.Println(err)
  5142. if err == gorm.ErrRecordNotFound {
  5143. dryWeight := &models.SgjPatientDryweight{
  5144. PatientId: patient_id,
  5145. DryWeight: dry_weight,
  5146. Remakes: remark,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: time.Now().Unix(),
  5149. Creator: doctor_id,
  5150. Status: 1,
  5151. UserOrgId: adminUserInfo.CurrentOrgId,
  5152. AdjustedValue: "/",
  5153. UserId: adminUserInfo.AdminUser.Id,
  5154. }
  5155. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5156. loc, _ := time.LoadLocation("Local")
  5157. nowTime := time.Now()
  5158. nowDay := nowTime.Format("2006-01-02")
  5159. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5160. redis := service.RedisClient()
  5161. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5162. redis.Set(keyOne, "", time.Second)
  5163. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5164. redis.Set(key, "", time.Second)
  5165. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5166. redis.Set(keyTwo, "", time.Second)
  5167. redis.Close()
  5168. if createErr == nil {
  5169. c.ServeSuccessJSON(map[string]interface{}{
  5170. "msg": "提交成功",
  5171. "weight": dryWeight,
  5172. })
  5173. }
  5174. } else {
  5175. dryWeight := &models.SgjPatientDryweight{
  5176. PatientId: patient_id,
  5177. DryWeight: dry_weight,
  5178. Remakes: remark,
  5179. Ctime: time.Now().Unix(),
  5180. Mtime: time.Now().Unix(),
  5181. Creator: doctor_id,
  5182. Status: 1,
  5183. UserOrgId: adminUserInfo.CurrentOrgId,
  5184. AdjustedValue: "/",
  5185. UserId: adminUserInfo.AdminUser.Id,
  5186. }
  5187. var value float64
  5188. value = dry_weight - weightAdjust.DryWeight
  5189. fmt.Println(value)
  5190. if value < 0 {
  5191. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5192. } else if value == 0 {
  5193. dryWeight.AdjustedValue = "/"
  5194. } else if value > 0 {
  5195. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5196. }
  5197. fmt.Println(value)
  5198. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5199. //康桥
  5200. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10721 {
  5201. timeNowStr := time.Now().Format("2006-01-02")
  5202. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5203. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5204. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5205. if beforAssesment.ID > 0 {
  5206. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5207. var dewater_amount float64
  5208. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5209. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5210. //获取key,清空redis
  5211. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5212. redis := service.RedisClient()
  5213. //清空key 值
  5214. redis.Set(key, "", time.Second)
  5215. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  5216. //清空key 值
  5217. redis.Set(keyOne, "", time.Second)
  5218. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5219. //清空key 值
  5220. redis.Set(keyTwo, "", time.Second)
  5221. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5222. redis.Set(keySix, "", time.Second)
  5223. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5224. redis.Set(keySeven, "", time.Second)
  5225. }
  5226. }
  5227. loc, _ := time.LoadLocation("Local")
  5228. nowTime := time.Now()
  5229. nowDay := nowTime.Format("2006-01-02")
  5230. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5231. redis := service.RedisClient()
  5232. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5233. redis.Set(keyOne, "", time.Second)
  5234. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5235. redis.Set(key, "", time.Second)
  5236. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5237. redis.Set(keyTwo, "", time.Second)
  5238. redis.Close()
  5239. if createErr == nil {
  5240. c.ServeSuccessJSON(map[string]interface{}{
  5241. "msg": "提交成功",
  5242. "weight": dryWeight,
  5243. })
  5244. }
  5245. }
  5246. }
  5247. func (this *DialysisApiController) GetFuncPurview() {
  5248. adminUserInfo := this.GetAdminUserInfo()
  5249. user_id := adminUserInfo.AdminUser.Id
  5250. app_id := adminUserInfo.CurrentAppId
  5251. org_id := adminUserInfo.CurrentOrgId
  5252. create_url := this.GetString("create_url")
  5253. modify_url := this.GetString("modify_url")
  5254. modify_other_url := this.GetString("modify_other_url")
  5255. del_url := this.GetString("del_url")
  5256. del_other_url := this.GetString("del_other_url")
  5257. exce_url := this.GetString("exce_url")
  5258. check_url := this.GetString("check_url")
  5259. modify_exce_url := this.GetString("modify_exce_url")
  5260. module, _ := this.GetInt64("module", 0)
  5261. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  5262. var is_has_create bool
  5263. var is_has_modify bool
  5264. var is_has_modify_other bool
  5265. var is_has_del bool
  5266. var is_has_del_other bool
  5267. var is_has_exce bool
  5268. var is_has_check bool
  5269. var is_has_modify_exce bool
  5270. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  5271. if adminUserInfo.AdminUser.Id != org.Creator {
  5272. if app_role != nil {
  5273. if len(app_role.RoleIds) > 0 {
  5274. roles := strings.Split(app_role.RoleIds, ",")
  5275. var userRolePurviews string
  5276. for _, item := range roles {
  5277. role_id, _ := strconv.ParseInt(item, 10, 64)
  5278. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  5279. if len(userRolePurviews) == 0 {
  5280. userRolePurviews = purviews
  5281. } else {
  5282. userRolePurviews = userRolePurviews + "," + purviews
  5283. }
  5284. }
  5285. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  5286. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  5287. for _, item := range funcPurviews {
  5288. //for _, url := range strings.Split(item.Urlfor,","){
  5289. if strings.Split(item.Urlfor, ",")[1] == create_url {
  5290. is_has_create = true
  5291. }
  5292. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  5293. is_has_modify = true
  5294. }
  5295. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  5296. is_has_modify_other = true
  5297. }
  5298. if strings.Split(item.Urlfor, ",")[1] == del_url {
  5299. is_has_del = true
  5300. }
  5301. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  5302. is_has_del_other = true
  5303. }
  5304. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  5305. is_has_exce = true
  5306. }
  5307. if strings.Split(item.Urlfor, ",")[1] == check_url {
  5308. is_has_check = true
  5309. }
  5310. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  5311. is_has_modify_exce = true
  5312. }
  5313. }
  5314. } else {
  5315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  5316. return
  5317. }
  5318. this.ServeSuccessJSON(map[string]interface{}{
  5319. "is_has_create": is_has_create,
  5320. "is_has_modify": is_has_modify,
  5321. "is_has_modify_other": is_has_modify_other,
  5322. "is_has_del": is_has_del,
  5323. "is_has_del_other": is_has_del_other,
  5324. "is_has_exce": is_has_exce,
  5325. "is_has_check": is_has_check,
  5326. "is_has_modify_exce": is_has_modify_exce,
  5327. "module": module,
  5328. })
  5329. } else {
  5330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  5331. return
  5332. }
  5333. } else {
  5334. this.ServeSuccessJSON(map[string]interface{}{
  5335. "is_has_create": true,
  5336. "is_has_modify": true,
  5337. "is_has_modify_other": true,
  5338. "is_has_del": true,
  5339. "is_has_del_other": true,
  5340. "is_has_exce": true,
  5341. "is_has_check": true,
  5342. "is_has_modify_exce": true,
  5343. "module": true,
  5344. })
  5345. }
  5346. }
  5347. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  5348. patient_id, _ := this.GetInt64("patient_id", 0)
  5349. advice_date, _ := this.GetInt64("advice_date")
  5350. adminUserInfo := this.GetAdminUserInfo()
  5351. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5352. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5353. this.ServeSuccessJSON(map[string]interface{}{
  5354. "doctorAdvice": doctorAdvice,
  5355. "hisDoctorAdvice": hisDoctorAdvice,
  5356. })
  5357. }
  5358. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  5359. change_type, _ := this.GetInt64("type", 0)
  5360. record_date := this.GetString("record_time")
  5361. patient_id, _ := this.GetInt64("patient_id", 0)
  5362. timeLayout := "2006-01-02"
  5363. loc, _ := time.LoadLocation("Local")
  5364. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5365. record_time := theAdviceRecordTime.Unix()
  5366. adminUserInfo := this.GetAdminUserInfo()
  5367. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  5368. if err == nil {
  5369. if len(advices) == 0 {
  5370. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5371. return
  5372. } else {
  5373. this.ServeSuccessJSON(map[string]interface{}{
  5374. "advices": advices,
  5375. "schedule": sch,
  5376. })
  5377. return
  5378. }
  5379. } else {
  5380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5381. return
  5382. }
  5383. }
  5384. func (c *DialysisApiController) GetDialysisGoods() {
  5385. schedualDate := c.GetString("schedule_date")
  5386. schedule_type, _ := c.GetInt64("schedule_type")
  5387. partition_id, _ := c.GetInt64("partition_id")
  5388. page, _ := c.GetInt("page")
  5389. limit, _ := c.GetInt("limit")
  5390. keywords := c.GetString("keywords")
  5391. patient_id, _ := c.GetInt64("patient_id")
  5392. good_type, _ := c.GetInt64("good_type")
  5393. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5394. if parseDateErr != nil && len(schedualDate) != 0 {
  5395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5396. return
  5397. }
  5398. schedualEndDate := int64(0)
  5399. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5400. if parseDateErr != nil && len(schedualDate) != 0 {
  5401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5402. return
  5403. }
  5404. schedualEndDate = endDate.Unix()
  5405. adminUser := c.GetAdminUserInfo()
  5406. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  5407. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  5408. if err == gorm.ErrRecordNotFound {
  5409. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5410. var ids []int64
  5411. for _, item := range list {
  5412. ids = append(ids, item.PatientId)
  5413. }
  5414. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5415. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5416. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5417. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5418. item.LastAutomaticReduceDetail = goodUser
  5419. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5420. }
  5421. c.ServeSuccessJSON(map[string]interface{}{
  5422. "dialysis_goods": dialysisGoods,
  5423. "good_type": goodTypes,
  5424. "total": total,
  5425. })
  5426. return
  5427. } else if err == nil {
  5428. //获取当天排班的每个患者的库存使用情况
  5429. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5430. var ids []int64
  5431. for _, item := range list {
  5432. ids = append(ids, item.PatientId)
  5433. }
  5434. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5435. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5436. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5437. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5438. fmt.Println(goodUser)
  5439. fmt.Println(lastGoodUserDetial)
  5440. item.LastAutomaticReduceDetail = goodUser
  5441. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5442. }
  5443. if err == nil {
  5444. c.ServeSuccessJSON(map[string]interface{}{
  5445. "dialysis_goods": dialysisGoods,
  5446. "good_type": goodTypes,
  5447. "total": total,
  5448. })
  5449. return
  5450. } else {
  5451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5452. return
  5453. }
  5454. } else if err != nil {
  5455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5456. return
  5457. }
  5458. }
  5459. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  5460. start_time := c.GetString("start_time")
  5461. end_time := c.GetString("end_time")
  5462. timeLayout := "2006-01-02"
  5463. loc, _ := time.LoadLocation("Local")
  5464. var theStartTime int64
  5465. if len(start_time) > 0 {
  5466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5467. if err != nil {
  5468. utils.ErrorLog(err.Error())
  5469. }
  5470. theStartTime = theTime.Unix()
  5471. }
  5472. var theEndtTime int64
  5473. if len(end_time) > 0 {
  5474. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5475. if err != nil {
  5476. utils.ErrorLog(err.Error())
  5477. }
  5478. theEndtTime = theTime.Unix()
  5479. }
  5480. adminUser := c.GetAdminUserInfo()
  5481. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  5482. if err == nil {
  5483. c.ServeSuccessJSON(map[string]interface{}{
  5484. "stock_out": outInfo,
  5485. })
  5486. return
  5487. } else {
  5488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5489. return
  5490. }
  5491. }
  5492. func (c *DialysisApiController) GetRoleList() {
  5493. orgId := c.GetAdminUserInfo().CurrentOrgId
  5494. admin_user_id, _ := c.GetInt64("admin_user_id")
  5495. list, err := service.GetRoleList(orgId, admin_user_id)
  5496. if err == nil {
  5497. c.ServeSuccessJSON(map[string]interface{}{
  5498. "adminRole": list,
  5499. })
  5500. return
  5501. } else {
  5502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5503. return
  5504. }
  5505. }
  5506. func (c *DialysisApiController) GetInitPrintData() {
  5507. patient_id, _ := c.GetInt64("patient_id")
  5508. record_date, _ := c.GetInt64("record_date")
  5509. orgId := c.GetAdminUserInfo().CurrentOrgId
  5510. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  5511. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5512. if err == nil {
  5513. c.ServeSuccessJSON(map[string]interface{}{
  5514. "list": list,
  5515. "assessmentAfterDislysis": assessmentAfterDislysis,
  5516. })
  5517. return
  5518. } else {
  5519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5520. return
  5521. }
  5522. }
  5523. func (c *DialysisApiController) GetInitPrintDataOne() {
  5524. patient_id, _ := c.GetInt64("patient_id")
  5525. start_time := c.GetString("record_date")
  5526. timeLayout := "2006-01-02"
  5527. loc, _ := time.LoadLocation("Local")
  5528. var theStartTime int64
  5529. if len(start_time) > 0 {
  5530. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5531. if err != nil {
  5532. utils.ErrorLog(err.Error())
  5533. }
  5534. theStartTime = theTime.Unix()
  5535. }
  5536. orgId := c.GetAdminUserInfo().CurrentOrgId
  5537. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  5538. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5539. if err == nil {
  5540. c.ServeSuccessJSON(map[string]interface{}{
  5541. "list": list,
  5542. "assessmentAfterDislysis": assessmentAfterDislysis,
  5543. })
  5544. return
  5545. } else {
  5546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5547. return
  5548. }
  5549. }
  5550. // 新接口
  5551. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5552. keyword := this.GetString("keywords")
  5553. limit, _ := this.GetInt64("limit")
  5554. page, _ := this.GetInt64("page")
  5555. partition_id, _ := this.GetInt64("partition_id")
  5556. schedule_type, _ := this.GetInt64("schedule_type")
  5557. start_time := this.GetString("schedule_date")
  5558. advice_ids := this.GetString("ids")
  5559. var ids []string
  5560. if advice_ids != "" {
  5561. ids = strings.Split(advice_ids, ",")
  5562. }
  5563. timeLayout := "2006-01-02"
  5564. loc, _ := time.LoadLocation("Local")
  5565. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5566. orgId := this.GetAdminUserInfo().CurrentOrgId
  5567. _, config := service.FindXTHisRecordByOrgId(orgId)
  5568. goodType, _ := service.GetAllGoodType(orgId)
  5569. if config.IsOpen != 1 {
  5570. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5571. if err == nil {
  5572. this.ServeSuccessJSON(map[string]interface{}{
  5573. "list": list,
  5574. "total": total,
  5575. "config": config,
  5576. "goodType": goodType,
  5577. })
  5578. return
  5579. } else {
  5580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5581. return
  5582. }
  5583. }
  5584. if config.IsOpen == 1 {
  5585. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5586. if err == nil {
  5587. this.ServeSuccessJSON(map[string]interface{}{
  5588. "list": list,
  5589. "total": total,
  5590. "config": config,
  5591. "goodType": goodType,
  5592. })
  5593. return
  5594. }
  5595. }
  5596. }
  5597. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5598. keyword := this.GetString("keywords")
  5599. limit, _ := this.GetInt64("limit")
  5600. page, _ := this.GetInt64("page")
  5601. partition_id, _ := this.GetInt64("partition_id")
  5602. schedule_type, _ := this.GetInt64("schedule_type")
  5603. start_time := this.GetString("schedule_date")
  5604. ids := this.GetString("ids")
  5605. var idArray []string
  5606. if ids != "" {
  5607. idArray = strings.Split(ids, ",")
  5608. }
  5609. timeLayout := "2006-01-02"
  5610. loc, _ := time.LoadLocation("Local")
  5611. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5612. orgId := this.GetAdminUserInfo().CurrentOrgId
  5613. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5614. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5615. //获取长期医嘱
  5616. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5617. _, config := service.FindXTHisRecordByOrgId(orgId)
  5618. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5619. if err == nil {
  5620. this.ServeSuccessJSON(map[string]interface{}{
  5621. "list": list,
  5622. "total": total,
  5623. "adviceList": adviceList,
  5624. "config": config,
  5625. "drugList": drugList,
  5626. "tablelist": tablelist,
  5627. })
  5628. return
  5629. } else {
  5630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5631. return
  5632. }
  5633. }
  5634. func (this *DialysisApiController) SaveDialysisSetting() {
  5635. orgId := this.GetAdminUserInfo().CurrentOrgId
  5636. device_number_set, _ := this.GetInt64("device_number_set")
  5637. device_type_set, _ := this.GetInt64("device_type_set")
  5638. name_set, _ := this.GetInt64("name_set")
  5639. admission_number_set, _ := this.GetInt64("admission_number_set")
  5640. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5641. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5642. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5643. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5644. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5645. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5646. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5647. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5648. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5649. mode_id_set, _ := this.GetInt64("mode_id_set")
  5650. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5651. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5652. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5653. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5654. kalium_set, _ := this.GetInt64("kalium_set")
  5655. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5656. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5657. glucose_set, _ := this.GetInt64("glucose_set")
  5658. sodium_set, _ := this.GetInt64("sodium_set")
  5659. calcium_set, _ := this.GetInt64("calcium_set")
  5660. blood_access_set, _ := this.GetInt64("blood_access_set")
  5661. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5662. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5663. cuhong_set, _ := this.GetInt64("cuhong_set")
  5664. zuoka_set, _ := this.GetInt64("zuoka_set")
  5665. difenzi_set, _ := this.GetInt64("difenzi_set")
  5666. gansuna_set, _ := this.GetInt64("gansuna_set")
  5667. zhetangtie_set, _ := this.GetInt64("zhetangtie_set")
  5668. niaojimei_set, _ := this.GetInt64("niaojimei_set")
  5669. dialysis_strainer_set, _ := this.GetInt64("dialysis_strainer_set")
  5670. dialysisSetting := models.XtDialysisSetting{
  5671. Sodium: sodium_set,
  5672. Calcium: calcium_set,
  5673. BloodAccess: blood_access_set,
  5674. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5675. DisplaceLiquiPart: displace_liqui_part_set,
  5676. UserOrgId: orgId,
  5677. Status: 1,
  5678. DeviceNumber: device_number_set,
  5679. DeviceType: device_type_set,
  5680. Name: name_set,
  5681. AdmissionNumber: admission_number_set,
  5682. DialysisNo: dialysis_no_set,
  5683. WeightBefor: weight_befor_set,
  5684. DryWeight: dry_weight_set,
  5685. BloodPressure: blood_pressure_set,
  5686. UltrafiltrationVolume: ultrafiltration_volume_set,
  5687. InternalFistula: internal_fistula_set,
  5688. BloodFlowVolume: blood_flow_volume_set,
  5689. Anticoagulant: anticoagulant_set,
  5690. SealingFluidDispose: sealing_fluid_dispose_set,
  5691. ModeId: mode_id_set,
  5692. DialysisTime: dialysis_time_set,
  5693. DialysisDialyszers: dialysis_dialyszers_set,
  5694. DialysisIrrigation: dialysis_irrigation_set,
  5695. Gaijiliang: gaijiliang_set,
  5696. Kalium: kalium_set,
  5697. DisplaceLiquiValue: displace_liqui_value_set,
  5698. Bicarbonate: bicarbonate_set,
  5699. Glucose: glucose_set,
  5700. Ctime: time.Now().Unix(),
  5701. Mtime: time.Now().Unix(),
  5702. CuhongSet: cuhong_set,
  5703. ZuokaSet: zuoka_set,
  5704. DifenziSet: difenzi_set,
  5705. GansunaSet: gansuna_set,
  5706. ZhetangtieSet: zhetangtie_set,
  5707. NiaojimeiSet: niaojimei_set,
  5708. DialysisStrainerSet: dialysis_strainer_set,
  5709. }
  5710. err := service.SaveDialysisSetting(dialysisSetting)
  5711. if err == nil {
  5712. this.ServeSuccessJSON(map[string]interface{}{
  5713. "dialysisSetting": dialysisSetting,
  5714. })
  5715. return
  5716. } else {
  5717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5718. return
  5719. }
  5720. }
  5721. func (this *DialysisApiController) GetDialysisSetting() {
  5722. orgId := this.GetAdminUserInfo().CurrentOrgId
  5723. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5724. this.ServeSuccessJSON(map[string]interface{}{
  5725. "dialysisSett": dialysisSett,
  5726. })
  5727. return
  5728. }
  5729. func (this *DialysisApiController) GetDialysisParameterList() {
  5730. keyword := this.GetString("keywords")
  5731. limit, _ := this.GetInt64("limit")
  5732. page, _ := this.GetInt64("page")
  5733. //partition_id, _ := this.GetInt64("partition_id")
  5734. partion_type := this.GetString("partition_id")
  5735. idSplit := strings.Split(partion_type, ",")
  5736. schedule_type, _ := this.GetInt64("schedule_type")
  5737. start_time := this.GetString("schedule_date")
  5738. timeLayout := "2006-01-02"
  5739. loc, _ := time.LoadLocation("Local")
  5740. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5741. orgId := this.GetAdminUserInfo().CurrentOrgId
  5742. scheduids := this.GetString("ids")
  5743. var ids []string
  5744. if scheduids != "" {
  5745. ids = strings.Split(scheduids, ",")
  5746. }
  5747. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5748. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5749. if err == nil {
  5750. this.ServeSuccessJSON(map[string]interface{}{
  5751. "list": list,
  5752. "total": total,
  5753. "dialysisSett": dialysisSett,
  5754. })
  5755. return
  5756. } else {
  5757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5758. return
  5759. }
  5760. }
  5761. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5762. orgId := this.GetAdminUserInfo().CurrentOrgId
  5763. schedule_type, _ := this.GetInt64("schedule_type")
  5764. //partion_type, _ := this.GetInt64("partion_type")
  5765. start_time := this.GetString("selected_date")
  5766. partion_type := this.GetString("partion_type")
  5767. var ids []string
  5768. ids = strings.Split(partion_type, ",")
  5769. timeLayout := "2006-01-02"
  5770. loc, _ := time.LoadLocation("Local")
  5771. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5772. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5773. if err == nil {
  5774. this.ServeSuccessJSON(map[string]interface{}{
  5775. "list": list,
  5776. })
  5777. return
  5778. } else {
  5779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5780. return
  5781. }
  5782. }
  5783. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5784. orgId := this.GetAdminUserInfo().CurrentOrgId
  5785. schedule_type, _ := this.GetInt64("schedule_type")
  5786. //partion_type, _ := this.GetInt64("partion_type")
  5787. partion_type := this.GetString("partion_type")
  5788. var ids []string
  5789. ids = strings.Split(partion_type, ",")
  5790. start_time := this.GetString("selected_date")
  5791. timeLayout := "2006-01-02"
  5792. loc, _ := time.LoadLocation("Local")
  5793. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5794. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5795. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5796. //获取长期医嘱
  5797. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5798. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5799. _, config := service.FindXTHisRecordByOrgId(orgId)
  5800. if err == nil {
  5801. this.ServeSuccessJSON(map[string]interface{}{
  5802. "list": list,
  5803. "drug": drug,
  5804. "adviceList": adviceList,
  5805. "config": config,
  5806. "tablelist": tablelist,
  5807. })
  5808. return
  5809. } else {
  5810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5811. return
  5812. }
  5813. }
  5814. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5815. orgId := this.GetAdminUserInfo().CurrentOrgId
  5816. schedule_type, _ := this.GetInt64("schedule_type")
  5817. partion_type, _ := this.GetInt64("partion_type")
  5818. start_time := this.GetString("selected_date")
  5819. timeLayout := "2006-01-02"
  5820. loc, _ := time.LoadLocation("Local")
  5821. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5822. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5823. if err == nil {
  5824. this.ServeSuccessJSON(map[string]interface{}{
  5825. "list": list,
  5826. })
  5827. return
  5828. } else {
  5829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5830. return
  5831. }
  5832. }
  5833. func (this *DialysisApiController) SaveHisDialysis() {
  5834. var ids []string
  5835. advice_ids := this.GetString("ids")
  5836. ids = strings.Split(advice_ids, ",")
  5837. orgId := this.GetAdminUserInfo().CurrentOrgId
  5838. service.SaveHisDialysis(orgId, ids)
  5839. returnData := make(map[string]interface{}, 0)
  5840. returnData["msg"] = "ok"
  5841. this.ServeSuccessJSON(returnData)
  5842. return
  5843. }
  5844. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5845. orgId := this.GetAdminUserInfo().CurrentOrgId
  5846. schedule_type, _ := this.GetInt64("schedule_type")
  5847. //partion_type, _ := this.GetInt64("partion_type")
  5848. partion_type := this.GetString("partion_type")
  5849. var ids []string
  5850. ids = strings.Split(partion_type, ",")
  5851. start_time := this.GetString("selected_date")
  5852. timeLayout := "2006-01-02"
  5853. loc, _ := time.LoadLocation("Local")
  5854. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5855. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5856. this.ServeSuccessJSON(map[string]interface{}{
  5857. "list": list,
  5858. })
  5859. return
  5860. }
  5861. func (this *DialysisApiController) GetPatientSchedule() {
  5862. orgId := this.GetAdminUserInfo().CurrentOrgId
  5863. patient_id, _ := this.GetInt64("patient_id")
  5864. schedule_date, _ := this.GetInt64("schedule_date")
  5865. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5866. this.ServeSuccessJSON(map[string]interface{}{
  5867. "schedulePatient": schedulePatient,
  5868. })
  5869. }
  5870. func (c *DialysisApiController) GetSchedulePrintList() {
  5871. page, _ := c.GetInt64("page", 1)
  5872. limit, _ := c.GetInt64("limit", 10)
  5873. schedulType, _ := c.GetInt64("schedule_type", 0)
  5874. partitionType, _ := c.GetInt64("partition_type", 0)
  5875. keywords := c.GetString("keywords")
  5876. schedule_date := c.GetString("schedule_date")
  5877. timeLayout := "2006-01-02"
  5878. loc, _ := time.LoadLocation("Local")
  5879. var theStartTime int64
  5880. if len(schedule_date) > 0 {
  5881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5882. if err != nil {
  5883. utils.ErrorLog(err.Error())
  5884. }
  5885. theStartTime = theTime.Unix()
  5886. }
  5887. adminUserInfo := c.GetAdminUserInfo()
  5888. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5889. for _, item := range list {
  5890. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5891. item.DialysisOrderTwenty = order
  5892. }
  5893. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5894. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5895. c.ServeSuccessJSON(map[string]interface{}{
  5896. "list": list,
  5897. "total": total,
  5898. "numberList": numberList,
  5899. "listOne": listOne,
  5900. })
  5901. }
  5902. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5903. orgId := this.GetAdminUserInfo().CurrentOrgId
  5904. list, _ := service.GetSolutionListByOrgId(orgId)
  5905. for _, item := range list {
  5906. //获取该模式最新的1条数据
  5907. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5908. //更新状态值
  5909. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5910. }
  5911. this.ServeSuccessJSON(map[string]interface{}{
  5912. "list": list,
  5913. })
  5914. }
  5915. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5916. orgId := this.GetAdminUserInfo().CurrentOrgId
  5917. is_open, _ := this.GetInt64("is_open")
  5918. idsStr := this.GetString("str")
  5919. recordIDStrs := strings.Split(idsStr, ",")
  5920. start_time := this.GetString("advice_date")
  5921. exec_time, _ := this.GetInt64("exec_time")
  5922. timeLayout := "2006-01-02"
  5923. loc, _ := time.LoadLocation("Local")
  5924. var startTime int64
  5925. if len(start_time) > 0 {
  5926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5927. if err != nil {
  5928. //fmt.Println(err)
  5929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5930. return
  5931. }
  5932. startTime = theTime.Unix()
  5933. }
  5934. config, _ := service.GetDrugOpenConfigOne(orgId)
  5935. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5936. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5937. //his医嘱
  5938. if is_open == 1 {
  5939. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5940. //查找未执行医嘱
  5941. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5942. for _, item := range list {
  5943. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5944. this.ServeSuccessJSON(map[string]interface{}{
  5945. "msg": "3",
  5946. })
  5947. return
  5948. }
  5949. }
  5950. for _, item := range groupList {
  5951. for _, it := range list {
  5952. if item.DrugId == it.DrugId {
  5953. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5954. }
  5955. }
  5956. }
  5957. for _, item := range groupList {
  5958. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5959. var sum_out_count int64
  5960. for _, it := range item.ChildDoctorAdvice {
  5961. var prescribing_number int64
  5962. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5963. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5964. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5965. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5966. }
  5967. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5968. prescribing_number = parseIntPrescribingNumber
  5969. }
  5970. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5971. prescribing_number = parseIntPrescribingNumber
  5972. }
  5973. sum_out_count += prescribing_number
  5974. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5975. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5976. //库存不足
  5977. if sum_out_count > drugStockOut.FlushCount {
  5978. this.ServeSuccessJSON(map[string]interface{}{
  5979. "msg": "2",
  5980. "drug": medical,
  5981. })
  5982. return
  5983. }
  5984. }
  5985. }
  5986. creater := this.GetAdminUserInfo().AdminUser.Id
  5987. //执行出库逻辑
  5988. for _, item := range list {
  5989. hisadvice := &models.HisDoctorAdviceInfo{
  5990. ID: item.ID,
  5991. UserOrgId: item.UserOrgId,
  5992. PatientId: item.PatientId,
  5993. AdviceType: item.AdviceType,
  5994. AdviceDate: item.AdviceDate,
  5995. StartTime: item.StartTime,
  5996. AdviceName: item.AdviceName,
  5997. AdviceDesc: item.AdviceDesc,
  5998. ReminderDate: item.ReminderDate,
  5999. SingleDose: item.SingleDose,
  6000. SingleDoseUnit: item.SingleDoseUnit,
  6001. DrugSpec: item.DrugSpec,
  6002. DrugSpecUnit: item.DrugSpecUnit,
  6003. PrescribingNumber: item.PrescribingNumber,
  6004. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6005. DeliveryWay: item.DeliveryWay,
  6006. ExecutionFrequency: item.ExecutionFrequency,
  6007. AdviceDoctor: item.AdviceDoctor,
  6008. Status: 1,
  6009. CreatedTime: item.CreatedTime,
  6010. UpdatedTime: item.UpdatedTime,
  6011. AdviceAffirm: item.AdviceAffirm,
  6012. Remark: item.Remark,
  6013. StopTime: item.StopTime,
  6014. StopReason: item.StopReason,
  6015. StopDoctor: item.StopDoctor,
  6016. StopState: item.StopState,
  6017. ParentId: item.ParentId,
  6018. ExecutionTime: item.ExecutionTime,
  6019. ExecutionStaff: creater,
  6020. ExecutionState: item.ExecutionState,
  6021. Checker: item.Checker,
  6022. RecordDate: item.RecordDate,
  6023. DialysisOrderId: item.DialysisOrderId,
  6024. CheckTime: item.CheckTime,
  6025. CheckState: item.CheckState,
  6026. RemindType: item.RemindType,
  6027. FrequencyType: item.FrequencyType,
  6028. DayCount: item.DayCount,
  6029. WeekDay: item.WeekDay,
  6030. TemplateId: item.TemplateId,
  6031. Modifier: item.Modifier,
  6032. Way: item.Way,
  6033. DrugId: item.DrugId,
  6034. ExecutionFrequencyId: item.ExecutionFrequencyId,
  6035. }
  6036. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6037. if medical.IsUse == 2 {
  6038. if config.IsOpen != 1 {
  6039. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6040. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6041. }
  6042. //不通过药房发药
  6043. if pharmacyConfig.IsOpen != 1 {
  6044. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6045. }
  6046. //查询默认仓库
  6047. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6048. //查询默认仓库剩余多少库存
  6049. var sum_count int64
  6050. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6051. for _, its := range stockInfo {
  6052. if its.MaxUnit == medical.MaxUnit {
  6053. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6054. }
  6055. sum_count += its.StockMaxNumber + its.StockMinNumber
  6056. }
  6057. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6058. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6059. }
  6060. }
  6061. info := models.HisDoctorAdviceInfo{
  6062. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6063. ExecutionTime: exec_time,
  6064. ExecutionState: 1,
  6065. UpdatedTime: time.Now().Unix(),
  6066. }
  6067. //执行医嘱
  6068. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  6069. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6070. redis := service.RedisClient()
  6071. //清空key 值
  6072. redis.Set(key, "", time.Second)
  6073. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6074. redis.Set(keyTwo, "", time.Second)
  6075. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6076. redis.Set(keyThree, "", time.Second)
  6077. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6078. theTime := toTime.Format("2006-01-02")
  6079. fmt.Println("theTIME", theTime)
  6080. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6081. redis.Set(keyFour, "", time.Second)
  6082. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6083. redis.Set(keyFive, "", time.Second)
  6084. }
  6085. } else {
  6086. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  6087. //查找未执行医嘱
  6088. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  6089. for _, item := range groupList {
  6090. for _, it := range list {
  6091. if item.DrugId == it.DrugId {
  6092. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6093. }
  6094. }
  6095. }
  6096. for _, item := range groupList {
  6097. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6098. var sum_out_count int64
  6099. for _, it := range item.ChildDoctorAdvice {
  6100. var prescribing_number int64
  6101. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  6102. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6103. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6104. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6105. }
  6106. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6107. prescribing_number = parseIntPrescribingNumber
  6108. }
  6109. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6110. prescribing_number = parseIntPrescribingNumber
  6111. }
  6112. sum_out_count += prescribing_number
  6113. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6114. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6115. //库存不足
  6116. if sum_out_count > drugStockOut.FlushCount {
  6117. this.ServeSuccessJSON(map[string]interface{}{
  6118. "msg": "2",
  6119. "drug": medical,
  6120. })
  6121. return
  6122. }
  6123. }
  6124. }
  6125. for _, item := range list {
  6126. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6127. dadvice := &models.DoctorAdvice{
  6128. ID: item.ID,
  6129. UserOrgId: item.UserOrgId,
  6130. PatientId: item.PatientId,
  6131. AdviceType: item.AdviceType,
  6132. AdviceDate: item.AdviceDate,
  6133. StartTime: item.StartTime,
  6134. AdviceName: item.AdviceName,
  6135. AdviceDesc: item.AdviceDesc,
  6136. ReminderDate: item.ReminderDate,
  6137. SingleDose: item.SingleDose,
  6138. SingleDoseUnit: item.SingleDoseUnit,
  6139. DrugSpec: item.DrugSpec,
  6140. DrugSpecUnit: item.DrugSpecUnit,
  6141. PrescribingNumber: item.PrescribingNumber,
  6142. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6143. DeliveryWay: item.DeliveryWay,
  6144. ExecutionFrequency: item.ExecutionFrequency,
  6145. AdviceDoctor: item.AdviceDoctor,
  6146. Status: 1,
  6147. CreatedTime: item.CreatedTime,
  6148. UpdatedTime: item.UpdatedTime,
  6149. AdviceAffirm: item.AdviceAffirm,
  6150. Remark: item.Remark,
  6151. StopTime: item.StopTime,
  6152. StopReason: item.StopReason,
  6153. StopDoctor: item.StopDoctor,
  6154. StopState: item.StopState,
  6155. ParentId: item.ParentId,
  6156. ExecutionTime: item.ExecutionTime,
  6157. ExecutionStaff: item.ExecutionStaff,
  6158. ExecutionState: item.ExecutionState,
  6159. Checker: item.Checker,
  6160. RecordDate: item.ReminderDate,
  6161. DialysisOrderId: item.DialysisOrderId,
  6162. CheckTime: item.CheckTime,
  6163. CheckState: item.CheckState,
  6164. RemindType: item.RemindType,
  6165. FrequencyType: item.FrequencyType,
  6166. DayCount: item.DayCount,
  6167. WeekDay: item.WeekDay,
  6168. TemplateId: item.TemplateId,
  6169. Modifier: item.Modifier,
  6170. Way: item.Way,
  6171. DrugId: item.DrugId,
  6172. }
  6173. if medical.IsUse == 2 {
  6174. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6175. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6176. }
  6177. if pharmacyConfig.IsOpen != 1 {
  6178. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6179. }
  6180. //更新字典里面的库存
  6181. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6182. var sum_count int64
  6183. for _, its := range stockInfo {
  6184. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6185. if its.MaxUnit == baseDrug.MaxUnit {
  6186. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6187. }
  6188. sum_count += its.StockMaxNumber + its.StockMinNumber
  6189. }
  6190. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6191. //剩余库存
  6192. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6193. }
  6194. info := models.DoctorAdvice{
  6195. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6196. ExecutionTime: exec_time,
  6197. ExecutionState: 1,
  6198. UpdatedTime: time.Now().Unix(),
  6199. }
  6200. //执行医嘱
  6201. service.UpdateDoctorAdviceExecution(info, item.ID)
  6202. }
  6203. }
  6204. this.ServeSuccessJSON(map[string]interface{}{
  6205. "msg": "1",
  6206. })
  6207. return
  6208. }
  6209. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  6210. orgId := this.GetAdminUserInfo().CurrentOrgId
  6211. idsStr := this.GetString("str")
  6212. recordIDStrs := strings.Split(idsStr, ",")
  6213. start_time := this.GetString("advice_date")
  6214. timeLayout := "2006-01-02"
  6215. loc, _ := time.LoadLocation("Local")
  6216. var startTime int64
  6217. if len(start_time) > 0 {
  6218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6219. if err != nil {
  6220. //fmt.Println(err)
  6221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6222. return
  6223. }
  6224. startTime = theTime.Unix()
  6225. }
  6226. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6227. if config.IsOpen == 1 {
  6228. creater := this.GetAdminUserInfo().AdminUser.Id
  6229. //查询未核对的医嘱
  6230. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6231. for _, item := range advicelist {
  6232. if item.ExecutionStaff == creater {
  6233. this.ServeSuccessJSON(map[string]interface{}{
  6234. "msg": "2",
  6235. "advice": item,
  6236. })
  6237. return
  6238. }
  6239. service.CheckHisDoctorAdvice(item.ID, creater)
  6240. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6241. redis := service.RedisClient()
  6242. //清空key 值
  6243. redis.Set(key, "", time.Second)
  6244. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6245. redis.Set(keyTwo, "", time.Second)
  6246. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6247. redis.Set(keyThree, "", time.Second)
  6248. theTime := time.Now()
  6249. recordDate := theTime.Format("2006-01-02")
  6250. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6251. redis.Set(keyFour, "", time.Second)
  6252. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6253. redis.Set(keyFive, "", time.Second)
  6254. }
  6255. } else {
  6256. //查询未核对的医嘱
  6257. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6258. creater := this.GetAdminUserInfo().AdminUser.Id
  6259. for _, item := range advicelist {
  6260. if item.ExecutionStaff == creater {
  6261. this.ServeSuccessJSON(map[string]interface{}{
  6262. "msg": "2",
  6263. "advice": item,
  6264. })
  6265. return
  6266. }
  6267. service.CheckDoctorAdvice(item.ID, creater)
  6268. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6269. redis := service.RedisClient()
  6270. //清空key 值
  6271. redis.Set(key, "", time.Second)
  6272. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6273. redis.Set(keyTwo, "", time.Second)
  6274. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6275. redis.Set(keyThree, "", time.Second)
  6276. theTime := time.Now()
  6277. recordDate := theTime.Format("2006-01-02")
  6278. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6279. redis.Set(keyFour, "", time.Second)
  6280. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6281. redis.Set(keyFive, "", time.Second)
  6282. }
  6283. }
  6284. this.ServeSuccessJSON(map[string]interface{}{
  6285. "msg": "1",
  6286. })
  6287. return
  6288. }
  6289. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  6290. orgId := this.GetAdminUserInfo().CurrentOrgId
  6291. is_open, _ := this.GetInt64("is_open")
  6292. idsStr := this.GetString("str")
  6293. recordIDStrs := strings.Split(idsStr, ",")
  6294. start_time := this.GetString("advice_date")
  6295. timeLayout := "2006-01-02"
  6296. loc, _ := time.LoadLocation("Local")
  6297. var startTime int64
  6298. if len(start_time) > 0 {
  6299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6300. if err != nil {
  6301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6302. return
  6303. }
  6304. startTime = theTime.Unix()
  6305. }
  6306. if is_open == 1 {
  6307. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6308. } else {
  6309. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6310. }
  6311. this.ServeSuccessJSON(map[string]interface{}{
  6312. "msg": "1",
  6313. })
  6314. return
  6315. }
  6316. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  6317. advice_id, _ := this.GetInt64("advice_id")
  6318. start_time := this.GetString("advice_date")
  6319. orgId := this.GetAdminUserInfo().CurrentOrgId
  6320. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6321. exec_time, _ := this.GetInt64("exec_time")
  6322. //his医嘱
  6323. if config.IsOpen == 1 {
  6324. //查询医嘱
  6325. advice, _ := service.GetHisDocById(advice_id, orgId)
  6326. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  6327. this.ServeSuccessJSON(map[string]interface{}{
  6328. "msg": "3",
  6329. })
  6330. return
  6331. }
  6332. medical, _ := service.GetBaseDrugMedical(orgId)
  6333. var prescribing_number int64
  6334. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6335. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6336. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6337. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6338. }
  6339. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6340. prescribing_number = parseIntPrescribingNumber
  6341. }
  6342. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6343. prescribing_number = parseIntPrescribingNumber
  6344. }
  6345. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6346. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6347. //库存不足
  6348. if prescribing_number > drugStockOut.FlushCount {
  6349. this.ServeSuccessJSON(map[string]interface{}{
  6350. "msg": "2",
  6351. "drug": medical,
  6352. })
  6353. return
  6354. }
  6355. info := models.HisDoctorAdviceInfo{
  6356. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6357. ExecutionTime: exec_time,
  6358. ExecutionState: 1,
  6359. UpdatedTime: time.Now().Unix(),
  6360. }
  6361. //执行医嘱
  6362. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  6363. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  6364. redis := service.RedisClient()
  6365. //清空key 值
  6366. redis.Set(key, "", time.Second)
  6367. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  6368. redis.Set(keyTwo, "", time.Second)
  6369. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6370. redis.Set(keyThree, "", time.Second)
  6371. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6372. theTime := toTime.Format("2006-01-02")
  6373. fmt.Println("theTIME", theTime)
  6374. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6375. redis.Set(keyFour, "", time.Second)
  6376. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6377. redis.Set(keyFive, "", time.Second)
  6378. //出库
  6379. if prescribing_number <= drugStockOut.FlushCount {
  6380. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6381. //执行出库逻辑
  6382. hisadvice := &models.HisDoctorAdviceInfo{
  6383. ID: advice.ID,
  6384. UserOrgId: advice.UserOrgId,
  6385. PatientId: advice.PatientId,
  6386. AdviceType: advice.AdviceType,
  6387. AdviceDate: advice.AdviceDate,
  6388. StartTime: advice.StartTime,
  6389. AdviceName: advice.AdviceName,
  6390. AdviceDesc: advice.AdviceDesc,
  6391. ReminderDate: advice.ReminderDate,
  6392. SingleDose: advice.SingleDose,
  6393. SingleDoseUnit: advice.SingleDoseUnit,
  6394. DrugSpec: advice.DrugSpec,
  6395. DrugSpecUnit: advice.DrugSpecUnit,
  6396. PrescribingNumber: advice.PrescribingNumber,
  6397. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6398. DeliveryWay: advice.DeliveryWay,
  6399. ExecutionFrequency: advice.ExecutionFrequency,
  6400. AdviceDoctor: advice.AdviceDoctor,
  6401. Status: 1,
  6402. CreatedTime: advice.CreatedTime,
  6403. UpdatedTime: advice.UpdatedTime,
  6404. AdviceAffirm: advice.AdviceAffirm,
  6405. Remark: advice.Remark,
  6406. StopTime: advice.StopTime,
  6407. StopReason: advice.StopReason,
  6408. StopDoctor: advice.StopDoctor,
  6409. StopState: advice.StopState,
  6410. ParentId: advice.ParentId,
  6411. ExecutionTime: advice.ExecutionTime,
  6412. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6413. ExecutionState: advice.ExecutionState,
  6414. Checker: advice.Checker,
  6415. RecordDate: advice.RecordDate,
  6416. DialysisOrderId: advice.DialysisOrderId,
  6417. CheckTime: advice.CheckTime,
  6418. CheckState: advice.CheckState,
  6419. RemindType: advice.RemindType,
  6420. FrequencyType: advice.FrequencyType,
  6421. DayCount: advice.DayCount,
  6422. WeekDay: advice.WeekDay,
  6423. TemplateId: advice.TemplateId,
  6424. Modifier: advice.Modifier,
  6425. Way: advice.Way,
  6426. DrugId: advice.DrugId,
  6427. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  6428. }
  6429. if medical.IsUse == 2 {
  6430. if config.IsOpen != 1 {
  6431. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6432. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6433. }
  6434. //不通过药房发药
  6435. if pharmacyConfig.IsOpen != 1 {
  6436. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6437. }
  6438. //查询默认仓库
  6439. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  6440. //查询默认仓库剩余多少库存
  6441. var sum_count int64
  6442. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6443. for _, its := range stockInfo {
  6444. if its.MaxUnit == medical.MaxUnit {
  6445. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6446. }
  6447. sum_count += its.StockMaxNumber + its.StockMinNumber
  6448. }
  6449. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6450. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6451. }
  6452. }
  6453. }
  6454. this.ServeSuccessJSON(map[string]interface{}{
  6455. "msg": "1",
  6456. })
  6457. return
  6458. }
  6459. if config.IsOpen == 2 || config.IsOpen == 0 {
  6460. advice, _ := service.GetBloodDocById(advice_id, orgId)
  6461. medical, _ := service.GetBaseDrugMedical(orgId)
  6462. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6463. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6464. var prescribing_number int64
  6465. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6466. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6467. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6468. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6469. }
  6470. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6471. prescribing_number = parseIntPrescribingNumber
  6472. }
  6473. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6474. prescribing_number = parseIntPrescribingNumber
  6475. }
  6476. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6477. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6478. //库存不足
  6479. if prescribing_number > drugStockOut.FlushCount {
  6480. this.ServeSuccessJSON(map[string]interface{}{
  6481. "msg": "2",
  6482. "drug": medical,
  6483. })
  6484. return
  6485. }
  6486. info := models.DoctorAdvice{
  6487. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6488. ExecutionTime: exec_time,
  6489. ExecutionState: 1,
  6490. UpdatedTime: time.Now().Unix(),
  6491. }
  6492. //执行医嘱
  6493. service.UpdateDoctorAdviceExecution(info, advice.ID)
  6494. dadvice := &models.DoctorAdvice{
  6495. ID: advice.ID,
  6496. UserOrgId: advice.UserOrgId,
  6497. PatientId: advice.PatientId,
  6498. AdviceType: advice.AdviceType,
  6499. AdviceDate: advice.AdviceDate,
  6500. StartTime: advice.StartTime,
  6501. AdviceName: advice.AdviceName,
  6502. AdviceDesc: advice.AdviceDesc,
  6503. ReminderDate: advice.ReminderDate,
  6504. SingleDose: advice.SingleDose,
  6505. SingleDoseUnit: advice.SingleDoseUnit,
  6506. DrugSpec: advice.DrugSpec,
  6507. DrugSpecUnit: advice.DrugSpecUnit,
  6508. PrescribingNumber: advice.PrescribingNumber,
  6509. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6510. DeliveryWay: advice.DeliveryWay,
  6511. ExecutionFrequency: advice.ExecutionFrequency,
  6512. AdviceDoctor: advice.AdviceDoctor,
  6513. Status: 1,
  6514. CreatedTime: advice.CreatedTime,
  6515. UpdatedTime: advice.UpdatedTime,
  6516. AdviceAffirm: advice.AdviceAffirm,
  6517. Remark: advice.Remark,
  6518. StopTime: advice.StopTime,
  6519. StopReason: advice.StopReason,
  6520. StopDoctor: advice.StopDoctor,
  6521. StopState: advice.StopState,
  6522. ParentId: advice.ParentId,
  6523. ExecutionTime: advice.ExecutionTime,
  6524. ExecutionStaff: advice.ExecutionStaff,
  6525. ExecutionState: advice.ExecutionState,
  6526. Checker: advice.Checker,
  6527. RecordDate: advice.ReminderDate,
  6528. DialysisOrderId: advice.DialysisOrderId,
  6529. CheckTime: advice.CheckTime,
  6530. CheckState: advice.CheckState,
  6531. RemindType: advice.RemindType,
  6532. FrequencyType: advice.FrequencyType,
  6533. DayCount: advice.DayCount,
  6534. WeekDay: advice.WeekDay,
  6535. TemplateId: advice.TemplateId,
  6536. Modifier: advice.Modifier,
  6537. Way: advice.Way,
  6538. DrugId: advice.DrugId,
  6539. }
  6540. if medical.IsUse == 2 {
  6541. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6542. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6543. }
  6544. if pharmacyConfig.IsOpen != 1 {
  6545. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6546. }
  6547. //更新字典里面的库存
  6548. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6549. var sum_count int64
  6550. for _, its := range stockInfo {
  6551. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6552. if its.MaxUnit == baseDrug.MaxUnit {
  6553. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6554. }
  6555. sum_count += its.StockMaxNumber + its.StockMinNumber
  6556. }
  6557. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6558. //剩余库存
  6559. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6560. }
  6561. }
  6562. this.ServeSuccessJSON(map[string]interface{}{
  6563. "msg": "1",
  6564. })
  6565. return
  6566. }
  6567. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6568. orgId := this.GetAdminUserInfo().CurrentOrgId
  6569. schedule_type, _ := this.GetInt64("schedule_type")
  6570. //partion_type, _ := this.GetInt64("partion_type")
  6571. partion_type := this.GetString("partion_type")
  6572. var ids []string
  6573. ids = strings.Split(partion_type, ",")
  6574. start_time := this.GetString("selected_date")
  6575. timeLayout := "2006-01-02"
  6576. loc, _ := time.LoadLocation("Local")
  6577. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6578. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6579. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6580. _, config := service.FindXTHisRecordByOrgId(orgId)
  6581. appId := this.GetAdminUserInfo().CurrentAppId
  6582. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6583. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6584. if err == nil {
  6585. this.ServeSuccessJSON(map[string]interface{}{
  6586. "list": list,
  6587. "drug": drug,
  6588. "config": config,
  6589. "doctorList": doctorList,
  6590. "manufacturerList": manufacturerList,
  6591. })
  6592. return
  6593. } else {
  6594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6595. return
  6596. }
  6597. }
  6598. func (this *DialysisApiController) GetDialysisProject() {
  6599. orgId := this.GetAdminUserInfo().CurrentOrgId
  6600. schedule_type, _ := this.GetInt64("schedule_type")
  6601. partion_type := this.GetString("partion_type")
  6602. var ids []string
  6603. ids = strings.Split(partion_type, ",")
  6604. start_time := this.GetString("selected_date")
  6605. timeLayout := "2006-01-02"
  6606. loc, _ := time.LoadLocation("Local")
  6607. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6608. list, err := service.GetDialysisProjectSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6609. if err == nil {
  6610. this.ServeSuccessJSON(map[string]interface{}{
  6611. "list": list,
  6612. })
  6613. return
  6614. } else {
  6615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6616. return
  6617. }
  6618. }
  6619. func (this *DialysisApiController) GetMobileScheduleList() {
  6620. orgId := this.GetAdminUserInfo().CurrentOrgId
  6621. schedule, _ := service.GetMobileScheduleList(orgId)
  6622. if len(schedule) > 0 {
  6623. for _, its := range schedule {
  6624. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6625. //its.DialysisPrescription = prescription
  6626. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6627. //its.MonitoringRecord = monitor
  6628. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6629. //its.XtAssessmentAfterDislysis = after
  6630. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6631. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6632. }
  6633. }
  6634. this.ServeSuccessJSON(map[string]interface{}{
  6635. "schedule": schedule,
  6636. })
  6637. return
  6638. }
  6639. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6640. week_day, _ := this.GetInt64("week_day")
  6641. orgId := this.GetAdminUserInfo().CurrentOrgId
  6642. informaitonSetting := models.XtDialysisInformaitonSetting{
  6643. WeekDay: week_day,
  6644. UserOrgId: orgId,
  6645. Status: 1,
  6646. Ctime: time.Now().Unix(),
  6647. Mtime: 0,
  6648. }
  6649. information, _ := service.GetInformationSettingByOrgId(orgId)
  6650. if information.ID == 0 {
  6651. service.CreateInformationSetting(informaitonSetting)
  6652. }
  6653. if information.ID > 0 {
  6654. service.UpdateInformationSettingById(orgId, week_day)
  6655. }
  6656. this.ServeSuccessJSON(map[string]interface{}{
  6657. "informaitonSetting": informaitonSetting,
  6658. })
  6659. return
  6660. }
  6661. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6662. orgId := this.GetAdminUserInfo().CurrentOrgId
  6663. limit, _ := this.GetInt64("limit")
  6664. page, _ := this.GetInt64("page")
  6665. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6666. //未审核
  6667. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6668. //全部
  6669. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6670. patients, _ := service.GetAllpatientThirty(orgId)
  6671. appId := this.GetAdminUserInfo().CurrentAppId
  6672. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6673. this.ServeSuccessJSON(map[string]interface{}{
  6674. "informaitonSetting": informationSetting,
  6675. "infor": infor,
  6676. "total": total,
  6677. "totalOne": totalOne,
  6678. "inforList": inforList,
  6679. "patients": patients,
  6680. "adminList": role,
  6681. })
  6682. return
  6683. }
  6684. func (this *DialysisApiController) CheckDialysisInformation() {
  6685. id, _ := this.GetInt64("id")
  6686. application_status, _ := this.GetInt64("application_status")
  6687. timeNow := time.Now().Unix()
  6688. checker := this.GetAdminUserInfo().AdminUser.Id
  6689. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6690. this.ServeSuccessJSON(map[string]interface{}{
  6691. "information": information,
  6692. })
  6693. return
  6694. }
  6695. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6696. page, _ := this.GetInt64("page", 1)
  6697. limit, _ := this.GetInt64("limit", 10)
  6698. schedulType, _ := this.GetInt64("schedul_type", 0)
  6699. startTime, _ := this.GetInt64("schedul_time", 0)
  6700. partitionType, _ := this.GetInt64("partition_type", 0)
  6701. keywords := this.GetString("keywords")
  6702. start_time, _ := this.GetInt64("start_time")
  6703. end_time, _ := this.GetInt64("end_time")
  6704. adminUserInfo := this.GetAdminUserInfo()
  6705. if len(keywords) > 0 {
  6706. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6707. if err == nil {
  6708. this.ServeSuccessJSON(map[string]interface{}{
  6709. "schedule": dialysisSchedule,
  6710. "total": total,
  6711. })
  6712. } else {
  6713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6714. }
  6715. } else {
  6716. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6717. if err == nil {
  6718. this.ServeSuccessJSON(map[string]interface{}{
  6719. "schedule": dialysisSchedule,
  6720. "total": total,
  6721. })
  6722. } else {
  6723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6724. }
  6725. }
  6726. }
  6727. func (this *DialysisApiController) SaveInformation() {
  6728. patient_id, _ := this.GetInt64("patient_id")
  6729. record_date, _ := this.GetInt64("record_date")
  6730. startTime := this.GetString("selected_date")
  6731. timeLayout := "2006-01-02 15:04"
  6732. loc, _ := time.LoadLocation("Local")
  6733. if len(startTime) == 0 {
  6734. utils.ErrorLog("len(start_time) == 0")
  6735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6736. return
  6737. }
  6738. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6739. if err != nil {
  6740. utils.ErrorLog(err.Error())
  6741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6742. return
  6743. }
  6744. StartTime := theTime.Unix()
  6745. fmt.Println("startime-------------", StartTime)
  6746. module, _ := this.GetInt64("module")
  6747. remark := this.GetString("remark")
  6748. orgId := this.GetAdminUserInfo().CurrentOrgId
  6749. creater := this.GetAdminUserInfo().AdminUser.Id
  6750. information := models.XtDialysisInformation{
  6751. Module: module,
  6752. PatientId: patient_id,
  6753. RecordDate: record_date,
  6754. ApplicationDate: StartTime,
  6755. Creater: creater,
  6756. ApplicationStatus: 2,
  6757. Checker: 0,
  6758. CheckTime: 0,
  6759. Remark: remark,
  6760. UserOrgId: orgId,
  6761. Ctime: time.Now().Unix(),
  6762. Status: 1,
  6763. Mtime: 0,
  6764. }
  6765. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6766. if infor.ID == 0 {
  6767. err := service.CreatedDialysisInformation(information)
  6768. if err == nil {
  6769. this.ServeSuccessJSON(map[string]interface{}{
  6770. "information": information,
  6771. })
  6772. return
  6773. }
  6774. }
  6775. if infor.ID > 0 {
  6776. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6777. if err == nil {
  6778. this.ServeSuccessJSON(map[string]interface{}{
  6779. "information": information,
  6780. })
  6781. return
  6782. }
  6783. }
  6784. }
  6785. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6786. orgId := this.GetAdminUserInfo().CurrentOrgId
  6787. schedule_type, _ := this.GetInt64("schedule_type")
  6788. partion_type := this.GetString("partion_type")
  6789. var ids []string
  6790. ids = strings.Split(partion_type, ",")
  6791. start_time := this.GetString("selected_date")
  6792. timeLayout := "2006-01-02"
  6793. loc, _ := time.LoadLocation("Local")
  6794. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6795. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6796. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6797. _, config := service.FindXTHisRecordByOrgId(orgId)
  6798. appId := this.GetAdminUserInfo().CurrentAppId
  6799. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6800. if err == nil {
  6801. this.ServeSuccessJSON(map[string]interface{}{
  6802. "list": list,
  6803. "drug": drug,
  6804. "config": config,
  6805. "doctorList": doctorList,
  6806. })
  6807. return
  6808. } else {
  6809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6810. return
  6811. }
  6812. }
  6813. func (this *DialysisApiController) GetPatientList() {
  6814. orgId := this.GetAdminUserInfo().CurrentOrgId
  6815. keyWord := this.GetString("keyword")
  6816. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  6817. if err == nil {
  6818. this.ServeSuccessJSON(map[string]interface{}{
  6819. "patientList": patientList,
  6820. })
  6821. return
  6822. } else {
  6823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6824. return
  6825. }
  6826. }
  6827. func (this *DialysisApiController) GetPrescriptionLogList() {
  6828. patient_id, _ := this.GetInt64("patient_id")
  6829. record_date := this.GetString("record_date")
  6830. page, _ := this.GetInt64("page")
  6831. limit, _ := this.GetInt64("limit")
  6832. orgId := this.GetAdminUserInfo().CurrentOrgId
  6833. timeLayout := "2006-01-02"
  6834. loc, _ := time.LoadLocation("Local")
  6835. var recordDateTime int64
  6836. if len(record_date) > 0 {
  6837. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6838. if err != nil {
  6839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6840. return
  6841. }
  6842. recordDateTime = theTime.Unix()
  6843. }
  6844. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  6845. patients, _ := service.GetAllPatientLog(orgId)
  6846. role, _ := service.GetAllDoctorLog(orgId)
  6847. if err == nil {
  6848. this.ServeSuccessJSON(map[string]interface{}{
  6849. "prescriptionlogList": prescriptionlogList,
  6850. "total": total,
  6851. "patients": patients,
  6852. "role": role,
  6853. })
  6854. return
  6855. } else {
  6856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6857. return
  6858. }
  6859. }
  6860. func (this *DialysisApiController) GetBeforLogList() {
  6861. patient_id, _ := this.GetInt64("patient_id")
  6862. record_date := this.GetString("record_date")
  6863. page, _ := this.GetInt64("page")
  6864. limit, _ := this.GetInt64("limit")
  6865. orgId := this.GetAdminUserInfo().CurrentOrgId
  6866. timeLayout := "2006-01-02"
  6867. loc, _ := time.LoadLocation("Local")
  6868. var recordDateTime int64
  6869. if len(record_date) > 0 {
  6870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6871. if err != nil {
  6872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6873. return
  6874. }
  6875. recordDateTime = theTime.Unix()
  6876. }
  6877. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  6878. patients, _ := service.GetAllPatientLog(orgId)
  6879. role, _ := service.GetAllDoctorLog(orgId)
  6880. if err == nil {
  6881. this.ServeSuccessJSON(map[string]interface{}{
  6882. "beforLogList": beforLogList,
  6883. "total": total,
  6884. "patients": patients,
  6885. "role": role,
  6886. })
  6887. return
  6888. } else {
  6889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6890. return
  6891. }
  6892. }
  6893. func (this *DialysisApiController) GetDocLogList() {
  6894. patient_id, _ := this.GetInt64("patient_id")
  6895. record_date := this.GetString("record_date")
  6896. page, _ := this.GetInt64("page")
  6897. limit, _ := this.GetInt64("limit")
  6898. orgId := this.GetAdminUserInfo().CurrentOrgId
  6899. timeLayout := "2006-01-02"
  6900. loc, _ := time.LoadLocation("Local")
  6901. var recordDateTime int64
  6902. if len(record_date) > 0 {
  6903. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6904. if err != nil {
  6905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6906. return
  6907. }
  6908. recordDateTime = theTime.Unix()
  6909. }
  6910. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  6911. patients, _ := service.GetAllPatientLog(orgId)
  6912. role, _ := service.GetAllDoctorLog(orgId)
  6913. if err == nil {
  6914. this.ServeSuccessJSON(map[string]interface{}{
  6915. "adviceLogList": adviceLogList,
  6916. "total": total,
  6917. "patients": patients,
  6918. "role": role,
  6919. })
  6920. return
  6921. } else {
  6922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6923. return
  6924. }
  6925. }
  6926. func (this *DialysisApiController) GetMonitorLogList() {
  6927. patient_id, _ := this.GetInt64("patient_id")
  6928. record_date := this.GetString("record_date")
  6929. page, _ := this.GetInt64("page")
  6930. limit, _ := this.GetInt64("limit")
  6931. orgId := this.GetAdminUserInfo().CurrentOrgId
  6932. timeLayout := "2006-01-02"
  6933. loc, _ := time.LoadLocation("Local")
  6934. var recordDateTime int64
  6935. if len(record_date) > 0 {
  6936. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6937. if err != nil {
  6938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6939. return
  6940. }
  6941. recordDateTime = theTime.Unix()
  6942. }
  6943. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  6944. patients, _ := service.GetAllPatientLog(orgId)
  6945. role, _ := service.GetAllDoctorLog(orgId)
  6946. if err == nil {
  6947. this.ServeSuccessJSON(map[string]interface{}{
  6948. "monitorLogList": monitorLogList,
  6949. "total": total,
  6950. "patients": patients,
  6951. "role": role,
  6952. })
  6953. return
  6954. } else {
  6955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6956. return
  6957. }
  6958. }
  6959. func (this *DialysisApiController) GetAfterLogList() {
  6960. patient_id, _ := this.GetInt64("patient_id")
  6961. record_date := this.GetString("record_date")
  6962. page, _ := this.GetInt64("page")
  6963. limit, _ := this.GetInt64("limit")
  6964. orgId := this.GetAdminUserInfo().CurrentOrgId
  6965. timeLayout := "2006-01-02"
  6966. loc, _ := time.LoadLocation("Local")
  6967. var recordDateTime int64
  6968. if len(record_date) > 0 {
  6969. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6970. if err != nil {
  6971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6972. return
  6973. }
  6974. recordDateTime = theTime.Unix()
  6975. }
  6976. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  6977. patients, _ := service.GetAllPatientLog(orgId)
  6978. role, _ := service.GetAllDoctorLog(orgId)
  6979. if err == nil {
  6980. this.ServeSuccessJSON(map[string]interface{}{
  6981. "afterLogList": afterLogList,
  6982. "total": total,
  6983. "patients": patients,
  6984. "role": role,
  6985. })
  6986. return
  6987. } else {
  6988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6989. return
  6990. }
  6991. }
  6992. func (this *DialysisApiController) SaveGatherSetting() {
  6993. orgId := this.GetAdminUserInfo().CurrentOrgId
  6994. is_index_number, _ := this.GetInt64("is_index_number")
  6995. fmt.Println("this,23o2332232323232332", is_index_number)
  6996. is_zone, _ := this.GetInt64("is_zone")
  6997. is_number, _ := this.GetInt64("is_number")
  6998. is_birth, _ := this.GetInt64("is_birth")
  6999. is_age, _ := this.GetInt64("is_age")
  7000. is_name, _ := this.GetInt64("is_name")
  7001. is_mode_type, _ := this.GetInt64("is_mode_type")
  7002. is_prescription_status, _ := this.GetInt64("is_prescription_status")
  7003. is_admission_number, _ := this.GetInt64("is_admission_number")
  7004. is_dialysis_no, _ := this.GetInt64("is_dialysis_no")
  7005. is_dry_weight, _ := this.GetInt64("is_dry_weight")
  7006. is_dialysis_dialyszers, _ := this.GetInt64("is_dialysis_dialyszers")
  7007. is_dialysis_strainer, _ := this.GetInt64("is_dialysis_strainer")
  7008. is_dialysis_irrigation, _ := this.GetInt64("is_dialysis_irrigation")
  7009. is_calcium, _ := this.GetInt64("is_calcium")
  7010. is_kalium, _ := this.GetInt64("is_kalium")
  7011. is_change_nurse, _ := this.GetInt64("is_change_nurse")
  7012. is_puncture_needle, _ := this.GetInt64("is_puncture_needle")
  7013. is_anticoagulant, _ := this.GetInt64("is_anticoagulant")
  7014. is_tube, _ := this.GetInt64("is_tube")
  7015. is_cuhong, _ := this.GetInt64("is_cuhong")
  7016. is_zuoka, _ := this.GetInt64("is_zuoka")
  7017. is_zhetangtie, _ := this.GetInt64("is_zhetangtie")
  7018. is_paligu, _ := this.GetInt64("is_paligu")
  7019. is_guhuachun, _ := this.GetInt64("is_guhuachun")
  7020. is_niaojimei, _ := this.GetInt64("is_niaojimei")
  7021. is_putaosuangai, _ := this.GetInt64("is_putaosuangai")
  7022. is_jiaguan, _ := this.GetInt64("is_jiaguan")
  7023. is_xiongxiewutai, _ := this.GetInt64("is_xiongxiewutai")
  7024. gatherSetting := models.XtDialysisGatherSetting{
  7025. UserOrgId: orgId,
  7026. IndexNumber: is_index_number,
  7027. Zone: is_zone,
  7028. Number: is_number,
  7029. Birth: is_birth,
  7030. Name: is_name,
  7031. Age: is_age,
  7032. ModeType: is_mode_type,
  7033. PrescriptionStatus: is_prescription_status,
  7034. AdmissionNumber: is_admission_number,
  7035. DialysisNo: is_dialysis_no,
  7036. DryWeight: is_dry_weight,
  7037. DialysisDialyszers: is_dialysis_dialyszers,
  7038. DialysisStrainer: is_dialysis_strainer,
  7039. DialysisIrrigation: is_dialysis_irrigation,
  7040. Calcium: is_calcium,
  7041. Kalium: is_kalium,
  7042. ChangeNurse: is_change_nurse,
  7043. PunctureNeedle: is_puncture_needle,
  7044. Anticoagulant: is_anticoagulant,
  7045. Tube: is_tube,
  7046. Cuhong: is_cuhong,
  7047. Zuoka: is_zuoka,
  7048. Zhetangtie: is_zhetangtie,
  7049. Paligu: is_paligu,
  7050. Guhuachun: is_guhuachun,
  7051. Niaojimei: is_niaojimei,
  7052. Putaosuangai: is_putaosuangai,
  7053. Jiaguan: is_jiaguan,
  7054. Xiongxiewutai: is_xiongxiewutai,
  7055. Ctime: time.Now().Unix(),
  7056. Mtime: time.Now().Unix(),
  7057. Status: 1,
  7058. }
  7059. //查询该机构有没有设置
  7060. gatherSettingOne, _ := service.GetGatherSettingByOrgId(orgId)
  7061. if gatherSettingOne.ID == 0 {
  7062. service.CreateGather(gatherSetting)
  7063. } else {
  7064. gatherSetting.ID = gatherSettingOne.ID
  7065. service.SaveGather(gatherSetting)
  7066. }
  7067. this.ServeSuccessJSON(map[string]interface{}{
  7068. "gatherSetting": gatherSetting,
  7069. })
  7070. return
  7071. }
  7072. func (this *DialysisApiController) GetGatherSetting() {
  7073. orgId := this.GetAdminUserInfo().CurrentOrgId
  7074. gatherSetting, _ := service.GetGatherSetting(orgId)
  7075. this.ServeSuccessJSON(map[string]interface{}{
  7076. "gatherSetting": gatherSetting,
  7077. })
  7078. return
  7079. }
  7080. func (this *DialysisApiController) GetDialysisGatherList() {
  7081. keyword := this.GetString("keywords")
  7082. limit, _ := this.GetInt64("limit")
  7083. page, _ := this.GetInt64("page")
  7084. partion_type := this.GetString("partition_id")
  7085. idSplit := strings.Split(partion_type, ",")
  7086. schedule_type, _ := this.GetInt64("schedule_type")
  7087. start_time := this.GetString("schedule_date")
  7088. timeLayout := "2006-01-02"
  7089. loc, _ := time.LoadLocation("Local")
  7090. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7091. orgId := this.GetAdminUserInfo().CurrentOrgId
  7092. scheduids := this.GetString("ids")
  7093. var ids []string
  7094. if scheduids != "" {
  7095. ids = strings.Split(scheduids, ",")
  7096. }
  7097. list, total, _ := service.GetDialysisGatherList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  7098. gatherSetting, _ := service.GetGatherSetting(orgId)
  7099. this.ServeSuccessJSON(map[string]interface{}{
  7100. "list": list,
  7101. "total": total,
  7102. "gatherSetting": gatherSetting,
  7103. })
  7104. return
  7105. }
  7106. func (this *DialysisApiController) GetPatientDialysisRecordList() {
  7107. patient_id, _ := this.GetInt64("patient_id")
  7108. timeLayout := "2006-01-02"
  7109. loc, _ := time.LoadLocation("Local")
  7110. start_time := this.GetString("start_time")
  7111. end_time := this.GetString("end_time")
  7112. var startdateunix int64
  7113. if len(start_time) > 0 {
  7114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7115. if err != nil {
  7116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7117. return
  7118. }
  7119. startdateunix = theTime.Unix()
  7120. }
  7121. var enddateunix int64
  7122. if len(end_time) > 0 {
  7123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7124. if err != nil {
  7125. utils.ErrorLog(err.Error())
  7126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7127. return
  7128. }
  7129. enddateunix = theTime.Unix()
  7130. }
  7131. org_id := this.GetAdminUserInfo().CurrentOrgId
  7132. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7133. list, _ := service.GetPatientDialysisRecordList(patient_id, startdateunix, enddateunix)
  7134. this.ServeSuccessJSON(map[string]interface{}{
  7135. "list": list,
  7136. })
  7137. return
  7138. } else {
  7139. list, _ := service.GetPatientDialysisRecordListOne(patient_id, startdateunix, enddateunix)
  7140. this.ServeSuccessJSON(map[string]interface{}{
  7141. "list": list,
  7142. })
  7143. }
  7144. return
  7145. }
  7146. func (this *DialysisApiController) GetPatientRecordList() {
  7147. patient_id, _ := this.GetInt64("patient_id")
  7148. orgId := this.GetAdminUserInfo().CurrentOrgId
  7149. beforList, _ := service.GetPatientBeforRecordList(patient_id, orgId)
  7150. afterList, _ := service.GetPatientAfterRecordList(patient_id, orgId)
  7151. monitorList, _ := service.GetMonitorRecordByGroup(patient_id, orgId)
  7152. this.ServeSuccessJSON(map[string]interface{}{
  7153. "beforList": beforList,
  7154. "afterList": afterList,
  7155. "monitorList": monitorList,
  7156. })
  7157. }
  7158. func (this *DialysisApiController) GetDialysisTotalCount() {
  7159. timeLayout := "2006-01-02"
  7160. loc, _ := time.LoadLocation("Local")
  7161. start_time := this.GetString("start_time")
  7162. end_time := this.GetString("end_time")
  7163. patient_id, _ := this.GetInt64("patient_id")
  7164. var startdateunix int64
  7165. if len(start_time) > 0 {
  7166. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7167. if err != nil {
  7168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7169. return
  7170. }
  7171. startdateunix = theTime.Unix()
  7172. }
  7173. var enddateunix int64
  7174. if len(end_time) > 0 {
  7175. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7176. if err != nil {
  7177. utils.ErrorLog(err.Error())
  7178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7179. return
  7180. }
  7181. enddateunix = theTime.Unix()
  7182. }
  7183. orgId := this.GetAdminUserInfo().CurrentOrgId
  7184. order, _ := service.GetDialysisTotalCountByTime(orgId, startdateunix, enddateunix, patient_id)
  7185. this.ServeSuccessJSON(map[string]interface{}{
  7186. "order": order,
  7187. })
  7188. }
  7189. func (this *DialysisApiController) GetPatientBefor() {
  7190. timeLayout := "2006-01-02"
  7191. loc, _ := time.LoadLocation("Local")
  7192. record_date := this.GetString("record_date")
  7193. patient_id, _ := this.GetInt64("patient_id")
  7194. user_org_id := this.GetAdminUserInfo().CurrentOrgId
  7195. var startdateunix int64
  7196. if len(record_date) > 0 {
  7197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7198. if err != nil {
  7199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7200. return
  7201. }
  7202. startdateunix = theTime.Unix()
  7203. }
  7204. patientBefor, _ := service.GetPatientBefor(patient_id, startdateunix, user_org_id)
  7205. prescription, _ := service.GetDialysisPrescribeOneList(patient_id, startdateunix, user_org_id)
  7206. this.ServeSuccessJSON(map[string]interface{}{
  7207. "patientBefor": patientBefor,
  7208. "prescription": prescription,
  7209. })
  7210. }