dialysis_api_controller.go 307KB

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