dialysis_api_controller.go 306KB

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