dialysis_api_controller.go 311KB

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