dialysis_api_controller.go 312KB

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