dialysis_api_controller.go 318KB

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