dialysis_api_controller.go 243KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  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. }
  79. func (c *DialysisApiController) GetQueueCall() {
  80. adminUserInfo := c.GetAdminUserInfo()
  81. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  82. if queueConfig.ID <= 0 {
  83. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  84. queueConfig.Qhsj = 10
  85. queueConfig.Jzdcbbcs = 3
  86. queueConfig.Jzbbsy = 1
  87. queueConfig.Jzjhyc = 0
  88. queueConfig.Sjdcbbcs = 3
  89. queueConfig.Sjbbsy = 0
  90. queueConfig.Sjjhyc = 0
  91. queueConfig.Txxqyxs = 0
  92. queueConfig.Txglsyxs = 0
  93. }
  94. c.ServeSuccessJSON(map[string]interface{}{
  95. "queue_config": queueConfig,
  96. })
  97. }
  98. func (c *DialysisApiController) UpdateQueueCall() {
  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. queueConfig.CreateTime = time.Now().Unix()
  113. queueConfig.UpdateTime = time.Now().Unix()
  114. }
  115. qhsj, _ := c.GetInt64("qhsj", 0)
  116. if qhsj > 0 {
  117. queueConfig.Qhsj = qhsj
  118. }
  119. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  120. if jzdcbbcs > 0 {
  121. queueConfig.Jzdcbbcs = jzdcbbcs
  122. }
  123. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  124. if jzbbsy > 0 {
  125. queueConfig.Jzbbsy = jzbbsy
  126. }
  127. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  128. queueConfig.Jzjhyc = jzjhyc
  129. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  130. if sjdcbbcs > 0 {
  131. queueConfig.Sjdcbbcs = sjdcbbcs
  132. }
  133. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  134. if sjbbsy > 0 {
  135. queueConfig.Sjbbsy = sjbbsy
  136. }
  137. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  138. queueConfig.Sjjhyc = sjjhyc
  139. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  140. queueConfig.Txxqyxs = txxqyxs
  141. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  142. queueConfig.Txglsyxs = txglsyxs
  143. queueConfig.UpdateTime = time.Now().Unix()
  144. service.UpDateQueueCallInfo(queueConfig)
  145. c.ServeSuccessJSON(map[string]interface{}{
  146. "queue_config": queueConfig,
  147. })
  148. }
  149. func (c *DialysisApiController) PostPrescription() {
  150. patient, _ := c.GetInt64("patient_id", 0)
  151. recordDateStr := c.GetString("record_date")
  152. if patient <= 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. adminUserInfo := c.GetAdminUserInfo()
  157. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  158. if patientInfo.ID == 0 {
  159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  160. return
  161. }
  162. if len(recordDateStr) == 0 {
  163. recordDateStr = time.Now().Format("2006-01-02")
  164. }
  165. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  166. if parseDateErr != nil {
  167. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  169. return
  170. }
  171. mode_id, _ := c.GetInt64("mode_id", 0)
  172. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  173. dialyzer, _ := c.GetInt64("dialyzer", 0)
  174. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  175. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  176. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  177. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  178. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  179. replacement_way, _ := c.GetInt64("replacement_way", 0)
  180. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  181. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  182. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  183. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  184. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  185. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  186. kalium, _ := c.GetFloat("kalium", 0)
  187. sodium, _ := c.GetFloat("sodium", 0)
  188. replacement_total, _ := c.GetFloat("replacement_total", 0)
  189. calcium, _ := c.GetFloat("calcium", 0)
  190. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  191. glucose, _ := c.GetFloat("glucose", 0)
  192. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  193. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  194. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  195. conductivity, _ := c.GetFloat("conductivity", 0)
  196. remark := c.GetString("remark")
  197. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  198. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  199. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  200. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  201. body_fluid, _ := c.GetInt64("body_fluid", 0)
  202. special_medicine, _ := c.GetInt64("special_medicine", 0)
  203. special_medicine_other := c.GetString("special_medicine_other")
  204. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  205. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  206. blood_access, _ := c.GetInt64("blood_access", 0)
  207. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  208. body_fluid_other := c.GetString("body_fluid_other")
  209. target_ktv, _ := c.GetFloat("target_ktv", 0)
  210. niprocart, _ := c.GetInt64("niprocart", 0)
  211. jms, _ := c.GetInt64("jms", 0)
  212. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  213. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  214. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  215. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  216. filtryzer, _ := c.GetInt64("filtryzer", 0)
  217. dialyzers, _ := c.GetInt64("dialyzers", 0)
  218. injector, _ := c.GetInt64("injector", 0)
  219. bloodlines, _ := c.GetInt64("bloodlines", 0)
  220. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  221. safe_package, _ := c.GetInt64("package", 0)
  222. a_liquid, _ := c.GetInt64("a_liquid", 0)
  223. preImpules, _ := c.GetFloat("pre_impulse", 0)
  224. fmt.Println("", preImpules)
  225. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  226. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  227. //heparin_sodium := c.GetString("heparin_sodium")
  228. //fmt.Println("肝素钠",heparin_sodium)
  229. //nucleoprotamine := c.GetString("nucleoprotamine")
  230. //fmt.Println("鱼精蛋白",nucleoprotamine)
  231. //push_the_protamine := c.GetString("push_the_protamine")
  232. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  233. // var prescription_doctor int64
  234. blood := c.GetString("blood")
  235. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  236. dialysis_irrigation := c.GetString("dialysis_irrigation")
  237. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  238. displace_speed := c.GetString("displace_speed")
  239. illness, _ := c.GetInt64("illness")
  240. amylaceum := c.GetString("amylaceum")
  241. single_time := c.GetString("single_time")
  242. single_water := c.GetString("single_water")
  243. replacement_flow := c.GetString("replacement_flow")
  244. plasma_separator := c.GetString("plasma_separator")
  245. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  246. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  247. oxygen_flow := c.GetString("oxygen_flow")
  248. oxygen_time := c.GetString("oxygen_time")
  249. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  250. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  251. puncture_needle := c.GetString("puncture_needle")
  252. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  253. epo := c.GetString("epo")
  254. epo_count, _ := c.GetFloat("epo_count", 0)
  255. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  256. admin_user_id, _ := c.GetInt64("admin_user_id")
  257. is_water, _ := c.GetInt64("is_water")
  258. drhy_water := c.GetString("drhy_water")
  259. dry_water_hour := c.GetString("dry_water_hour")
  260. water_machine := c.GetString("water_machine")
  261. add_amount, _ := c.GetFloat("add_amount")
  262. reduce_amount, _ := c.GetFloat("reduce_amount")
  263. dialysis_remark := c.GetString("dialysis_remark")
  264. prescribing_number, _ := c.GetFloat("prescribing_number")
  265. treatment_remark := c.GetString("treatment_remark")
  266. prescription_sodium := c.GetString("prescription_sodium")
  267. start_sodium := c.GetString("start_sodium")
  268. sodium_curve := c.GetString("sodium_curve")
  269. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  270. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  271. prescription_water, _ := c.GetFloat("prescription_water")
  272. dialysis_strainer := c.GetString("dialysis_strainer")
  273. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  274. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  275. //if template.TemplateId == 2 || template.TemplateId == 6 {
  276. // if appRole.UserType == 3 {
  277. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  278. // if getPermissionErr != nil {
  279. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // return
  281. // } else if headNursePermission == nil {
  282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  283. // return
  284. // }
  285. // }
  286. //}
  287. prescription := models.DialysisPrescription{
  288. UserOrgId: adminUserInfo.CurrentOrgId,
  289. PatientId: patient,
  290. RecordDate: recordDate.Unix(),
  291. ModeId: mode_id,
  292. DialysisDuration: dialysis_duration,
  293. Dialyzer: dialyzer,
  294. ReplacementTotal: replacement_total,
  295. PerfusionApparatus: perfusion_apparatus,
  296. BloodFlowVolume: blood_flow_volume,
  297. DewaterAmount: dewater_amount,
  298. DisplaceLiqui: displace_liqui,
  299. ReplacementWay: replacement_way,
  300. Anticoagulant: anticoagulant,
  301. AnticoagulantShouji: anticoagulant_shouji,
  302. AnticoagulantWeichi: anticoagulant_weichi,
  303. AnticoagulantZongliang: anticoagulant_zongliang,
  304. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  305. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  306. Kalium: kalium,
  307. Sodium: sodium,
  308. Calcium: calcium,
  309. Bicarbonate: bicarbonate,
  310. Glucose: glucose,
  311. // DryWeight: dry_weight,
  312. DialysateFlow: dialysate_flow,
  313. DialysateTemperature: dialysate_temperature,
  314. Conductivity: conductivity,
  315. Remark: remark,
  316. Status: 1,
  317. CreatedTime: time.Now().Unix(),
  318. UpdatedTime: time.Now().Unix(),
  319. DialysisDurationMinute: dialysisDurationMinute,
  320. DialysisDurationHour: dialysisDurationHour,
  321. TargetUltrafiltration: targetUltrafiltration,
  322. DialysateFormulation: dialysateFormulation,
  323. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  324. BodyFluid: body_fluid,
  325. SpecialMedicine: special_medicine,
  326. SpecialMedicineOther: special_medicine_other,
  327. DisplaceLiquiPart: displace_liqui_part,
  328. DisplaceLiquiValue: displace_liqui_value,
  329. BloodAccess: blood_access,
  330. Ultrafiltration: ultrafiltration,
  331. BodyFluidOther: body_fluid_other,
  332. TargetKtv: target_ktv,
  333. Niprocart: niprocart,
  334. Jms: jms,
  335. FistulaNeedleSet: fistula_needle_set,
  336. FistulaNeedleSet16: fistula_needle_set_16,
  337. Hemoperfusion: hemoperfusion,
  338. DialyserSterilised: dialyser_sterilised,
  339. Filtryzer: filtryzer,
  340. Dialyzers: dialyzers,
  341. Injector: injector,
  342. Bloodlines: bloodlines,
  343. TubingHemodialysis: tubing_hemodialysis,
  344. Package: safe_package,
  345. ALiquid: a_liquid,
  346. PreImpulse: preImpules,
  347. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  348. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  349. Blood: blood,
  350. DialysisDialyszers: dialysis_dialyszers,
  351. DialysisIrrigation: dialysis_irrigation,
  352. AntioxidantCommodityName: antioxidant_commodity_name,
  353. DisplaceSpeed: displace_speed,
  354. Illness: illness,
  355. Amylaceum: amylaceum,
  356. SingleTime: single_time,
  357. SingleWater: single_water,
  358. ReplacementFlow: replacement_flow,
  359. PlasmaSeparator: plasma_separator,
  360. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  361. OxygenFlow: oxygen_flow,
  362. OxygenUptake: oxygen_uptake,
  363. OxygenTime: oxygen_time,
  364. HemodialysisPipelines: hemodialysis_pipelines,
  365. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  366. PunctureNeedle: puncture_needle,
  367. PunctureNeedleCount: puncture_needle_count,
  368. Epo: epo,
  369. EpoCount: epo_count,
  370. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  371. AdminUserId: admin_user_id,
  372. IsWater: is_water,
  373. DrhyWater: drhy_water,
  374. DryWaterHour: dry_water_hour,
  375. WaterMachine: water_machine,
  376. AddAmount: add_amount,
  377. ReduceAmount: reduce_amount,
  378. DialysisRemark: dialysis_remark,
  379. PrescribingNumber: prescribing_number,
  380. TreatmentRemark: treatment_remark,
  381. PrescriptionSodium: prescription_sodium,
  382. StartSodium: start_sodium,
  383. SodiumCurve: sodium_curve,
  384. DialysisFluidFlow: dialysis_fluid_flow,
  385. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  386. PrescriptionWater: prescription_water,
  387. DialysisStrainer: dialysis_strainer,
  388. }
  389. //长沙南雅医院,自动生成抗凝剂的临时处方
  390. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  391. if prescribing_number == 0 {
  392. prescribing_number = 1
  393. }
  394. advice := models.DoctorAdvice{
  395. UserOrgId: adminUserInfo.CurrentOrgId,
  396. PatientId: patient,
  397. GroupNo: 0,
  398. AdviceType: 2,
  399. RecordDate: recordDate.Unix(),
  400. AdviceDate: recordDate.Unix(),
  401. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  402. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  403. AdviceDesc: "",
  404. ReminderDate: 0,
  405. SingleDose: anticoagulant_zongliang,
  406. SingleDoseUnit: "iu",
  407. DrugSpec: 0,
  408. DrugSpecUnit: "",
  409. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  410. PrescribingNumberUnit: "支",
  411. DeliveryWay: "静脉注射",
  412. ExecutionFrequency: "上机前",
  413. AdviceDoctor: 0,
  414. Status: 1,
  415. CreatedTime: time.Now().Unix(),
  416. UpdatedTime: time.Now().Unix(),
  417. IsPrescription: 1,
  418. ExecutionState: 2,
  419. StopState: 2,
  420. IsSettle: 2,
  421. }
  422. // 查询排班信息
  423. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  424. if schedulePatient.ID > 0 {
  425. if schedulePatient.ScheduleType == 1 {
  426. advice.StartTime = recordDate.Unix() + 6.5*60*60
  427. }
  428. if schedulePatient.ScheduleType == 2 {
  429. advice.StartTime = recordDate.Unix() + 11*60*60
  430. }
  431. }
  432. // 抗凝剂名称
  433. switch anticoagulant {
  434. case 1:
  435. advice.AdviceName = "无肝素"
  436. break
  437. case 2:
  438. advice.AdviceName = "普通肝素"
  439. break
  440. case 3:
  441. advice.AdviceName = "低分子肝素"
  442. break
  443. case 4:
  444. advice.AdviceName = "阿加曲班"
  445. break
  446. case 5:
  447. advice.AdviceName = "枸橼酸钠"
  448. break
  449. case 6:
  450. advice.AdviceName = "低分子肝素钙"
  451. break
  452. case 7:
  453. advice.AdviceName = "低分子肝素钠"
  454. break
  455. case 8:
  456. advice.AdviceName = "依诺肝素"
  457. break
  458. case 9:
  459. advice.AdviceName = "达肝素"
  460. break
  461. case 10:
  462. advice.AdviceName = "体外抗凝"
  463. break
  464. case 11:
  465. advice.AdviceName = "那曲肝素"
  466. break
  467. case 12:
  468. advice.AdviceName = "无抗凝剂"
  469. break
  470. }
  471. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  472. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  473. advice.AdviceDoctor = appRole.AdminUserId
  474. }
  475. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  476. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  477. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  478. advice.AdviceName = "低分子肝素钠注射液"
  479. // 修改患者临时医嘱里的抗凝剂医嘱
  480. advice.ID = advicePrescription.ID
  481. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  482. //service.UpdateDoctorAdvice(&advice)
  483. } else {
  484. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  485. advice.AdviceName = "低分子肝素钠注射液"
  486. // 新增患者临时医嘱里的抗凝剂医嘱
  487. service.CreateDoctorAdvice(&advice)
  488. }
  489. }
  490. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  491. redis := service.RedisClient()
  492. //清空key 值
  493. redis.Set(key, "", time.Second)
  494. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  495. redis.Set(keyOne, "", time.Second)
  496. }
  497. if appRole.UserType == 2 || appRole.UserType == 1 {
  498. prescription.PrescriptionDoctor = appRole.AdminUserId
  499. }
  500. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  501. if dialysisPrescription.ID == 0 { //新增
  502. if mode_id > 0 {
  503. var str string
  504. //查找该机构用的是什么透析器
  505. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  506. if filedConfig.ID > 0 {
  507. str = dialyzerPerfusionApparatus
  508. } else {
  509. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  510. }
  511. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  512. }
  513. prescription.Creater = adminUserInfo.AdminUser.Id
  514. //针对河间咸得
  515. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  516. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  517. prescription.DisplaceLiquiPart = 0
  518. prescription.DisplaceLiquiValue = 0
  519. }
  520. }
  521. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  522. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  523. }
  524. // 查询信息规挡的设置天数
  525. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  526. if infor.ID > 0 {
  527. var cha_time int64
  528. timeNowStr := time.Now().Format("2006-01-02")
  529. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  530. //今日的日期减去设置的日期
  531. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  532. if cha_time >= recordDate.Unix() {
  533. //查询审核是否允许
  534. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  535. //申请状态不允许的情况 拒绝修改
  536. if infor.ApplicationStatus != 1 {
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  538. return
  539. }
  540. }
  541. }
  542. err := service.AddSigleRecord(&prescription)
  543. //创建步骤表
  544. finish := models.XtDialysisFinish{
  545. IsFinish: 1,
  546. UserOrgId: adminUserInfo.CurrentOrgId,
  547. Status: 1,
  548. Ctime: time.Now().Unix(),
  549. Mtime: 0,
  550. Module: 1,
  551. RecordDate: recordDate.Unix(),
  552. Sourse: 1,
  553. }
  554. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1)
  555. if dialysisFinish.ID == 0 {
  556. service.CreateDialysisFinish(finish)
  557. }
  558. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  559. redis := service.RedisClient()
  560. //清空key 值
  561. redis.Set(key, "", time.Second)
  562. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  563. redis.Set(keyTwo, "", time.Second)
  564. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  565. redis.Set(keyThree, "", time.Second)
  566. defer redis.Close()
  567. if err == nil {
  568. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  569. if updateErr != nil {
  570. utils.ErrorLog("%v", updateErr)
  571. }
  572. c.ServeSuccessJSON(map[string]interface{}{
  573. "prescription": &prescription,
  574. })
  575. } else {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  577. }
  578. } else { //修改
  579. if mode_id > 0 {
  580. var str string
  581. //查找该机构用的是什么透析器
  582. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  583. if filedConfig.ID > 0 {
  584. str = dialyzerPerfusionApparatus
  585. } else {
  586. str = dialysis_dialyszers + "/" + dialysis_irrigation
  587. }
  588. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  589. }
  590. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  591. //if template.TemplateId == 1 {
  592. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  593. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  594. // if getPermissionErr != nil {
  595. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  596. // return
  597. // } else if headNursePermission == nil {
  598. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  599. // return
  600. // }
  601. // }
  602. //}
  603. if appRole.UserType == 2 || appRole.UserType == 1 {
  604. prescription_doctor := adminUserInfo.AdminUser.Id
  605. prescription.PrescriptionDoctor = prescription_doctor
  606. }
  607. if dialysisPrescription.Creater == 0 { //体重称
  608. prescription.Creater = adminUserInfo.AdminUser.Id
  609. } else {
  610. prescription.Creater = dialysisPrescription.Creater
  611. }
  612. prescription.CreatedTime = dialysisPrescription.CreatedTime
  613. prescription.UpdatedTime = time.Now().Unix()
  614. prescription.Modifier = adminUserInfo.AdminUser.Id
  615. prescription.ID = dialysisPrescription.ID
  616. updateErr := service.UpDateDialysisPrescription(&prescription)
  617. //修改处方
  618. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  619. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  620. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  621. if advicePrescription.ID > 0 {
  622. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  623. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  624. redis := service.RedisClient()
  625. defer redis.Close()
  626. //清空key 值
  627. redis.Set(key, "", time.Second)
  628. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  629. redis.Set(keyOne, "", time.Second)
  630. }
  631. }
  632. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  633. redis := service.RedisClient()
  634. defer redis.Close()
  635. //清空key 值
  636. redis.Set(key, "", time.Second)
  637. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  638. redis.Set(keyOne, "", time.Second)
  639. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  640. redis.Set(keyThree, "", time.Second)
  641. if updateErr == nil {
  642. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  643. if updateErr != nil {
  644. utils.ErrorLog("%v", updateErr)
  645. }
  646. c.ServeSuccessJSON(map[string]interface{}{
  647. "prescription": &prescription,
  648. })
  649. } else {
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  651. }
  652. }
  653. }
  654. func (c *DialysisApiController) PostSoulution() {
  655. patient, _ := c.GetInt64("patient", 0)
  656. recordDateStr := c.GetString("record_date")
  657. if patient <= 0 {
  658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  659. return
  660. }
  661. adminUserInfo := c.GetAdminUserInfo()
  662. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  663. if patientInfo.ID == 0 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  665. return
  666. }
  667. if len(recordDateStr) == 0 {
  668. recordDateStr = time.Now().Format("2006-01-02")
  669. }
  670. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  671. if parseDateErr != nil {
  672. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  674. return
  675. }
  676. mode_id, _ := c.GetInt64("mode_id", 0)
  677. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  678. dialyzer, _ := c.GetInt64("dialyzer", 0)
  679. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  680. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  681. replacement_total, _ := c.GetFloat("replacement_total", 0)
  682. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  683. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  684. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  685. replacement_way, _ := c.GetInt64("replacement_way", 0)
  686. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  687. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  688. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  689. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  690. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  691. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  692. kalium, _ := c.GetFloat("kalium", 0)
  693. sodium, _ := c.GetFloat("sodium", 0)
  694. calcium, _ := c.GetFloat("calcium", 0)
  695. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  696. glucose, _ := c.GetFloat("glucose", 0)
  697. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  698. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  699. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  700. conductivity, _ := c.GetFloat("conductivity", 0)
  701. remark := c.GetString("remark")
  702. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  703. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  704. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  705. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  706. body_fluid, _ := c.GetInt64("body_fluid", 0)
  707. special_medicine, _ := c.GetInt64("special_medicine", 0)
  708. special_medicine_other := c.GetString("special_medicine_other")
  709. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  710. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  711. blood_access, _ := c.GetInt64("blood_access", 0)
  712. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  713. body_fluid_other := c.GetString("body_fluid_other")
  714. target_ktv, _ := c.GetFloat("target_ktv", 0)
  715. niprocart, _ := c.GetInt64("niprocart", 0)
  716. jms, _ := c.GetInt64("jms", 0)
  717. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  718. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  719. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  720. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  721. filtryzer, _ := c.GetInt64("filtryzer", 0)
  722. dialyzers, _ := c.GetInt64("dialyzers", 0)
  723. injector, _ := c.GetInt64("injector", 0)
  724. bloodlines, _ := c.GetInt64("bloodlines", 0)
  725. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  726. safe_package, _ := c.GetInt64("package", 0)
  727. a_liquid, _ := c.GetInt64("a_liquid", 0)
  728. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  729. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  730. blood := c.GetString("blood")
  731. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  732. dialysis_irrigation := c.GetString("dialysis_irrigation")
  733. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  734. displace_speed := c.GetString("displace_speed")
  735. illness, _ := c.GetInt64("illness")
  736. amylaceum := c.GetString("amylaceum")
  737. single_time := c.GetString("single_time")
  738. single_water := c.GetString("single_water")
  739. replacement_flow := c.GetString("replacement_flow")
  740. plasma_separator := c.GetString("plasma_separator")
  741. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  742. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  743. oxygen_flow := c.GetString("oxygen_flow")
  744. oxygen_time := c.GetString("oxygen_time")
  745. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  746. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  747. puncture_needle := c.GetString("puncture_needle")
  748. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  749. epo := c.GetString("epo")
  750. epo_count, _ := c.GetFloat("epo_count", 0)
  751. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  752. impulse := c.GetString("impulse")
  753. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  754. admin_user_id, _ := c.GetInt64("admin_user_id")
  755. fmt.Println("", preImpules)
  756. is_water, _ := c.GetInt64("is_water")
  757. dry_water_hour := c.GetString("dry_water_hour")
  758. drhy_water := c.GetString("drhy_water")
  759. water_machine := c.GetString("water_machine")
  760. add_amount, _ := c.GetFloat("add_amount")
  761. reduce_amount, _ := c.GetFloat("reduce_amount")
  762. dialysis_remark := c.GetString("dialysis_remark")
  763. prescribing_number, _ := c.GetFloat("prescribing_number")
  764. treatment_remark := c.GetString("treatment_remark")
  765. prescription_sodium := c.GetString("prescription_sodium")
  766. start_sodium := c.GetString("start_sodium")
  767. sodium_curve := c.GetString("sodium_curve")
  768. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  769. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  770. prescription_water, _ := c.GetFloat("prescription_water")
  771. dialysis_strainer := c.GetString("dialysis_strainer")
  772. var prescription_doctor int64
  773. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  774. if appRole.UserType == 2 || appRole.UserType == 1 {
  775. prescription_doctor = appRole.AdminUserId
  776. }
  777. if mode_id > 0 {
  778. var str string
  779. //查找该机构用的是什么透析器
  780. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  781. if filedConfig.ID > 0 {
  782. str = dialyzerPerfusionApparatus
  783. } else {
  784. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  785. }
  786. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  787. }
  788. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  789. //
  790. //if template.TemplateId == 2 || template.TemplateId == 6 {
  791. // if appRole.UserType == 3 {
  792. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  793. // if getPermissionErr != nil {
  794. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  795. // return
  796. // } else if headNursePermission == nil {
  797. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  798. // return
  799. // }
  800. // }
  801. //}
  802. prescription := models.DialysisPrescription{
  803. UserOrgId: adminUserInfo.CurrentOrgId,
  804. PatientId: patient,
  805. RecordDate: recordDate.Unix(),
  806. ModeId: mode_id,
  807. DialysisDuration: dialysis_duration,
  808. Dialyzer: dialyzer,
  809. PerfusionApparatus: perfusion_apparatus,
  810. BloodFlowVolume: blood_flow_volume,
  811. DewaterAmount: dewater_amount,
  812. DisplaceLiqui: displace_liqui,
  813. ReplacementWay: replacement_way,
  814. Anticoagulant: anticoagulant,
  815. AnticoagulantShouji: anticoagulant_shouji,
  816. AnticoagulantWeichi: anticoagulant_weichi,
  817. AnticoagulantZongliang: anticoagulant_zongliang,
  818. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  819. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  820. Kalium: kalium,
  821. Sodium: sodium,
  822. Calcium: calcium,
  823. Bicarbonate: bicarbonate,
  824. Glucose: glucose,
  825. // DryWeight: dry_weight,
  826. DialysateFlow: dialysate_flow,
  827. DialysateTemperature: dialysate_temperature,
  828. Conductivity: conductivity,
  829. Remark: remark,
  830. PrescriptionDoctor: prescription_doctor,
  831. Status: 1,
  832. CreatedTime: time.Now().Unix(),
  833. UpdatedTime: time.Now().Unix(),
  834. DialysisDurationMinute: dialysisDurationMinute,
  835. DialysisDurationHour: dialysisDurationHour,
  836. TargetUltrafiltration: targetUltrafiltration,
  837. DialysateFormulation: dialysateFormulation,
  838. ReplacementTotal: replacement_total,
  839. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  840. BodyFluid: body_fluid,
  841. SpecialMedicine: special_medicine,
  842. SpecialMedicineOther: special_medicine_other,
  843. DisplaceLiquiPart: displace_liqui_part,
  844. DisplaceLiquiValue: displace_liqui_value,
  845. BloodAccess: blood_access,
  846. Ultrafiltration: ultrafiltration,
  847. BodyFluidOther: body_fluid_other,
  848. TargetKtv: target_ktv,
  849. Niprocart: niprocart,
  850. Jms: jms,
  851. FistulaNeedleSet: fistula_needle_set,
  852. FistulaNeedleSet16: fistula_needle_set_16,
  853. Hemoperfusion: hemoperfusion,
  854. DialyserSterilised: dialyser_sterilised,
  855. Filtryzer: filtryzer,
  856. Dialyzers: dialyzers,
  857. Injector: injector,
  858. Bloodlines: bloodlines,
  859. TubingHemodialysis: tubing_hemodialysis,
  860. Package: safe_package,
  861. ALiquid: a_liquid,
  862. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  863. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  864. Blood: blood,
  865. DialysisIrrigation: dialysis_irrigation,
  866. DialysisDialyszers: dialysis_dialyszers,
  867. AntioxidantCommodityName: antioxidant_commodity_name,
  868. DisplaceSpeed: displace_speed,
  869. Illness: illness,
  870. Amylaceum: amylaceum,
  871. SingleTime: single_time,
  872. SingleWater: single_water,
  873. ReplacementFlow: replacement_flow,
  874. PlasmaSeparator: plasma_separator,
  875. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  876. OxygenTime: oxygen_time,
  877. OxygenUptake: oxygen_uptake,
  878. OxygenFlow: oxygen_flow,
  879. HemodialysisPipelines: hemodialysis_pipelines,
  880. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  881. PunctureNeedle: puncture_needle,
  882. PunctureNeedleCount: puncture_needle_count,
  883. Epo: epo,
  884. EpoCount: epo_count,
  885. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  886. PreImpulse: preImpules,
  887. AdminUserId: admin_user_id,
  888. IsWater: is_water,
  889. DryWaterHour: dry_water_hour,
  890. DrhyWater: drhy_water,
  891. WaterMachine: water_machine,
  892. AddAmount: add_amount,
  893. ReduceAmount: reduce_amount,
  894. DialysisRemark: dialysis_remark,
  895. PrescribingNumber: prescribing_number,
  896. StartSodium: start_sodium,
  897. PrescriptionSodium: prescription_sodium,
  898. SodiumCurve: sodium_curve,
  899. TreatmentRemark: treatment_remark,
  900. DialysisFluidFlow: dialysis_fluid_flow,
  901. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  902. PrescriptionWater: prescription_water,
  903. DialysisStrainer: dialysis_strainer,
  904. }
  905. //查询最近透析准备表里是否存在 透析器 灌流器
  906. //splitStr := strings.Split(dialysis_dialyszers, ",")
  907. //
  908. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  909. //
  910. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  911. //if len(mation)>0{
  912. // for _, item := range splitStr {
  913. // for _,it := range mation{
  914. // if(item == it.SpecificationName){
  915. //
  916. // //查询最近一次的透析器
  917. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  918. //
  919. // if errcode == gorm.ErrRecordNotFound{
  920. // //插入数据
  921. // prepare := models.DialysisBeforePrepare{
  922. // UserOrgId: adminUserInfo.CurrentOrgId,
  923. // PatientId: patient,
  924. // RecordDate: recordDate.Unix(),
  925. // GoodTypeId: it.GoodTypeId,
  926. // GoodId: it.ID,
  927. // Count: 1,
  928. // Ctime: time.Now().Unix(),
  929. // Creater: adminUserInfo.AdminUser.Id,
  930. // Status:1,
  931. //
  932. // }
  933. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  934. // fmt.Println("",errcode)
  935. // }
  936. // }
  937. // }
  938. //
  939. // }
  940. //
  941. // for _, item := range splitIrrigation {
  942. // for _,it := range mation{
  943. // if(item == it.SpecificationName){
  944. // //查询最近一次的透析器
  945. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  946. // if errcode == gorm.ErrRecordNotFound{
  947. // //插入数据
  948. // prepare := models.DialysisBeforePrepare{
  949. // UserOrgId: adminUserInfo.CurrentOrgId,
  950. // PatientId: patient,
  951. // RecordDate: recordDate.Unix(),
  952. // GoodTypeId: it.GoodTypeId,
  953. // GoodId: it.ID,
  954. // Count: 1,
  955. // Ctime: time.Now().Unix(),
  956. // Creater: adminUserInfo.AdminUser.Id,
  957. // Status:1,
  958. //
  959. // }
  960. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  961. // fmt.Println(errcode)
  962. // }
  963. // }
  964. // }
  965. // }
  966. //}
  967. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  968. if dialysisPrescription.ID == 0 { //新增
  969. if appRole.UserType == 2 || appRole.UserType == 1 {
  970. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  971. }
  972. prescription.Creater = adminUserInfo.AdminUser.Id
  973. } else { //修改
  974. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  975. //if template.TemplateId == 1 {
  976. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  977. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  978. // if getPermissionErr != nil {
  979. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  980. // return
  981. // } else if headNursePermission == nil {
  982. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  983. // return
  984. // }
  985. // }
  986. //}
  987. if appRole.UserType == 2 || appRole.UserType == 1 {
  988. prescription_doctor := adminUserInfo.AdminUser.Id
  989. prescription.PrescriptionDoctor = prescription_doctor
  990. } else {
  991. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  992. }
  993. if dialysisPrescription.Creater == 0 {
  994. prescription.Creater = adminUserInfo.AdminUser.Id
  995. } else {
  996. prescription.Creater = dialysisPrescription.Creater
  997. }
  998. prescription.CreatedTime = dialysisPrescription.CreatedTime
  999. prescription.UpdatedTime = time.Now().Unix()
  1000. prescription.Modifier = adminUserInfo.AdminUser.Id
  1001. prescription.ID = dialysisPrescription.ID
  1002. }
  1003. solution := models.DialysisSolution{
  1004. RegistrarsId: adminUserInfo.AdminUser.Id,
  1005. UserOrgId: adminUserInfo.CurrentOrgId,
  1006. Doctor: prescription_doctor,
  1007. PatientId: patient,
  1008. ModeId: mode_id,
  1009. DialysisDuration: dialysis_duration,
  1010. PerfusionApparatus: perfusion_apparatus,
  1011. BloodFlowVolume: blood_flow_volume,
  1012. Dewater: dewater_amount,
  1013. DisplaceLiqui: displace_liqui,
  1014. ReplacementWay: replacement_way,
  1015. Anticoagulant: anticoagulant,
  1016. AnticoagulantShouji: anticoagulant_shouji,
  1017. AnticoagulantWeichi: anticoagulant_weichi,
  1018. AnticoagulantZongliang: anticoagulant_zongliang,
  1019. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1020. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1021. Kalium: kalium,
  1022. Sodium: sodium,
  1023. Calcium: calcium,
  1024. Bicarbonate: bicarbonate,
  1025. Glucose: glucose,
  1026. // DryWeight: dry_weight,
  1027. DialysateFlow: dialysate_flow,
  1028. DialysateTemperature: dialysate_temperature,
  1029. Conductivity: conductivity,
  1030. Remark: remark,
  1031. Status: 1,
  1032. CreatedTime: time.Now().Unix(),
  1033. UpdatedTime: time.Now().Unix(),
  1034. DialysisDurationMinute: dialysisDurationMinute,
  1035. DialysisDurationHour: dialysisDurationHour,
  1036. TargetUltrafiltration: targetUltrafiltration,
  1037. DialysateFormulation: dialysateFormulation,
  1038. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1039. BodyFluid: body_fluid,
  1040. SpecialMedicine: special_medicine,
  1041. SpecialMedicineOther: special_medicine_other,
  1042. DisplaceLiquiPart: displace_liqui_part,
  1043. DisplaceLiquiValue: displace_liqui_value,
  1044. BloodAccess: blood_access,
  1045. Ultrafiltration: ultrafiltration,
  1046. BodyFluidOther: body_fluid_other,
  1047. ReplacementTotal: replacement_total,
  1048. TargetKtv: target_ktv,
  1049. DialysisIrrigation: dialysis_irrigation,
  1050. DialysisDialyszers: dialysis_dialyszers,
  1051. HemodialysisPipelines: hemodialysis_pipelines,
  1052. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1053. PunctureNeedle: puncture_needle,
  1054. PunctureNeedleCount: puncture_needle_count,
  1055. Epo: epo,
  1056. EpoCount: epo_count,
  1057. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1058. OxygenUptake: oxygen_uptake,
  1059. OxygenFlow: oxygen_flow,
  1060. OxygenTime: oxygen_time,
  1061. PreImpulse: preImpules,
  1062. SolutionStatus: 1,
  1063. DialysisRemark: dialysis_remark,
  1064. PrescribingNumber: prescribing_number,
  1065. StartSodium: start_sodium,
  1066. PrescriptionSodium: prescription_sodium,
  1067. SodiumCurve: sodium_curve,
  1068. TreatmentRemark: treatment_remark,
  1069. DialysisFluidFlow: dialysis_fluid_flow,
  1070. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1071. PrescriptionWater: prescribing_number,
  1072. DialysisStrainer: dialysis_strainer,
  1073. }
  1074. //针对河间咸得
  1075. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1076. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1077. prescription.DisplaceLiquiPart = 0
  1078. prescription.DisplaceLiquiValue = 0
  1079. }
  1080. }
  1081. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1082. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1083. solution.DisplaceLiquiPart = 0
  1084. solution.DisplaceLiquiValue = 0
  1085. }
  1086. }
  1087. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1088. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1089. }
  1090. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1091. //获取最新1条
  1092. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1093. //更新状态
  1094. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1095. //长沙南雅医院,自动生成抗凝剂的临时处方
  1096. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1097. if prescribing_number == 0 {
  1098. prescribing_number = 1
  1099. }
  1100. advice := models.DoctorAdvice{
  1101. UserOrgId: adminUserInfo.CurrentOrgId,
  1102. PatientId: patient,
  1103. GroupNo: 0,
  1104. AdviceType: 2,
  1105. RecordDate: recordDate.Unix(),
  1106. AdviceDate: recordDate.Unix(),
  1107. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1108. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1109. AdviceDesc: "",
  1110. ReminderDate: 0,
  1111. SingleDose: anticoagulant_zongliang,
  1112. SingleDoseUnit: "iu",
  1113. DrugSpec: 0,
  1114. DrugSpecUnit: "",
  1115. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1116. PrescribingNumberUnit: "支",
  1117. DeliveryWay: "静脉注射",
  1118. ExecutionFrequency: "上机前",
  1119. AdviceDoctor: 0,
  1120. Status: 1,
  1121. CreatedTime: time.Now().Unix(),
  1122. UpdatedTime: time.Now().Unix(),
  1123. IsPrescription: 1,
  1124. ExecutionState: 2,
  1125. StopState: 2,
  1126. IsSettle: 2,
  1127. }
  1128. // 查询排班信息
  1129. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1130. if schedulePatient.ID > 0 {
  1131. if schedulePatient.ScheduleType == 1 {
  1132. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1133. }
  1134. if schedulePatient.ScheduleType == 2 {
  1135. advice.StartTime = recordDate.Unix() + 11*60*60
  1136. }
  1137. }
  1138. // 抗凝剂名称
  1139. switch anticoagulant {
  1140. case 1:
  1141. advice.AdviceName = "无肝素"
  1142. break
  1143. case 2:
  1144. advice.AdviceName = "普通肝素"
  1145. break
  1146. case 3:
  1147. advice.AdviceName = "低分子肝素"
  1148. break
  1149. case 4:
  1150. advice.AdviceName = "阿加曲班"
  1151. break
  1152. case 5:
  1153. advice.AdviceName = "枸橼酸钠"
  1154. break
  1155. case 6:
  1156. advice.AdviceName = "低分子肝素钙"
  1157. break
  1158. case 7:
  1159. advice.AdviceName = "低分子肝素钠"
  1160. break
  1161. case 8:
  1162. advice.AdviceName = "依诺肝素"
  1163. break
  1164. case 9:
  1165. advice.AdviceName = "达肝素"
  1166. break
  1167. case 10:
  1168. advice.AdviceName = "体外抗凝"
  1169. break
  1170. case 11:
  1171. advice.AdviceName = "那曲肝素"
  1172. break
  1173. case 12:
  1174. advice.AdviceName = "无抗凝剂"
  1175. break
  1176. }
  1177. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1178. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1179. advice.AdviceDoctor = appRole.AdminUserId
  1180. }
  1181. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1182. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1183. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1184. advice.AdviceName = "低分子肝素钠注射液"
  1185. // 修改患者临时医嘱里的抗凝剂医嘱
  1186. advice.ID = advicePrescription.ID
  1187. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1188. } else {
  1189. // 新增患者临时医嘱里的抗凝剂医嘱
  1190. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1191. advice.AdviceName = "低分子肝素钠注射液"
  1192. service.CreateDoctorAdvice(&advice)
  1193. }
  1194. }
  1195. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1196. redis := service.RedisClient()
  1197. //清空key 值
  1198. redis.Set(key, "", time.Second)
  1199. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1200. redis.Set(keyOne, "", time.Second)
  1201. }
  1202. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1203. redis := service.RedisClient()
  1204. //清空key 值
  1205. redis.Set(key, "", time.Second)
  1206. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1207. //清空key 值
  1208. redis.Set(keyOne, "", time.Second)
  1209. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1210. redis.Set(keyTwo, "", time.Second)
  1211. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1212. redis.Set(keyThree, "", time.Second)
  1213. defer redis.Close()
  1214. if err == nil {
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "solution": &solution,
  1217. "prescription": &prescription,
  1218. })
  1219. } else {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1221. }
  1222. }
  1223. func (c *DialysisApiController) PostDouleCheck() {
  1224. id, _ := c.GetInt64("patient", 0)
  1225. recordDateStr := c.GetString("record_date")
  1226. checkTimeStr := c.GetString("check_time")
  1227. firstCheckTimeStr := c.GetString("first_check_time")
  1228. creater, _ := c.GetInt64("creater", 0)
  1229. modifier, _ := c.GetInt64("modifier", 0)
  1230. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1231. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1232. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1233. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1234. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1235. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1236. vascular_access_desc := c.GetString("vascular_access_desc")
  1237. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1238. collator, _ := c.GetInt64("collator", 0)
  1239. employee_number := c.GetString("employee_number")
  1240. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1241. needle_batch_number := c.GetString("needle_batch_number")
  1242. if id <= 0 {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. adminUserInfo := c.GetAdminUserInfo()
  1247. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1248. if patient.ID == 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1250. return
  1251. }
  1252. if len(recordDateStr) == 0 {
  1253. recordDateStr = time.Now().Format("2006-01-02")
  1254. }
  1255. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1256. if parseDateErr != nil {
  1257. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1259. return
  1260. }
  1261. var checkDate int64
  1262. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1263. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1264. if employee_number != list.JobNumber {
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1266. return
  1267. }
  1268. }
  1269. if len(checkTimeStr) == 0 {
  1270. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1271. checkDate = 0
  1272. } else {
  1273. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1274. checkDate = checkDateUnix.Unix()
  1275. }
  1276. var firstCheckTimeDate int64
  1277. if len(firstCheckTimeStr) == 0 {
  1278. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1279. firstCheckTimeDate = 0
  1280. } else {
  1281. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1282. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1283. }
  1284. doubleCheck := models.DoubleCheck{
  1285. UserOrgId: adminUserInfo.CurrentOrgId,
  1286. PatientId: id,
  1287. DialysisItemCheck: dialysis_item_check,
  1288. DialysisParameterCheck: dialysis_parameter_check,
  1289. VascularAccessVerification: vascular_access_verification,
  1290. PipelineConnectionCheck: pipeline_connection_check,
  1291. DialysisItemDesc: dialysis_item_desc,
  1292. DialysisParameterDesc: dialysis_parameter_desc,
  1293. VascularAccessDesc: vascular_access_desc,
  1294. PipelineConnectionDesc: pipeline_connection_desc,
  1295. Collator: collator,
  1296. Status: 1,
  1297. CreatedTime: time.Now().Unix(),
  1298. UpdatedTime: time.Now().Unix(),
  1299. CheckDate: recordDate.Unix(),
  1300. EmployeeNumber: employee_number,
  1301. DialyzerBatchNumber: dialyzer_batch_number,
  1302. NeedleBatchNumber: needle_batch_number,
  1303. }
  1304. // 查询信息规挡的设置天数
  1305. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1306. if infor.ID > 0 {
  1307. var cha_time int64
  1308. timeNowStr := time.Now().Format("2006-01-02")
  1309. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1310. //今日的日期减去设置的日期
  1311. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1312. if cha_time >= recordDate.Unix() {
  1313. //查询审核是否允许
  1314. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1315. //申请状态不允许的情况 拒绝修改
  1316. if infor.ApplicationStatus != 1 {
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1318. return
  1319. }
  1320. }
  1321. }
  1322. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1323. if check.ID == 0 { //新增
  1324. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1325. doubleCheck.CheckTime = checkDate
  1326. doubleCheck.Creater = creater
  1327. doubleCheck.Modifier = modifier
  1328. err := service.AddSigleDoubleCheck(&doubleCheck)
  1329. //创建步骤表
  1330. finish := models.XtDialysisFinish{
  1331. IsFinish: 1,
  1332. UserOrgId: adminUserInfo.CurrentOrgId,
  1333. Status: 1,
  1334. Ctime: time.Now().Unix(),
  1335. Mtime: 0,
  1336. Module: 5,
  1337. RecordDate: recordDate.Unix(),
  1338. Sourse: 1,
  1339. }
  1340. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 5)
  1341. if dialysisFinish.ID == 0 {
  1342. service.CreateDialysisFinish(finish)
  1343. }
  1344. // 查询信息规挡的设置天数
  1345. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1346. if infor.ID > 0 {
  1347. var cha_time int64
  1348. timeNowStr := time.Now().Format("2006-01-02")
  1349. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1350. //今日的日期减去设置的日期
  1351. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1352. if cha_time >= recordDate.Unix() {
  1353. //查询审核是否允许
  1354. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1355. //申请状态不允许的情况 拒绝修改
  1356. if infor.ApplicationStatus != 1 {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1358. return
  1359. }
  1360. }
  1361. }
  1362. redis := service.RedisClient()
  1363. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1364. //清空key 值
  1365. redis.Set(key, "", time.Second)
  1366. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1367. redis.Set(keyTwo, "", time.Second)
  1368. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1369. redis.Set(keyThree, "", time.Second)
  1370. defer redis.Close()
  1371. if err == nil {
  1372. c.ServeSuccessJSON(map[string]interface{}{
  1373. "doubleCheck": doubleCheck,
  1374. })
  1375. } else {
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1377. }
  1378. } else { //修改
  1379. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1380. doubleCheck.CheckTime = checkDate
  1381. doubleCheck.Creater = creater
  1382. doubleCheck.Modifier = modifier
  1383. doubleCheck.CreatedTime = check.CreatedTime
  1384. doubleCheck.UpdatedTime = time.Now().Unix()
  1385. doubleCheck.ID = check.ID
  1386. redis := service.RedisClient()
  1387. err := service.UpdateDoubleCheck(&doubleCheck)
  1388. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1389. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1390. redis.Set(keyTwo, "", time.Second)
  1391. //清空key 值
  1392. redis.Set(key, "", time.Second)
  1393. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1394. redis.Set(keyThree, "", time.Second)
  1395. defer redis.Close()
  1396. if err == nil {
  1397. c.ServeSuccessJSON(map[string]interface{}{
  1398. "doubleCheck": doubleCheck,
  1399. })
  1400. } else {
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1402. }
  1403. }
  1404. }
  1405. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1406. id, _ := c.GetInt64("patient", 0)
  1407. recordDateStr := c.GetString("record_date")
  1408. way, _ := c.GetInt64("way", 0)
  1409. consciousness, _ := c.GetInt64("consciousness", 0)
  1410. appetite, _ := c.GetInt64("appetite", 0)
  1411. condition, _ := c.GetInt64("condition", 0)
  1412. posture, _ := c.GetInt64("posture")
  1413. score := c.GetString("score")
  1414. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1415. danger_level, _ := c.GetInt64("danger_level", 0)
  1416. intake, _ := c.GetInt64("intake", 0)
  1417. nutrition, _ := c.GetInt64("nutrition", 0)
  1418. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1419. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1420. sick_condition_other := c.GetString("sick_condition_other")
  1421. //precaution, _ := c.GetInt64("precaution", 0)
  1422. precaution := c.GetString("precaution")
  1423. precaution_other := c.GetString("precaution_other")
  1424. psychological_other := c.GetString("psychological_other")
  1425. admission_number := c.GetString("admission_number")
  1426. tumble, _ := c.GetInt64("tumble")
  1427. his_department := c.GetString("his_department")
  1428. his_bed := c.GetString("his_bed")
  1429. diacrisis := c.GetString("diacrisis")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1450. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1451. UserOrgId: adminUserInfo.CurrentOrgId,
  1452. PatientId: id,
  1453. RecordDate: recordDate.Unix(),
  1454. Way: way,
  1455. Consciousness: consciousness,
  1456. Appetite: appetite,
  1457. Condition: condition,
  1458. SickCondition: sick_condition,
  1459. DangerLevel: danger_level,
  1460. Intake: intake,
  1461. Nutrition: nutrition,
  1462. PsychologicalAssessment: psychological_assessment,
  1463. PsychologicalAssessmentOther: psychological_assessment_other,
  1464. SickConditionOther: sick_condition_other,
  1465. Posture: posture,
  1466. CreatedTime: time.Now().Unix(),
  1467. UpdateTime: time.Now().Unix(),
  1468. Status: 1,
  1469. Score: score,
  1470. Precaution: precaution,
  1471. PrecautionOther: precaution_other,
  1472. PsychologicalOther: psychological_other,
  1473. AdmissionNumber: admission_number,
  1474. Tumble: tumble,
  1475. HisDepartment: his_department,
  1476. HisBed: his_bed,
  1477. Diacrisis: diacrisis,
  1478. }
  1479. // 查询信息规挡的设置天数
  1480. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1481. if infor.ID > 0 {
  1482. var cha_time int64
  1483. timeNowStr := time.Now().Format("2006-01-02")
  1484. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1485. //今日的日期减去设置的日期
  1486. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1487. if cha_time >= recordDate.Unix() {
  1488. //查询审核是否允许
  1489. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1490. //申请状态不允许的情况 拒绝修改
  1491. if infor.ApplicationStatus != 1 {
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1493. return
  1494. }
  1495. }
  1496. }
  1497. if receiveTreatment.ID == 0 { //新增
  1498. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1499. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1500. //创建步骤表
  1501. finish := models.XtDialysisFinish{
  1502. IsFinish: 1,
  1503. UserOrgId: adminUserInfo.CurrentOrgId,
  1504. Status: 1,
  1505. Ctime: time.Now().Unix(),
  1506. Mtime: 0,
  1507. Module: 2,
  1508. RecordDate: recordDate.Unix(),
  1509. Sourse: 1,
  1510. }
  1511. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 2)
  1512. if dialysisFinish.ID == 0 {
  1513. service.CreateDialysisFinish(finish)
  1514. }
  1515. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1516. redis := service.RedisClient()
  1517. //清空key 值
  1518. redis.Set(key, "", time.Second)
  1519. defer redis.Close()
  1520. if err == nil {
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "receiveTreatmentAsses": receiveTreatmentAsses,
  1523. })
  1524. } else {
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1526. }
  1527. } else { //修改
  1528. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1529. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1530. // if getPermissionErr != nil {
  1531. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1532. // return
  1533. // } else if headNursePermission == nil {
  1534. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1535. // return
  1536. // }
  1537. //}
  1538. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1539. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1540. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1541. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1542. receiveTreatmentAsses.ID = receiveTreatment.ID
  1543. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1544. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1545. redis := service.RedisClient()
  1546. defer redis.Close()
  1547. redis.Set(keyOne, "", time.Second*60*60*18)
  1548. if err == nil {
  1549. c.ServeSuccessJSON(map[string]interface{}{
  1550. "receiveTreatmentAsses": receiveTreatmentAsses,
  1551. })
  1552. } else {
  1553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1554. }
  1555. }
  1556. }
  1557. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1558. patient, _ := c.GetInt64("patient", 0)
  1559. recordDateStr := c.GetString("record_date")
  1560. fmt.Println(recordDateStr)
  1561. if patient <= 0 {
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1563. return
  1564. }
  1565. adminUserInfo := c.GetAdminUserInfo()
  1566. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1567. if patientInfo.ID == 0 {
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1569. return
  1570. }
  1571. if len(recordDateStr) == 0 {
  1572. recordDateStr = time.Now().Format("2006-01-02")
  1573. }
  1574. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1575. if parseDateErr != nil {
  1576. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1578. return
  1579. }
  1580. // data := make(map[string]interface{}, 0)
  1581. var data models.AssessmentAfterDislysis
  1582. var err error
  1583. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1584. fmt.Println(err)
  1585. if err != nil {
  1586. c.ErrorLog("数据解析错误:%v", err)
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1591. assessment.DialysisOrderId = data.DialysisOrderId
  1592. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1593. assessment.Status = 1
  1594. assessment.WeightAfter = data.WeightAfter
  1595. assessment.WeightLoss = data.WeightLoss
  1596. assessment.Temperature = data.Temperature
  1597. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1598. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1599. assessment.PulseFrequency = data.PulseFrequency
  1600. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1601. assessment.ActualDisplacement = data.ActualDisplacement
  1602. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1603. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1604. assessment.Cruor = data.Cruor
  1605. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1606. assessment.DialysisIntakes = data.DialysisIntakes
  1607. assessment.InternalFistula = data.InternalFistula
  1608. assessment.BloodAccessPartId = data.BloodAccessPartId
  1609. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1610. assessment.Catheter = data.Catheter
  1611. assessment.Complication = data.Complication
  1612. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1613. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1614. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1615. assessment.PatientGose = data.PatientGose
  1616. assessment.InpatientDepartment = data.InpatientDepartment
  1617. assessment.ObservationContent = data.ObservationContent
  1618. assessment.ObservationContentOther = data.ObservationContentOther
  1619. assessment.Remark = data.Remark
  1620. assessment.BreathingRate = data.BreathingRate
  1621. assessment.DialysisProcess = data.DialysisProcess
  1622. assessment.InAdvanceMinute = data.InAdvanceMinute
  1623. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1624. assessment.InAdvanceReason = data.InAdvanceReason
  1625. assessment.HemostasisOpera = data.HemostasisOpera
  1626. assessment.HemostasisMinute = data.HemostasisMinute
  1627. assessment.TremorNoise = data.TremorNoise
  1628. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1629. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1630. assessment.ArterialTube = data.ArterialTube
  1631. assessment.IntravenousTube = data.IntravenousTube
  1632. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1633. assessment.Dialyzer = data.Dialyzer
  1634. assessment.IsEat = data.IsEat
  1635. assessment.CvcA = data.CvcA
  1636. assessment.CvcV = data.CvcV
  1637. assessment.Channel = data.Channel
  1638. assessment.ReturnBlood = data.ReturnBlood
  1639. assessment.RehydrationVolume = data.RehydrationVolume
  1640. assessment.DialysisDuring = data.DialysisDuring
  1641. assessment.StrokeVolume = data.StrokeVolume
  1642. assessment.BloodFlow = data.BloodFlow
  1643. assessment.SealingFluidDispose = data.SealingFluidDispose
  1644. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1645. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1646. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1647. assessment.SettingPressure = data.SettingPressure
  1648. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1649. assessment.DiastolicPressure = data.DiastolicPressure
  1650. assessment.AdditionalWeight = data.AdditionalWeight
  1651. assessment.OtherComplication = data.OtherComplication
  1652. assessment.Ktv = data.Ktv
  1653. assessment.Urr = data.Urr
  1654. assessment.Hypertenison = data.Hypertenison
  1655. assessment.Hypopiesia = data.Hypopiesia
  1656. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1657. assessment.Lapse = data.Lapse
  1658. assessment.Consciousness = data.Consciousness
  1659. assessment.Fallrisk = data.Fallrisk
  1660. assessment.MachineRun = data.MachineRun
  1661. assessment.AfterUrea = data.AfterUrea
  1662. assessment.PipCoagulation = data.PipCoagulation
  1663. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1664. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1665. if assessment.ID > 0 {
  1666. if appRole.UserType == 2 || appRole.UserType == 1 {
  1667. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1668. assessment.AssessmentTime = time.Now().Unix()
  1669. } else {
  1670. if assessment.Creater == 0 {
  1671. assessment.Modifier = adminUserInfo.AdminUser.Id
  1672. assessment.Creater = adminUserInfo.AdminUser.Id
  1673. } else {
  1674. assessment.Modifier = adminUserInfo.AdminUser.Id
  1675. }
  1676. }
  1677. assessment.UpdatedTime = time.Now().Unix()
  1678. // 查询信息规挡的设置天数
  1679. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1680. if infor.ID > 0 {
  1681. var cha_time int64
  1682. timeNowStr := time.Now().Format("2006-01-02")
  1683. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1684. //今日的日期减去设置的日期
  1685. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1686. if cha_time >= recordDate.Unix() {
  1687. //查询审核是否允许
  1688. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1689. //申请状态不允许的情况 拒绝修改
  1690. if infor.ApplicationStatus != 1 {
  1691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1692. return
  1693. }
  1694. }
  1695. }
  1696. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1697. finish := models.XtDialysisFinish{
  1698. IsFinish: 1,
  1699. UserOrgId: adminUserInfo.CurrentOrgId,
  1700. Status: 1,
  1701. Ctime: time.Now().Unix(),
  1702. Mtime: 0,
  1703. Module: 9,
  1704. RecordDate: recordDate.Unix(),
  1705. Sourse: 1,
  1706. }
  1707. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1)
  1708. if dialysisFinish.ID == 0 {
  1709. service.CreateDialysisFinish(finish)
  1710. }
  1711. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1712. redis := service.RedisClient()
  1713. //清空key 值
  1714. redis.Set(key, "", time.Second)
  1715. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1716. redis.Set(keyThree, "", time.Second)
  1717. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1718. redis.Set(keyTwo, "", time.Second)
  1719. defer redis.Close()
  1720. } else {
  1721. if appRole.UserType == 2 || appRole.UserType == 1 {
  1722. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1723. assessment.AssessmentTime = time.Now().Unix()
  1724. } else {
  1725. assessment.Creater = adminUserInfo.AdminUser.Id
  1726. }
  1727. assessment.CreatedTime = time.Now().Unix()
  1728. assessment.UpdatedTime = time.Now().Unix()
  1729. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1730. assessment.PatientId = patient
  1731. assessment.AssessmentDate = recordDate.Unix()
  1732. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1733. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1734. redis := service.RedisClient()
  1735. //清空key 值
  1736. redis.Set(key, "", time.Second)
  1737. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1738. redis.Set(keyThree, "", time.Second)
  1739. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1740. redis.Set(keyTwo, "", time.Second)
  1741. defer redis.Close()
  1742. }
  1743. if err != nil {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1745. return
  1746. }
  1747. c.ServeSuccessJSON(map[string]interface{}{
  1748. "AssessmentAfterDislysis": &assessment,
  1749. })
  1750. }
  1751. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1752. patient, _ := c.GetInt64("patient", 0)
  1753. recordDateStr := c.GetString("record_date")
  1754. if patient <= 0 {
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1756. return
  1757. }
  1758. adminUserInfo := c.GetAdminUserInfo()
  1759. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1760. if patientInfo.ID == 0 {
  1761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1762. return
  1763. }
  1764. if len(recordDateStr) == 0 {
  1765. recordDateStr = time.Now().Format("2006-01-02")
  1766. }
  1767. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1768. if parseDateErr != nil {
  1769. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1771. return
  1772. }
  1773. weight_before, _ := c.GetFloat("weight_before", 0)
  1774. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1775. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1776. temperature, _ := c.GetFloat("temperature", 0)
  1777. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1778. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1779. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1780. last_post_dialysis := c.GetString("last_post_dialysis")
  1781. dialysis_interphase := c.GetString("dialysis_interphase")
  1782. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1783. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1784. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1785. bloodAccessPartId := c.GetString("blood_access_part_id")
  1786. internalFistula := c.GetString("internal_fistula")
  1787. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1788. catheter := c.GetString("catheter")
  1789. catheter_bend, _ := c.GetInt("catheter_bend")
  1790. complication := c.GetString("complication")
  1791. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1792. hemorrhage := c.GetString("hemorrhage")
  1793. hemorrhage_other := c.GetString("hemorrhage_other")
  1794. remark := c.GetString("remark")
  1795. puncture_method := c.GetString("puncture_method")
  1796. dialysis_count := c.GetString("dialysis_count")
  1797. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1798. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1799. ductus_arantii := c.GetString("ductus_arantii")
  1800. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1801. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1802. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1803. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1804. puncture_way := c.GetString("puncture_way")
  1805. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1806. internal_fistula_other := c.GetString("internal_fistula_other")
  1807. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1808. breathing_rate := c.GetString("breathing_rate")
  1809. is_infect, _ := c.GetInt64("is_infect", 0)
  1810. exposed, _ := c.GetFloat("exposed", 0)
  1811. skin := c.GetString("skin")
  1812. skin_other := c.GetString("skin_other")
  1813. infect_other := c.GetString("infect_other")
  1814. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1815. machine_type := c.GetString("machine_type")
  1816. puncture_needle := c.GetString("puncture_needle")
  1817. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1818. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1819. phinholing := c.GetString("pinholing")
  1820. catheter_suture := c.GetString("catheter_suture")
  1821. catheter_suture_other := c.GetString("catheter_suture_other")
  1822. edema := c.GetString("edema")
  1823. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1824. special_treatment := c.GetString("special_treatment")
  1825. catheter_maintenance := c.GetString("catheter_maintenance")
  1826. thrombusType := c.GetString("thromubus_type")
  1827. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1828. thrombus_a := c.GetString("thromubus_a")
  1829. thrombus_av := c.GetString("thrombus_av")
  1830. thrombus_v := c.GetString("thromubus_v")
  1831. dehydration := c.GetString("dehydration")
  1832. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1833. period, _ := c.GetInt64("period")
  1834. estimated_food_intake := c.GetString("estimated_food_intake")
  1835. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1836. urea_befor := c.GetString("urea_befor")
  1837. suction := c.GetString("suction")
  1838. weight_befor_remake := c.GetString("weight_befor_remake")
  1839. height := c.GetString("height")
  1840. age := c.GetString("age")
  1841. his_department := c.GetString("his_department")
  1842. his_bed := c.GetString("his_bed")
  1843. point_puncture := c.GetString("point_puncture")
  1844. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1845. DialysisCount: dialysis_count,
  1846. EmergencyTreatment: emergency_treatment,
  1847. EmergencyTreatmentOther: emergency_treatment_other,
  1848. DuctusArantii: ductus_arantii,
  1849. VenousCatheterization: venous_catheterization,
  1850. VenousCatheterizationPart: venous_catheterization_part,
  1851. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1852. PunctureWay: puncture_way,
  1853. BloodAccessInternalFistula: blood_access_internal_fistula,
  1854. BloodAccessNoise: blood_access_noise,
  1855. InternalFistulaOther: internal_fistula_other,
  1856. Evaluator: adminUserInfo.AdminUser.Id,
  1857. UserOrgId: adminUserInfo.CurrentOrgId,
  1858. PatientId: patient,
  1859. AssessmentDate: recordDate.Unix(),
  1860. Temperature: temperature,
  1861. PulseFrequency: pulse_frequency,
  1862. SystolicBloodPressure: systolic_blood_pressure,
  1863. DiastolicBloodPressure: diastolic_blood_pressure,
  1864. WeightBefore: weight_before,
  1865. DryWeight: dry_weight,
  1866. AdditionalWeight: additional_weight,
  1867. DialysisInterphase: dialysis_interphase,
  1868. LastPostDialysis: last_post_dialysis,
  1869. SymptomBeforeDialysis: symptom_before_dialysis,
  1870. InternalFistula: internalFistula,
  1871. InternalFistulaSkin: internal_fistula_skin,
  1872. Catheter: catheter,
  1873. CatheterBend: catheter_bend,
  1874. Complication: complication,
  1875. CreatedTime: time.Now().Unix(),
  1876. Status: 1,
  1877. Remark: remark,
  1878. IsHemorrhage: is_hemorrhage,
  1879. Hemorrhage: hemorrhage,
  1880. HemorrhageOther: hemorrhage_other,
  1881. BloodAccessPartId: bloodAccessPartId,
  1882. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1883. PunctureMethod: puncture_method,
  1884. BreathingRate: breathing_rate,
  1885. IsInfect: is_infect,
  1886. Exposed: exposed,
  1887. Skin: skin,
  1888. SkinOther: skin_other,
  1889. InfectOther: infect_other,
  1890. DuctusArantiiOther: ductus_arantii_other,
  1891. MachineType: machine_type,
  1892. PunctureNeedle: puncture_needle,
  1893. HumorExcessiveSymptom: humor_excessive_symptom,
  1894. Phinholing: phinholing,
  1895. CatheterSuture: catheter_suture,
  1896. CatheterSutureOther: catheter_suture_other,
  1897. Edema: edema,
  1898. UrineVolume: urine_volume,
  1899. SpecialTreatment: special_treatment,
  1900. CatheterMaintenance: catheter_maintenance,
  1901. ThromubusType: thrombusInt,
  1902. ThrombusAv: thrombus_av,
  1903. ThromubusA: thrombus_a,
  1904. ThromubusV: thrombus_v,
  1905. Dehydration: dehydration,
  1906. PreDialysisDrugs: pre_dialysis_drugs,
  1907. Period: period,
  1908. EstimatedFoodIntake: estimated_food_intake,
  1909. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1910. UreaBefor: urea_befor,
  1911. Suction: suction,
  1912. WeightBeforRemake: weight_befor_remake,
  1913. Height: height,
  1914. Age: age,
  1915. HisDepartment: his_department,
  1916. HisBed: his_bed,
  1917. PointPuncture: point_puncture,
  1918. }
  1919. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1920. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1921. if evaluation.ID == 0 { //新增
  1922. if appRole.UserType == 2 || appRole.UserType == 1 {
  1923. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1924. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1925. } else {
  1926. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1927. }
  1928. // 查询信息规挡的设置天数
  1929. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1930. if infor.ID > 0 {
  1931. var cha_time int64
  1932. timeNowStr := time.Now().Format("2006-01-02")
  1933. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1934. //今日的日期减去设置的日期
  1935. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1936. if cha_time >= recordDate.Unix() {
  1937. //查询审核是否允许
  1938. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1939. //申请状态不允许的情况 拒绝修改
  1940. if infor.ApplicationStatus != 1 {
  1941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1942. return
  1943. }
  1944. }
  1945. }
  1946. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1947. //创建步骤表
  1948. finish := models.XtDialysisFinish{
  1949. IsFinish: 1,
  1950. UserOrgId: adminUserInfo.CurrentOrgId,
  1951. Status: 1,
  1952. Ctime: time.Now().Unix(),
  1953. Mtime: 0,
  1954. Module: 3,
  1955. RecordDate: recordDate.Unix(),
  1956. Sourse: 1,
  1957. }
  1958. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3)
  1959. if dialysisFinish.ID == 0 {
  1960. service.CreateDialysisFinish(finish)
  1961. }
  1962. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1963. var dewater_amount float64
  1964. dewater_amount = 0
  1965. if dry_weight > 0 {
  1966. dewater_amount = weight_before - dry_weight - additional_weight
  1967. dewater_amount = dewater_amount * 1000
  1968. if dewater_amount <= 0 {
  1969. dewater_amount = 0
  1970. }
  1971. } else {
  1972. dewater_amount = 0
  1973. }
  1974. // 计算透析处方的相关超滤量
  1975. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1976. var lastDialysisPrescribe *models.DialysisPrescription
  1977. var dialysisSolution *models.DialysisSolution
  1978. var dialysisPrescribe *models.DialysisPrescription
  1979. var mode_id int64
  1980. if schedual != nil {
  1981. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1982. if dialysisPrescribe == nil {
  1983. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1984. }
  1985. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1986. // 获取透析模版
  1987. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1988. mode_id = schedual.ModeId
  1989. } else {
  1990. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1991. // 获取透析模版
  1992. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1993. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1994. if dialysisPrescribe == nil && dialysisSolution != nil {
  1995. mode_id = dialysisSolution.ModeId
  1996. }
  1997. if dialysisPrescribe == nil && dialysisSolution == nil {
  1998. mode_id = 0
  1999. }
  2000. }
  2001. // 插入透析处方
  2002. if dialysisPrescribe == nil && dialysisSolution != nil {
  2003. var newprescribe models.DialysisPrescription
  2004. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2005. newprescribe.PatientId = dialysisSolution.PatientId
  2006. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2007. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2008. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2009. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2010. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2011. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2012. newprescribe.ModeId = dialysisSolution.ModeId
  2013. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2014. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2015. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2016. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2017. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2018. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2019. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2020. newprescribe.Glucose = dialysisSolution.Glucose
  2021. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2022. newprescribe.Kalium = dialysisSolution.Kalium
  2023. newprescribe.Sodium = dialysisSolution.Sodium
  2024. newprescribe.Calcium = dialysisSolution.Calcium
  2025. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2026. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2027. newprescribe.Conductivity = dialysisSolution.Conductivity
  2028. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2029. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2030. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2031. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2032. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2033. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2034. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2035. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2036. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2037. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2038. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2039. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2040. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2041. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2042. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2043. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2044. newprescribe.CreatedTime = time.Now().Unix()
  2045. newprescribe.UpdatedTime = time.Now().Unix()
  2046. newprescribe.RecordDate = recordDate.Unix()
  2047. newprescribe.DewaterAmount = dewater_amount
  2048. newprescribe.TargetUltrafiltration = dewater_amount
  2049. newprescribe.Status = 1
  2050. err := service.AddSigleRecord(&newprescribe)
  2051. if err != nil {
  2052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2053. }
  2054. }
  2055. if dialysisPrescribe == nil && dialysisSolution == nil {
  2056. if lastDialysisPrescribe != nil {
  2057. var newprescribe models.DialysisPrescription
  2058. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2059. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2060. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2061. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2062. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2063. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2064. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2065. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2066. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2067. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2068. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2069. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2070. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2071. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2072. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2073. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2074. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2075. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2076. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2077. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2078. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2079. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2080. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2081. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2082. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2083. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2084. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2085. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2086. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2087. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2088. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2089. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2090. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2091. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2092. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2093. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2094. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2095. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2096. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2097. newprescribe.CreatedTime = time.Now().Unix()
  2098. newprescribe.UpdatedTime = time.Now().Unix()
  2099. newprescribe.RecordDate = recordDate.Unix()
  2100. newprescribe.DewaterAmount = dewater_amount
  2101. newprescribe.TargetUltrafiltration = dewater_amount
  2102. newprescribe.Status = 1
  2103. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2104. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2105. err := service.AddSigleRecord(&newprescribe)
  2106. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2107. redis := service.RedisClient()
  2108. defer redis.Close()
  2109. //清空key 值
  2110. redis.Set(key, "", time.Second)
  2111. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2112. redis.Set(keyOne, "", time.Second)
  2113. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2114. redis.Set(keyThree, "", time.Second)
  2115. if err != nil {
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2117. }
  2118. } else {
  2119. var newprescribe models.DialysisPrescription
  2120. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2121. newprescribe.PatientId = patient
  2122. newprescribe.ModeId = mode_id
  2123. newprescribe.CreatedTime = time.Now().Unix()
  2124. newprescribe.UpdatedTime = time.Now().Unix()
  2125. newprescribe.RecordDate = recordDate.Unix()
  2126. newprescribe.DewaterAmount = dewater_amount
  2127. newprescribe.TargetUltrafiltration = dewater_amount
  2128. newprescribe.Status = 1
  2129. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2130. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2131. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2132. err := service.AddSigleRecord(&newprescribe)
  2133. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2134. redis := service.RedisClient()
  2135. defer redis.Close()
  2136. //清空key 值
  2137. redis.Set(key, "", time.Second)
  2138. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2139. redis.Set(keyOne, "", time.Second)
  2140. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2141. redis.Set(keyThree, "", time.Second)
  2142. if err != nil {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2144. }
  2145. }
  2146. }
  2147. }
  2148. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2149. redis := service.RedisClient()
  2150. //清空key 值
  2151. redis.Set(key, "", time.Second)
  2152. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2153. redis.Set(keyOne, "", time.Second)
  2154. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2155. redis.Set(keyTwo, "", time.Second)
  2156. defer redis.Close()
  2157. if err == nil {
  2158. c.ServeSuccessJSON(map[string]interface{}{
  2159. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2160. })
  2161. } else {
  2162. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2164. }
  2165. } else { //修改
  2166. //if appRole.UserType == 3 {
  2167. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2168. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2169. // if getPermissionErr != nil {
  2170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. // return
  2172. // } else if headNursePermission == nil {
  2173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2174. // return
  2175. // }
  2176. // }
  2177. //}
  2178. if appRole.UserType == 2 || appRole.UserType == 1 {
  2179. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2180. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2181. } else {
  2182. if evaluation.Creater == 0 {
  2183. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2184. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2185. } else {
  2186. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2187. }
  2188. }
  2189. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2190. assessmentBeforeDislysis.ID = evaluation.ID
  2191. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2192. //
  2193. //新增逻辑
  2194. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2195. var dewater_amount float64
  2196. dewater_amount = 0
  2197. if evaluation.DryWeight > 0 {
  2198. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2199. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2200. dewater_amount = dewater_amount * 1000
  2201. }
  2202. if dewater_amount <= 0 {
  2203. dewater_amount = 0
  2204. }
  2205. } else {
  2206. dewater_amount = 0
  2207. }
  2208. // 计算透析处方的相关超滤量
  2209. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2210. var lastDialysisPrescribe *models.DialysisPrescription
  2211. var dialysisSolution *models.DialysisSolution
  2212. var dialysisPrescribe *models.DialysisPrescription
  2213. var mode_id int64
  2214. if schedual != nil {
  2215. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2216. if dialysisPrescribe == nil {
  2217. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2218. }
  2219. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2220. // 获取透析模版
  2221. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2222. mode_id = schedual.ModeId
  2223. } else {
  2224. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2225. // 获取透析模版
  2226. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2227. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2228. if dialysisPrescribe == nil && dialysisSolution != nil {
  2229. mode_id = dialysisSolution.ModeId
  2230. }
  2231. if dialysisPrescribe == nil && dialysisSolution == nil {
  2232. mode_id = 0
  2233. }
  2234. }
  2235. // 插入透析处方
  2236. if dialysisPrescribe == nil && dialysisSolution != nil {
  2237. var newprescribe models.DialysisPrescription
  2238. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2239. newprescribe.PatientId = dialysisSolution.PatientId
  2240. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2241. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2242. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2243. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2244. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2245. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2246. newprescribe.ModeId = dialysisSolution.ModeId
  2247. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2248. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2249. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2250. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2251. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2252. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2253. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2254. newprescribe.Glucose = dialysisSolution.Glucose
  2255. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2256. newprescribe.Kalium = dialysisSolution.Kalium
  2257. newprescribe.Sodium = dialysisSolution.Sodium
  2258. newprescribe.Calcium = dialysisSolution.Calcium
  2259. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2260. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2261. newprescribe.Conductivity = dialysisSolution.Conductivity
  2262. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2263. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2264. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2265. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2266. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2267. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2268. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2269. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2270. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2271. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2272. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2273. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2274. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2275. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2276. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2277. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2278. newprescribe.CreatedTime = time.Now().Unix()
  2279. newprescribe.UpdatedTime = time.Now().Unix()
  2280. newprescribe.RecordDate = recordDate.Unix()
  2281. newprescribe.DewaterAmount = dewater_amount
  2282. newprescribe.TargetUltrafiltration = dewater_amount
  2283. newprescribe.Status = 1
  2284. err := service.AddSigleRecord(&newprescribe)
  2285. if err != nil {
  2286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2287. }
  2288. }
  2289. if dialysisPrescribe == nil && dialysisSolution == nil {
  2290. if lastDialysisPrescribe != nil {
  2291. var newprescribe models.DialysisPrescription
  2292. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2293. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2294. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2295. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2296. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2297. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2298. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2299. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2300. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2301. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2302. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2303. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2304. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2305. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2306. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2307. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2308. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2309. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2310. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2311. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2312. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2313. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2314. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2315. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2316. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2317. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2318. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2319. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2320. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2321. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2322. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2323. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2324. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2325. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2326. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2327. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2328. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2329. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2330. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2331. newprescribe.CreatedTime = time.Now().Unix()
  2332. newprescribe.UpdatedTime = time.Now().Unix()
  2333. newprescribe.RecordDate = recordDate.Unix()
  2334. newprescribe.DewaterAmount = dewater_amount
  2335. newprescribe.TargetUltrafiltration = dewater_amount
  2336. newprescribe.Status = 1
  2337. err := service.AddSigleRecord(&newprescribe)
  2338. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2339. redis := service.RedisClient()
  2340. defer redis.Close()
  2341. //清空key 值
  2342. redis.Set(key, "", time.Second)
  2343. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2344. redis.Set(keyOne, "", time.Second)
  2345. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2346. redis.Set(keyThree, "", time.Second)
  2347. if err != nil {
  2348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2349. }
  2350. } else {
  2351. var newprescribe models.DialysisPrescription
  2352. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2353. newprescribe.PatientId = patient
  2354. newprescribe.ModeId = mode_id
  2355. newprescribe.CreatedTime = time.Now().Unix()
  2356. newprescribe.UpdatedTime = time.Now().Unix()
  2357. newprescribe.RecordDate = recordDate.Unix()
  2358. newprescribe.DewaterAmount = dewater_amount
  2359. newprescribe.TargetUltrafiltration = dewater_amount
  2360. newprescribe.Status = 1
  2361. err := service.AddSigleRecord(&newprescribe)
  2362. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2363. redis := service.RedisClient()
  2364. defer redis.Close()
  2365. //清空key 值
  2366. redis.Set(key, "", time.Second)
  2367. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2368. redis.Set(keyOne, "", time.Second)
  2369. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2370. redis.Set(keyThree, "", time.Second)
  2371. if err != nil {
  2372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2373. }
  2374. }
  2375. }
  2376. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2377. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2378. redis := service.RedisClient()
  2379. //清空key 值
  2380. redis.Set(key, "", time.Second)
  2381. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2382. redis.Set(keyOne, "", time.Second)
  2383. defer redis.Close()
  2384. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2385. redis.Set(keyTwo, "", time.Second)
  2386. if err == nil {
  2387. c.ServeSuccessJSON(map[string]interface{}{
  2388. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2389. })
  2390. } else {
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2392. }
  2393. }
  2394. }
  2395. func (c *DialysisApiController) PostTreatmentSummary() {
  2396. patient, _ := c.GetInt64("patient", 0)
  2397. recordDateStr := c.GetString("record_date")
  2398. if patient <= 0 {
  2399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2400. return
  2401. }
  2402. adminUserInfo := c.GetAdminUserInfo()
  2403. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2404. if patientInfo.ID == 0 {
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2406. return
  2407. }
  2408. if len(recordDateStr) == 0 {
  2409. recordDateStr = time.Now().Format("2006-01-02")
  2410. }
  2411. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2412. if parseDateErr != nil {
  2413. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2415. return
  2416. }
  2417. mission := c.GetString("mission")
  2418. dialysis_summary := c.GetString("dialysis_summary")
  2419. nursingRecord := c.GetString("nursing_record")
  2420. specialRecord := c.GetString("special_record")
  2421. sj_nurse := adminUserInfo.AdminUser.Id
  2422. zl_nurse := adminUserInfo.AdminUser.Id
  2423. hd_nurse := adminUserInfo.AdminUser.Id
  2424. xj_nurse := adminUserInfo.AdminUser.Id
  2425. zl_doctor := adminUserInfo.AdminUser.Id
  2426. treatmentSummary := models.TreatmentSummary{
  2427. UserOrgId: adminUserInfo.CurrentOrgId,
  2428. PatientId: patient,
  2429. AssessmentDate: recordDate.Unix(),
  2430. Mission: mission,
  2431. DialysisSummary: dialysis_summary,
  2432. SjNurse: sj_nurse,
  2433. ZlNurse: zl_nurse,
  2434. HdNurse: hd_nurse,
  2435. XjNurse: xj_nurse,
  2436. ZlDoctor: zl_doctor,
  2437. Status: 1,
  2438. CreatedTime: time.Now().Unix(),
  2439. NursingRecord: nursingRecord,
  2440. SpecialRecord: specialRecord,
  2441. }
  2442. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2443. if tempTreatmentSummary.ID == 0 { //新增
  2444. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2445. // 查询信息规挡的设置天数
  2446. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2447. if infor.ID > 0 {
  2448. var cha_time int64
  2449. timeNowStr := time.Now().Format("2006-01-02")
  2450. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2451. //今日的日期减去设置的日期
  2452. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2453. if cha_time >= recordDate.Unix() {
  2454. //查询审核是否允许
  2455. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2456. //申请状态不允许的情况 拒绝修改
  2457. if infor.ApplicationStatus != 1 {
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2459. return
  2460. }
  2461. }
  2462. }
  2463. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2464. finish := models.XtDialysisFinish{
  2465. IsFinish: 1,
  2466. UserOrgId: adminUserInfo.CurrentOrgId,
  2467. Status: 1,
  2468. Ctime: time.Now().Unix(),
  2469. Mtime: 0,
  2470. Module: 10,
  2471. RecordDate: recordDate.Unix(),
  2472. Sourse: 1,
  2473. }
  2474. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10)
  2475. if dialysisFinish.ID == 0 {
  2476. service.CreateDialysisFinish(finish)
  2477. }
  2478. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2479. redis := service.RedisClient()
  2480. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2481. redis.Set(keyOne, "", time.Second)
  2482. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2483. redis.Set(keyThree, "", time.Second)
  2484. defer redis.Close()
  2485. //清空key 值
  2486. redis.Set(key, "", time.Second)
  2487. if err == nil {
  2488. c.ServeSuccessJSON(map[string]interface{}{
  2489. "summary": treatmentSummary,
  2490. })
  2491. } else {
  2492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2493. }
  2494. } else { //修改
  2495. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2496. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2497. // if getPermissionErr != nil {
  2498. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2499. // return
  2500. // } else if headNursePermission == nil {
  2501. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2502. // return
  2503. // }
  2504. //}
  2505. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2506. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2507. treatmentSummary.UpdatedTime = time.Now().Unix()
  2508. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2509. treatmentSummary.ID = tempTreatmentSummary.ID
  2510. err := service.UpdateSummeRecord(&treatmentSummary)
  2511. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2512. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2513. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2514. //清空key 值
  2515. redis := service.RedisClient()
  2516. redis.Set(key, "", time.Second)
  2517. redis.Set(keyOne, "", time.Second)
  2518. redis.Set(keyThree, "", time.Second)
  2519. defer redis.Close()
  2520. if err == nil {
  2521. c.ServeSuccessJSON(map[string]interface{}{
  2522. "summary": treatmentSummary,
  2523. })
  2524. } else {
  2525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2526. }
  2527. }
  2528. }
  2529. func (c *DialysisApiController) GetDeviceList() {
  2530. adminUserInfo := c.GetAdminUserInfo()
  2531. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "device": device,
  2534. })
  2535. }
  2536. func (c *DialysisApiController) GetAllDeviceZone() {
  2537. adminUserInfo := c.GetAdminUserInfo()
  2538. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2539. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2540. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2541. if err == nil {
  2542. c.ServeSuccessJSON(map[string]interface{}{
  2543. "zone": zone,
  2544. "dics": dics,
  2545. "efs": efs,
  2546. })
  2547. }
  2548. }
  2549. func (c *DialysisApiController) GetDialysisWatch() {
  2550. page, _ := c.GetInt64("page", 1)
  2551. limit, _ := c.GetInt64("limit", 10)
  2552. schedulType, _ := c.GetInt64("schedul_type", 0)
  2553. startTime, _ := c.GetInt64("schedul_time", 0)
  2554. partitionType, _ := c.GetInt64("partition_type", 0)
  2555. keywords := c.GetString("keywords")
  2556. start_time, _ := c.GetInt64("start_time")
  2557. end_time, _ := c.GetInt64("end_time")
  2558. adminUserInfo := c.GetAdminUserInfo()
  2559. if len(keywords) > 0 {
  2560. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2561. if err == nil {
  2562. c.ServeSuccessJSON(map[string]interface{}{
  2563. "schedule": dialysisSchedule,
  2564. "total": total,
  2565. })
  2566. } else {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2568. }
  2569. } else {
  2570. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2571. if err == nil {
  2572. c.ServeSuccessJSON(map[string]interface{}{
  2573. "schedule": dialysisSchedule,
  2574. "total": total,
  2575. })
  2576. } else {
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2578. }
  2579. }
  2580. }
  2581. //func (c *DialysisApiController) GetDialysisWatch() {
  2582. // page, _ := c.GetInt64("page", 1)
  2583. // limit, _ := c.GetInt64("limit", 10)
  2584. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2585. // startTime, _ := c.GetInt64("schedul_time", 0)
  2586. // partitionType, _ := c.GetInt64("partition_type", 0)
  2587. // keywords := c.GetString("keywords")
  2588. //
  2589. // adminUserInfo := c.GetAdminUserInfo()
  2590. // if len(keywords) > 0 {
  2591. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2592. //
  2593. // //获取所有床位号
  2594. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2595. //
  2596. // //获取透析处方
  2597. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2598. // //获取透前评估
  2599. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2600. // //获取上机
  2601. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2602. // //获取透后
  2603. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2604. //
  2605. // //获取透后监测
  2606. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2607. //
  2608. // //获取所有的患者
  2609. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2610. //
  2611. // //获取所有透析模式
  2612. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2613. //
  2614. // for key, scheduals := range dialysisSchedule {
  2615. // // 获取患者信息
  2616. // for _, patient := range patients {
  2617. // if scheduals.PatientId == patient.ID {
  2618. // dialysisSchedule[key].MonitorPatients = patient
  2619. // break
  2620. // }
  2621. // }
  2622. // // 床位信息
  2623. // for _, device := range numberList {
  2624. // if scheduals.BedId == device.ID {
  2625. // dialysisSchedule[key].DeviceNumber = device
  2626. // break
  2627. // }
  2628. // }
  2629. //
  2630. // // 医嘱信息
  2631. // for _, prescription := range prescriptions {
  2632. // if scheduals.PatientId == prescription.PatientId {
  2633. // dialysisSchedule[key].Prescription = prescription
  2634. // break
  2635. // }
  2636. // }
  2637. //
  2638. // // 透前评估
  2639. // for _, assessmentBefore := range assessmentBefores {
  2640. // if scheduals.PatientId == assessmentBefore.PatientId {
  2641. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2642. // break
  2643. // }
  2644. // }
  2645. //
  2646. // // 透析上下机
  2647. // for _, dialysisOrder := range dialysisOrders {
  2648. // if scheduals.PatientId == dialysisOrder.PatientId {
  2649. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2650. // break
  2651. // }
  2652. // }
  2653. //
  2654. // records := make([]*models.MonitoringRecord, 0)
  2655. // // 透析监测
  2656. // for _, it := range monitorlist {
  2657. // records := append(records, it)
  2658. // if scheduals.PatientId == it.PatientId {
  2659. // dialysisSchedule[key].MonitoringRecord = records
  2660. // }
  2661. // }
  2662. //
  2663. // // 透后评估
  2664. // for _, afterDislysis := range AssessmentAfterDislysis {
  2665. // if scheduals.PatientId == afterDislysis.PatientId {
  2666. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2667. // break
  2668. // }
  2669. // }
  2670. //
  2671. // //透析模式
  2672. // for _, treatment := range treatments {
  2673. // if scheduals.ModeId == treatment.ID {
  2674. // dialysisSchedule[key].TreatmentMode = treatment
  2675. // break
  2676. // }
  2677. // }
  2678. // }
  2679. // //获取所有床位号
  2680. // if err == nil {
  2681. // c.ServeSuccessJSON(map[string]interface{}{
  2682. // "schedule": dialysisSchedule,
  2683. // "total": total,
  2684. // })
  2685. // } else {
  2686. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2687. // }
  2688. //
  2689. // } else {
  2690. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2691. // if err == nil {
  2692. // c.ServeSuccessJSON(map[string]interface{}{
  2693. // "schedule": dialysisSchedule,
  2694. // "total": total,
  2695. // })
  2696. // } else {
  2697. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2698. // }
  2699. // }
  2700. //}
  2701. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2702. patientId, _ := c.GetInt64("id", 0)
  2703. record_date, _ := c.GetInt64("record_date", 0)
  2704. adminUserInfo := c.GetAdminUserInfo()
  2705. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2706. var dialysisStatus int64
  2707. if dialysisOrder == nil { //没有透析记录
  2708. dialysisStatus = 0 //未透析
  2709. } else {
  2710. dialysisStatus = dialysisOrder.Stage
  2711. }
  2712. //用户基本信息
  2713. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2714. //接诊评估
  2715. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2716. //透前评估
  2717. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2718. //临时医嘱
  2719. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2720. //双人核对
  2721. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2722. //透析监测
  2723. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2724. //透后评估
  2725. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2726. //透析小结
  2727. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2728. //透析处方
  2729. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2730. if dialysisPrescription.ID == 0 {
  2731. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2732. c.ServeSuccessJSON(map[string]interface{}{
  2733. "patientInfo": schedualPatientInfo,
  2734. "dialysisPrescription": solution,
  2735. "receiverTreatmentAccess": receiverTreatmentAccess,
  2736. "predialysisEvaluation": PredialysisEvaluation,
  2737. "doctorAdvice": DoctorAdvice,
  2738. "doubleCheck": DoubleCheck,
  2739. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2740. "treatmentSummary": TreatmentSummary,
  2741. "monitorRecord": Record,
  2742. "dialysisStatus": dialysisStatus,
  2743. "dialysisOrder": dialysisOrder,
  2744. "isSolution": 1,
  2745. })
  2746. } else {
  2747. c.ServeSuccessJSON(map[string]interface{}{
  2748. "patientInfo": schedualPatientInfo,
  2749. "dialysisPrescription": dialysisPrescription,
  2750. "receiverTreatmentAccess": receiverTreatmentAccess,
  2751. "predialysisEvaluation": PredialysisEvaluation,
  2752. "doctorAdvice": DoctorAdvice,
  2753. "doubleCheck": DoubleCheck,
  2754. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2755. "treatmentSummary": TreatmentSummary,
  2756. "monitorRecord": Record,
  2757. "dialysisStatus": dialysisStatus,
  2758. "dialysisOrder": dialysisOrder,
  2759. "isSolution": 2,
  2760. })
  2761. }
  2762. }
  2763. func (c *DialysisApiController) CreateDoctorAdvice() {
  2764. patient, _ := c.GetInt64("id", 0)
  2765. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2766. record_date, _ := c.GetInt64("record_date", 0)
  2767. if patient <= 0 {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2769. return
  2770. }
  2771. adminUserInfo := c.GetAdminUserInfo()
  2772. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2773. if patientInfo.ID == 0 {
  2774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2775. return
  2776. }
  2777. var advice models.DoctorAdvice
  2778. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2779. if code > 0 {
  2780. c.ServeFailJSONWithSGJErrorCode(code)
  2781. return
  2782. }
  2783. if advice.ParentId > 0 {
  2784. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2785. if old.ID == 0 || old.PatientId != patient {
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2787. return
  2788. }
  2789. if old.StopState == 1 || old.ExecutionState == 1 {
  2790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2791. return
  2792. }
  2793. if old.ParentId > 0 {
  2794. advice.ParentId = old.ParentId
  2795. }
  2796. advice.StartTime = old.StartTime
  2797. advice.AdviceDoctor = old.AdviceDoctor
  2798. advice.DeliveryWay = old.DeliveryWay
  2799. advice.ExecutionFrequency = old.ExecutionFrequency
  2800. }
  2801. advice.RecordDate = record_date
  2802. advice.DialysisOrderId = dialysis_id
  2803. advice.Status = 1
  2804. advice.CreatedTime = time.Now().Unix()
  2805. advice.UpdatedTime = time.Now().Unix()
  2806. advice.StopState = 2
  2807. advice.ExecutionState = 2
  2808. advice.AdviceType = 2
  2809. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2810. advice.PatientId = patient
  2811. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2812. err := service.CreateDoctorAdvice(&advice)
  2813. if err != nil {
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2815. return
  2816. }
  2817. for _, subAdvice := range subAdivice {
  2818. subAdvice.ParentId = advice.ID
  2819. subAdvice.PatientId = patient
  2820. subAdvice.RecordDate = record_date
  2821. subAdvice.CreatedTime = time.Now().Unix()
  2822. subAdvice.UpdatedTime = time.Now().Unix()
  2823. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2824. }
  2825. service.CreateSubDoctorAdvice(subAdivice)
  2826. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2827. c.ServeSuccessJSON(map[string]interface{}{
  2828. "msg": "ok",
  2829. "advice": advice,
  2830. "subAdvice": subAdivices,
  2831. })
  2832. return
  2833. }
  2834. func (c *DialysisApiController) EditDoctorAdvice() {
  2835. patient, _ := c.GetInt64("patient", 0)
  2836. id, _ := c.GetInt64("id", 0)
  2837. parent_id, _ := c.GetInt64("parent_id", 0)
  2838. execution_time := c.GetString("execution_time")
  2839. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2840. // checker, _ := c.GetInt64("checker", 0)
  2841. if id <= 0 || patient <= 0 {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2843. return
  2844. }
  2845. adminUserInfo := c.GetAdminUserInfo()
  2846. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2847. if advice.ID == 0 || advice.PatientId != patient {
  2848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2849. return
  2850. }
  2851. if len(execution_time) <= 0 {
  2852. utils.ErrorLog("execution_time")
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2854. return
  2855. }
  2856. execution_staff := adminUserInfo.AdminUser.Id
  2857. checker := adminUserInfo.AdminUser.Id
  2858. timeLayout2 := "2006-01-02 15:04"
  2859. loc, _ := time.LoadLocation("Local")
  2860. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2861. if errs != nil {
  2862. utils.ErrorLog(errs.Error())
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2864. return
  2865. }
  2866. advices := models.DoctorAdvice{
  2867. ExecutionStaff: execution_staff,
  2868. ExecutionTime: theTime.Unix(),
  2869. Checker: checker,
  2870. UpdatedTime: time.Now().Unix(),
  2871. }
  2872. var err error
  2873. if parent_id > 0 {
  2874. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2875. } else {
  2876. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2877. }
  2878. if err != nil {
  2879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2880. return
  2881. }
  2882. c.ServeSuccessJSON(map[string]interface{}{
  2883. "msg": "ok",
  2884. "advice": advice,
  2885. })
  2886. return
  2887. }
  2888. func (c *DialysisApiController) GetDoctorAdvice() {
  2889. patient, _ := c.GetInt64("patient_id", 0)
  2890. parent_id, _ := c.GetInt64("parent_id", 0)
  2891. adviceId, _ := c.GetInt64("id", 0)
  2892. if patient <= 0 {
  2893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2894. return
  2895. }
  2896. dminUserInfo := c.GetAdminUserInfo()
  2897. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2898. if patientInfo.ID == 0 {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2900. return
  2901. }
  2902. var subAdvice []*models.DoctorAdvice
  2903. var advice models.DoctorAdvice
  2904. if parent_id > 0 {
  2905. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2906. if advice.ID == 0 || advice.PatientId != patient {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2908. return
  2909. }
  2910. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2911. } else {
  2912. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2913. if advice.ID == 0 || advice.PatientId != patient {
  2914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2915. return
  2916. }
  2917. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2918. }
  2919. c.ServeSuccessJSON(map[string]interface{}{
  2920. "msg": "ok",
  2921. "advice": advice,
  2922. "subAdvice": subAdvice,
  2923. })
  2924. }
  2925. func (this *DialysisApiController) DelMonitor() {
  2926. recordID, _ := this.GetInt64("record_id")
  2927. patientID, _ := this.GetInt64("patient_id")
  2928. if recordID <= 0 || patientID <= 0 {
  2929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2930. return
  2931. }
  2932. adminInfo := this.GetAdminUserInfo()
  2933. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2934. if getPatientErr != nil {
  2935. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2937. return
  2938. } else if patient == nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2940. return
  2941. }
  2942. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2943. if getMonitorErr != nil {
  2944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2945. return
  2946. }
  2947. //if monitor != nil {
  2948. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2949. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2950. // if getPermissionErr != nil {
  2951. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2952. // return
  2953. // } else if headNursePermission == nil {
  2954. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2955. // return
  2956. // }
  2957. // }
  2958. //}
  2959. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2960. // 查询信息规挡的设置天数
  2961. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  2962. if infor.ID > 0 {
  2963. var cha_time int64
  2964. timeNowStr := time.Now().Format("2006-01-02")
  2965. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2966. //今日的日期减去设置的日期
  2967. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2968. if cha_time >= monitor.MonitoringDate {
  2969. //查询审核是否允许
  2970. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId)
  2971. //申请状态不允许的情况 拒绝修改
  2972. if infor.ApplicationStatus != 1 {
  2973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2974. return
  2975. }
  2976. }
  2977. }
  2978. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2979. redis := service.RedisClient()
  2980. //清空key 值
  2981. redis.Set(key, "", time.Second)
  2982. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2983. redis.Set(keyOne, "", time.Second)
  2984. defer redis.Close()
  2985. if err != nil {
  2986. this.ErrorLog("删除透析监测记录失败:%v", err)
  2987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2988. return
  2989. }
  2990. this.ServeSuccessJSON(map[string]interface{}{
  2991. "record_id": monitor.ID,
  2992. })
  2993. }
  2994. func (c *DialysisApiController) CreateMonitor() {
  2995. patient, _ := c.GetInt64("id", 0)
  2996. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2997. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2998. operate_time, _ := c.GetInt64("operate_time", 0)
  2999. // monitoring_time := c.GetString("monitoring_time")
  3000. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3001. breathing_rated := c.GetString("breathing_rated")
  3002. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3003. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3004. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3005. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3006. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3007. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3008. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3009. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3010. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3011. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3012. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3013. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3014. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3015. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3016. temperature, _ := c.GetFloat("temperature", 0)
  3017. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3018. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3019. conductivity, _ := c.GetFloat("conductivity", 0)
  3020. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3021. heparin, _ := c.GetFloat("heparin", 0)
  3022. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3023. ktv, _ := c.GetFloat("ktv", 0)
  3024. symptom := c.GetString("symptom")
  3025. dispose := c.GetString("dispose")
  3026. result := c.GetString("results")
  3027. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3028. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3029. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3030. monitoring_date = monitoring_date / 1000
  3031. // operate_time = operate_time / 1000
  3032. if patient <= 0 {
  3033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3034. return
  3035. }
  3036. adminUserInfo := c.GetAdminUserInfo()
  3037. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3038. if patientInfo.ID == 0 {
  3039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3040. return
  3041. }
  3042. monitorRecord := models.MonitoringRecord{
  3043. PatientId: patient,
  3044. MonitoringDate: monitoring_date,
  3045. DialysisOrderId: dialysis_order_id,
  3046. OperateTime: operate_time,
  3047. // MonitoringTime: monitoring_time,
  3048. PulseFrequency: pulse_frequency,
  3049. BreathingRate: breathing_rated,
  3050. SystolicBloodPressure: systolic_blood_pressure,
  3051. DiastolicBloodPressure: diastolic_blood_pressure,
  3052. BloodPressureType: blood_pressure_type,
  3053. BloodFlowVolume: blood_flow_volume,
  3054. VenousPressure: venous_pressure,
  3055. VenousPressureType: venous_pressure_type,
  3056. TransmembranePressure: transmembrane_pressure,
  3057. TransmembranePressureType: transmembrane_pressure_type,
  3058. UltrafiltrationRate: ultrafiltration_rate,
  3059. UltrafiltrationVolume: ultrafiltration_volume,
  3060. SodiumConcentration: sodium_concentration,
  3061. ArterialPressure: arterial_pressure,
  3062. ArterialPressureType: arterial_pressure_type,
  3063. DialysateTemperature: dialysate_temperature,
  3064. Temperature: temperature,
  3065. ReplacementRate: replacement_rate,
  3066. DisplacementQuantity: displacement_quantity,
  3067. Ktv: ktv,
  3068. Symptom: symptom,
  3069. Dispose: dispose,
  3070. Result: result,
  3071. MonitoringNurse: monitoring_nurse,
  3072. Status: 1,
  3073. CreatedTime: time.Now().Unix(),
  3074. UpdatedTime: time.Now().Unix(),
  3075. UserOrgId: adminUserInfo.CurrentOrgId,
  3076. Conductivity: conductivity,
  3077. DisplacementFlowQuantity: displacement_flow_quantity,
  3078. Heparin: heparin,
  3079. DialysateFlow: dialysate_flow,
  3080. MonitorAnticoagulant: monitor_anticoagulant,
  3081. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3082. }
  3083. err := service.CreateMonitor(&monitorRecord)
  3084. redis := service.RedisClient()
  3085. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3086. redis.Set(key, "", time.Second)
  3087. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3088. redis.Set(keyOne, "", time.Second)
  3089. redis.Close()
  3090. if err != nil {
  3091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3092. return
  3093. }
  3094. c.ServeSuccessJSON(map[string]interface{}{
  3095. "msg": "ok",
  3096. "monitor": monitorRecord,
  3097. })
  3098. return
  3099. }
  3100. // 已弃用
  3101. // func (c *DialysisApiController) CreateRecordData() {
  3102. // patient, _ := c.GetInt64("id", 0)
  3103. // status, _ := c.GetInt64("status", 0)
  3104. // now := time.Now()
  3105. // year, month, day := now.Date()
  3106. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3107. // todayTimeStamp := today_time.Unix()
  3108. // if patient <= 0 {
  3109. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3110. // return
  3111. // }
  3112. // adminUserInfo := c.GetAdminUserInfo()
  3113. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3114. // if patientInfo.ID == 0 {
  3115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3116. // return
  3117. // }
  3118. // record := &models.DialysisOrder{
  3119. // DialysisDate: todayTimeStamp,
  3120. // UserOrgId: adminUserInfo.CurrentOrgId,
  3121. // PatientId: patient,
  3122. // Stage: status,
  3123. // Status: 1,
  3124. // CreatedTime: time.Now().Unix(),
  3125. // UpdatedTime: time.Now().Unix(),
  3126. // }
  3127. // if status == 1 {
  3128. // //创建透析记录
  3129. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3130. // if err == nil {
  3131. // c.ServeSuccessJSON(map[string]interface{}{
  3132. // "dialysisOrder": record,
  3133. // })
  3134. // } else {
  3135. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3136. // }
  3137. // } else {
  3138. // record_id, _ := c.GetInt64("record_id", 0)
  3139. // //修改透析记录状态
  3140. // errs := service.ModifyDialysisRecord(record_id)
  3141. // //结束时候透析次数加1
  3142. // service.UpdateSolutionByPatientId(patient)
  3143. // if errs == nil {
  3144. // c.ServeSuccessJSON(map[string]interface{}{
  3145. // "dialysisOrder": record,
  3146. // })
  3147. // } else {
  3148. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3149. // }
  3150. // }
  3151. // }
  3152. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3153. dataBody := make(map[string]interface{}, 0)
  3154. err := json.Unmarshal(data, &dataBody)
  3155. if err != nil {
  3156. utils.ErrorLog(err.Error())
  3157. code = enums.ErrorCodeParamWrong
  3158. return
  3159. }
  3160. timeLayout := "2006-01-02 "
  3161. timeLayout2 := "2006-01-02 15:04"
  3162. loc, _ := time.LoadLocation("Local")
  3163. if action == "create" {
  3164. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3165. utils.ErrorLog("advice_type")
  3166. code = enums.ErrorCodeParamWrong
  3167. return
  3168. }
  3169. adviceType := int64(dataBody["advice_type"].(float64))
  3170. if adviceType != 1 && adviceType != 2 {
  3171. utils.ErrorLog("advice_type != 1&&2")
  3172. code = enums.ErrorCodeParamWrong
  3173. return
  3174. }
  3175. advice.AdviceType = adviceType
  3176. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3177. utils.ErrorLog("advice_date")
  3178. code = enums.ErrorCodeParamWrong
  3179. return
  3180. }
  3181. adviceDate, _ := dataBody["advice_date"].(string)
  3182. if len(adviceDate) == 0 {
  3183. utils.ErrorLog("len(adviceDate) == 0")
  3184. code = enums.ErrorCodeParamWrong
  3185. return
  3186. }
  3187. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3188. if err != nil {
  3189. utils.ErrorLog(err.Error())
  3190. code = enums.ErrorCodeParamWrong
  3191. return
  3192. }
  3193. advice.AdviceDate = theTime.Unix()
  3194. }
  3195. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3196. utils.ErrorLog("start_time")
  3197. code = enums.ErrorCodeParamWrong
  3198. return
  3199. }
  3200. startDate, _ := dataBody["start_time"].(string)
  3201. if len(startDate) == 0 {
  3202. utils.ErrorLog("len(startDate) == 0")
  3203. code = enums.ErrorCodeParamWrong
  3204. return
  3205. }
  3206. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3207. if err != nil {
  3208. utils.ErrorLog(err.Error())
  3209. code = enums.ErrorCodeParamWrong
  3210. return
  3211. }
  3212. advice.StartTime = theTime.Unix()
  3213. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3214. utils.ErrorLog("advice_name")
  3215. code = enums.ErrorCodeParamWrong
  3216. return
  3217. }
  3218. adviceName, _ := dataBody["advice_name"].(string)
  3219. if len(adviceName) == 0 {
  3220. utils.ErrorLog("len(advice_name) == 0")
  3221. code = enums.ErrorCodeParamWrong
  3222. return
  3223. }
  3224. advice.AdviceName = adviceName
  3225. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3226. utils.ErrorLog("delivery_way")
  3227. code = enums.ErrorCodeParamWrong
  3228. return
  3229. }
  3230. deliveryWay, _ := dataBody["delivery_way"].(string)
  3231. if len(deliveryWay) == 0 {
  3232. utils.ErrorLog("len(deliveryWay) == 0")
  3233. code = enums.ErrorCodeParamWrong
  3234. return
  3235. }
  3236. advice.DeliveryWay = deliveryWay
  3237. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3238. utils.ErrorLog("execution_frequency")
  3239. code = enums.ErrorCodeParamWrong
  3240. return
  3241. }
  3242. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3243. if len(execution_frequency) == 0 {
  3244. utils.ErrorLog("len(execution_frequency) == 0")
  3245. code = enums.ErrorCodeParamWrong
  3246. return
  3247. }
  3248. advice.ExecutionFrequency = execution_frequency
  3249. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3250. adviceDsc, _ := dataBody["advice_desc"].(string)
  3251. advice.AdviceDesc = adviceDsc
  3252. }
  3253. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3254. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3255. advice.DrugSpecUnit = drugSpecUnit
  3256. }
  3257. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3258. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3259. advice.SingleDose = singleDose
  3260. }
  3261. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3262. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3263. advice.SingleDoseUnit = singleDoseUnit
  3264. }
  3265. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3266. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3267. advice.PrescribingNumber = prescribingNumber
  3268. }
  3269. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3270. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3271. advice.PrescribingNumberUnit = prescribingNumberUnit
  3272. }
  3273. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3274. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3275. if len(thisContagions) > 0 {
  3276. for _, item := range thisContagions {
  3277. items := item.(map[string]interface{})
  3278. advice_name, _ := items["advice_name"].(string)
  3279. advice_desc, _ := items["advice_desc"].(string)
  3280. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3281. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3282. single_dose_unit, _ := items["single_dose_unit"].(string)
  3283. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3284. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3285. advice := &models.DoctorAdvice{
  3286. AdviceName: advice_name,
  3287. AdviceDesc: advice_desc,
  3288. SingleDose: single_dose,
  3289. SingleDoseUnit: single_dose_unit,
  3290. DrugSpecUnit: drug_spec_unit,
  3291. PrescribingNumber: prescribing_number,
  3292. PrescribingNumberUnit: prescribing_number_unit,
  3293. }
  3294. subAdvice = append(subAdvice, advice)
  3295. }
  3296. }
  3297. }
  3298. return
  3299. }
  3300. func (c *DialysisApiController) GetDialysisOrder() {
  3301. xtno := c.GetString("xtno")
  3302. xtdate := c.GetString("xtdate")
  3303. timeLayout := "2006-01-02"
  3304. loc, _ := time.LoadLocation("Local")
  3305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3306. if err != nil {
  3307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3308. return
  3309. }
  3310. xttime := theTime.Unix()
  3311. operatorIDs := make([]int64, 0)
  3312. adminUserInfo := c.GetAdminUserInfo()
  3313. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3314. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3315. //透析单
  3316. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3317. if dialysisOrder != nil {
  3318. if dialysisOrder.FinishNurse > 0 {
  3319. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3320. }
  3321. if dialysisOrder.StartNurse > 0 {
  3322. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3323. }
  3324. }
  3325. //透前评估
  3326. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3327. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3328. //透后评估
  3329. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3330. if AssessmentAfterDislysis.Modifier > 0 {
  3331. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3332. }
  3333. //上次透前评估
  3334. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3335. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3336. //透析处方
  3337. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3338. if dialysisPrescription.PrescriptionDoctor > 0 {
  3339. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3340. }
  3341. //获取病人的透析模式
  3342. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3343. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3344. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3345. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3346. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3347. //获取透析处方
  3348. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3349. //获取临时医嘱
  3350. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3351. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3352. //获取医嘱内容
  3353. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3354. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3355. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3356. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3357. //获取上次的透后体重
  3358. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3359. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3360. //获取透析次数
  3361. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3362. if len(DoctorAdvice) > 0 {
  3363. for _, item := range DoctorAdvice {
  3364. if item.AdviceDoctor > 0 {
  3365. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3366. }
  3367. if item.ExecutionStaff > 0 {
  3368. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3369. }
  3370. if item.Checker > 0 {
  3371. operatorIDs = append(operatorIDs, item.Checker)
  3372. }
  3373. }
  3374. }
  3375. //透析监测
  3376. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3377. //透析检测
  3378. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3379. //透析小结
  3380. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3381. //接诊评估
  3382. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3383. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3384. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3385. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3386. patientInfo.TotalDialysis = dialysis_count
  3387. }
  3388. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3389. if xttime <= 1672416000 {
  3390. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3391. patientInfo.TotalDialysis = dialysis_count
  3392. }
  3393. if xttime >= 1672502400 {
  3394. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3395. patientInfo.TotalDialysis = dialysis_count
  3396. }
  3397. }
  3398. //相关操作对应的操作人
  3399. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3400. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3401. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3402. //获取当前日期月份的第一天
  3403. firstmonth := service.GetFirstDateOfMonth(theTime)
  3404. firstMonthDate := firstmonth.Unix()
  3405. //获取当前月份的病人透析次数
  3406. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3407. //获取his数据
  3408. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3409. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3410. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3411. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3412. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3413. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3414. // for _, item := range projects {
  3415. // var advice *models.HisDoctorAdviceInfo
  3416. // advice.ID = item.ID
  3417. // advice.Checker = item.Checker
  3418. // advice.CheckTime = item.CheckTime
  3419. // advice.CheckState = item.CheckState
  3420. // advice.ExecutionState = item.ExecutionState
  3421. // advice.ExecutionStaff = item.ExecutionStaff
  3422. // advice.PrescribingNumber = float64(item.Count)
  3423. // advice.PrescribingNumberUnit = item.Unit
  3424. // advice.AdviceDoctor = item.Doctor
  3425. // if item.Type == 3 {
  3426. // advice.AdviceName = item.GoodInfo.GoodName
  3427. // } else if item.Type == 2 {
  3428. // advice.AdviceName = item.HisProject.ProjectName
  3429. // }
  3430. // advice.StartTime = item.StartTime
  3431. // hisAdvice = append(hisAdvice, advice)
  3432. // }
  3433. //}
  3434. if config.IsOpen == 1 {
  3435. c.ServeSuccessJSON(map[string]interface{}{
  3436. "xtdate": xtdate,
  3437. "users": adminUser,
  3438. "patientInfo": patientInfo,
  3439. "PredialysisEvaluation": PredialysisEvaluation,
  3440. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3441. "dialysisPrescription": dialysisPrescription,
  3442. "advices": hisAdvice,
  3443. "monitors": Record,
  3444. "summary": TreatmentSummary,
  3445. "receiverTreatmentAccess": receiverTreatmentAccess,
  3446. "dialysisOrder": dialysisOrder,
  3447. "operators": operators,
  3448. "org_template_info": templateInfo,
  3449. "check": check,
  3450. "schedule": schedule,
  3451. "dialysisway": dialysisway,
  3452. "order": order,
  3453. "doctorAdvice": doctorAdvice,
  3454. "doctor": doctor,
  3455. "nurse": nurse,
  3456. "doctorAdevieInfo": doctorAdevieInfo,
  3457. "total": total,
  3458. "startNuse": startNuse,
  3459. "DoctorName": DoctorName,
  3460. "assessmentAfterDislysis": assessmentAfterDislysis,
  3461. "predialysName": predialysName,
  3462. "FinishNuse": FinishNuse,
  3463. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3464. "dialysiscount": dialysiscount,
  3465. "last_order": lastOrder,
  3466. "project_config": project_config,
  3467. "projects": projects,
  3468. })
  3469. }
  3470. if config.IsOpen == 0 || config.IsOpen == 2 {
  3471. c.ServeSuccessJSON(map[string]interface{}{
  3472. "xtdate": xtdate,
  3473. "users": adminUser,
  3474. "patientInfo": patientInfo,
  3475. "PredialysisEvaluation": PredialysisEvaluation,
  3476. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3477. "dialysisPrescription": dialysisPrescription,
  3478. "advices": DoctorAdvice,
  3479. "monitors": Record,
  3480. "summary": TreatmentSummary,
  3481. "receiverTreatmentAccess": receiverTreatmentAccess,
  3482. "dialysisOrder": dialysisOrder,
  3483. "operators": operators,
  3484. "org_template_info": templateInfo,
  3485. "check": check,
  3486. "schedule": schedule,
  3487. "dialysisway": dialysisway,
  3488. "order": order,
  3489. "doctorAdvice": doctorAdvice,
  3490. "doctor": doctor,
  3491. "nurse": nurse,
  3492. "doctorAdevieInfo": doctorAdevieInfo,
  3493. "total": total,
  3494. "startNuse": startNuse,
  3495. "DoctorName": DoctorName,
  3496. "assessmentAfterDislysis": assessmentAfterDislysis,
  3497. "predialysName": predialysName,
  3498. "FinishNuse": FinishNuse,
  3499. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3500. "dialysiscount": dialysiscount,
  3501. "last_order": lastOrder,
  3502. "project_config": project_config,
  3503. "projects": projects,
  3504. })
  3505. }
  3506. }
  3507. func (c *DialysisApiController) GetLongAdvice() {
  3508. patient_id, _ := c.GetInt64("patient_id")
  3509. adminUserInfo := c.GetAdminUserInfo()
  3510. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3511. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3512. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3513. c.ServeSuccessJSON(map[string]interface{}{
  3514. "status": "1",
  3515. })
  3516. return
  3517. } else { //开启推送提醒
  3518. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3519. var advice_three []*models.DoctorAdvice
  3520. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3521. recordDateStr := time.Now().Format("2006-01-02")
  3522. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3523. nowtime := recordDate.Unix()
  3524. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3525. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3526. for _, advice := range advices {
  3527. if advice.FrequencyType == 3 {
  3528. t := time.Now()
  3529. week := int(t.Weekday())
  3530. switch week {
  3531. case 1:
  3532. if strings.Index(advice.WeekDay, "周一") == -1 {
  3533. advice_three = append(advice_three, advice)
  3534. }
  3535. break
  3536. case 2:
  3537. if strings.Index(advice.WeekDay, "周二") == -1 {
  3538. advice_three = append(advice_three, advice)
  3539. }
  3540. break
  3541. case 3:
  3542. if strings.Index(advice.WeekDay, "周三") == -1 {
  3543. advice_three = append(advice_three, advice)
  3544. }
  3545. break
  3546. case 4:
  3547. if strings.Index(advice.WeekDay, "周四") == -1 {
  3548. advice_three = append(advice_three, advice)
  3549. }
  3550. break
  3551. case 5:
  3552. if strings.Index(advice.WeekDay, "周五") == -1 {
  3553. advice_three = append(advice_three, advice)
  3554. }
  3555. break
  3556. case 6:
  3557. if strings.Index(advice.WeekDay, "周六") == -1 {
  3558. advice_three = append(advice_three, advice)
  3559. }
  3560. break
  3561. case 0:
  3562. if strings.Index(advice.WeekDay, "周日") == -1 {
  3563. advice_three = append(advice_three, advice)
  3564. }
  3565. break
  3566. }
  3567. }
  3568. }
  3569. for _, advice := range advices_two {
  3570. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3571. now := p.Unix()
  3572. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3573. dayStr2 := "-" + dayStr
  3574. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3575. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3576. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3577. for _, ad := range advices {
  3578. advice_three = append(advice_three, ad)
  3579. }
  3580. }
  3581. if err == nil {
  3582. c.ServeSuccessJSON(map[string]interface{}{
  3583. "status": "2",
  3584. "advices": advices,
  3585. "advices_two": RemoveRepeatedElement(advice_three),
  3586. "is_open_remind": config.IsOpenRemind,
  3587. })
  3588. }
  3589. }
  3590. }
  3591. func (c *DialysisApiController) GetLongAdviceOne() {
  3592. patient_id, _ := c.GetInt64("patient_id")
  3593. schedule_date := c.GetString("schedule_date")
  3594. adminUserInfo := c.GetAdminUserInfo()
  3595. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3596. timeLayout := "2006-01-02"
  3597. loc, _ := time.LoadLocation("Local")
  3598. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3599. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3600. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3601. c.ServeSuccessJSON(map[string]interface{}{
  3602. "status": "1",
  3603. })
  3604. return
  3605. } else { //开启推送提醒
  3606. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3607. var advice_three []*models.DoctorAdvice
  3608. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3609. //recordDateStr := time.Now().Format("2006-01-02")
  3610. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3611. //
  3612. //nowtime := recordDate.Unix()
  3613. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3614. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3615. for _, advice := range advices {
  3616. if advice.FrequencyType == 3 {
  3617. t := time.Now()
  3618. week := int(t.Weekday())
  3619. switch week {
  3620. case 1:
  3621. if strings.Index(advice.WeekDay, "周一") == -1 {
  3622. advice_three = append(advice_three, advice)
  3623. }
  3624. break
  3625. case 2:
  3626. if strings.Index(advice.WeekDay, "周二") == -1 {
  3627. advice_three = append(advice_three, advice)
  3628. }
  3629. break
  3630. case 3:
  3631. if strings.Index(advice.WeekDay, "周三") == -1 {
  3632. advice_three = append(advice_three, advice)
  3633. }
  3634. break
  3635. case 4:
  3636. if strings.Index(advice.WeekDay, "周四") == -1 {
  3637. advice_three = append(advice_three, advice)
  3638. }
  3639. break
  3640. case 5:
  3641. if strings.Index(advice.WeekDay, "周五") == -1 {
  3642. advice_three = append(advice_three, advice)
  3643. }
  3644. break
  3645. case 6:
  3646. if strings.Index(advice.WeekDay, "周六") == -1 {
  3647. advice_three = append(advice_three, advice)
  3648. }
  3649. break
  3650. case 0:
  3651. if strings.Index(advice.WeekDay, "周日") == -1 {
  3652. advice_three = append(advice_three, advice)
  3653. }
  3654. break
  3655. }
  3656. }
  3657. }
  3658. for _, advice := range advices_two {
  3659. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3660. now := p.Unix()
  3661. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3662. dayStr2 := "-" + dayStr
  3663. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3664. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3665. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3666. for _, ad := range advices {
  3667. advice_three = append(advice_three, ad)
  3668. }
  3669. }
  3670. if err == nil {
  3671. c.ServeSuccessJSON(map[string]interface{}{
  3672. "status": "2",
  3673. "advices": advices,
  3674. "advices_two": RemoveRepeatedElement(advice_three),
  3675. "is_open_remind": config.IsOpenRemind,
  3676. })
  3677. }
  3678. }
  3679. }
  3680. func (c *DialysisApiController) GetLongAdviceTwo() {
  3681. patient_id, _ := c.GetInt64("patient_id")
  3682. schedule_date, _ := c.GetInt64("schedule_date")
  3683. adminUserInfo := c.GetAdminUserInfo()
  3684. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3685. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3686. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3687. c.ServeSuccessJSON(map[string]interface{}{
  3688. "status": "1",
  3689. })
  3690. return
  3691. } else { //开启推送提醒
  3692. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3693. var advice_three []*models.DoctorAdvice
  3694. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3695. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3696. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3697. for _, advice := range advices {
  3698. if advice.FrequencyType == 3 {
  3699. t := time.Now()
  3700. week := int(t.Weekday())
  3701. switch week {
  3702. case 1:
  3703. if strings.Index(advice.WeekDay, "周一") == -1 {
  3704. advice_three = append(advice_three, advice)
  3705. }
  3706. break
  3707. case 2:
  3708. if strings.Index(advice.WeekDay, "周二") == -1 {
  3709. advice_three = append(advice_three, advice)
  3710. }
  3711. break
  3712. case 3:
  3713. if strings.Index(advice.WeekDay, "周三") == -1 {
  3714. advice_three = append(advice_three, advice)
  3715. }
  3716. break
  3717. case 4:
  3718. if strings.Index(advice.WeekDay, "周四") == -1 {
  3719. advice_three = append(advice_three, advice)
  3720. }
  3721. break
  3722. case 5:
  3723. if strings.Index(advice.WeekDay, "周五") == -1 {
  3724. advice_three = append(advice_three, advice)
  3725. }
  3726. break
  3727. case 6:
  3728. if strings.Index(advice.WeekDay, "周六") == -1 {
  3729. advice_three = append(advice_three, advice)
  3730. }
  3731. break
  3732. case 0:
  3733. if strings.Index(advice.WeekDay, "周日") == -1 {
  3734. advice_three = append(advice_three, advice)
  3735. }
  3736. break
  3737. }
  3738. }
  3739. }
  3740. for _, advice := range advices_two {
  3741. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3742. now := p.Unix()
  3743. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3744. dayStr2 := "-" + dayStr
  3745. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3746. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3747. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3748. for _, ad := range advices {
  3749. advice_three = append(advice_three, ad)
  3750. }
  3751. }
  3752. if err == nil {
  3753. c.ServeSuccessJSON(map[string]interface{}{
  3754. "status": "2",
  3755. "advices": advices,
  3756. "advices_two": RemoveRepeatedElement(advice_three),
  3757. "is_open_remind": config.IsOpenRemind,
  3758. })
  3759. }
  3760. }
  3761. }
  3762. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3763. newArr = make([]*models.DoctorAdvice, 0)
  3764. for i := 0; i < len(arr); i++ {
  3765. repeat := false
  3766. for j := i + 1; j < len(arr); j++ {
  3767. if arr[i].ID == arr[j].ID {
  3768. repeat = true
  3769. break
  3770. }
  3771. }
  3772. if !repeat {
  3773. newArr = append(newArr, arr[i])
  3774. }
  3775. }
  3776. return
  3777. }
  3778. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3779. patient, _ := c.GetInt64("id", 0)
  3780. groupNo, _ := c.GetInt64("groupno", 0)
  3781. if patient <= 0 {
  3782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3783. return
  3784. }
  3785. adminUserInfo := c.GetAdminUserInfo()
  3786. dataBody := make(map[string]interface{}, 0)
  3787. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3788. if err != nil {
  3789. utils.ErrorLog(err.Error())
  3790. return
  3791. }
  3792. utils.ErrorLog("%v", dataBody)
  3793. timeLayout := "2006-01-02 15:04"
  3794. loc, _ := time.LoadLocation("Local")
  3795. timeLayout2 := "2006-01-02"
  3796. loc2, _ := time.LoadLocation("Local")
  3797. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3798. utils.ErrorLog("advice_type")
  3799. return
  3800. }
  3801. adviceType := int64(2)
  3802. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3803. utils.ErrorLog("advice_date")
  3804. return
  3805. }
  3806. adviceDate, _ := dataBody["advice_date"].(string)
  3807. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3808. AdviceDate := theTime.Unix()
  3809. RecordDate := theTime.Unix()
  3810. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3811. utils.ErrorLog("start_time")
  3812. return
  3813. }
  3814. startTime, _ := dataBody["start_time"].(string)
  3815. if len(startTime) == 0 {
  3816. utils.ErrorLog("len(start_time) == 0")
  3817. return
  3818. }
  3819. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3820. if err != nil {
  3821. utils.ErrorLog(err.Error())
  3822. return
  3823. }
  3824. StartTime := theTimeUnix.Unix()
  3825. fmt.Println("startTIME", StartTime)
  3826. Remark := ""
  3827. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3828. remark, _ := dataBody["remark"].(string)
  3829. Remark = remark
  3830. }
  3831. var advices []*models.GroupAdvice
  3832. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3833. utils.ErrorLog("advices")
  3834. return
  3835. }
  3836. adviceNames := dataBody["advices"].([]interface{})
  3837. for _, adviceNameMap := range adviceNames {
  3838. adviceNameM := adviceNameMap.(map[string]interface{})
  3839. var advice models.GroupAdvice
  3840. advice.Remark = Remark
  3841. advice.AdviceType = adviceType
  3842. advice.StartTime = StartTime
  3843. advice.AdviceDate = AdviceDate
  3844. advice.RecordDate = RecordDate
  3845. advice.Status = 1
  3846. advice.CreatedTime = time.Now().Unix()
  3847. advice.UpdatedTime = time.Now().Unix()
  3848. advice.StopState = 2
  3849. advice.ExecutionState = 2
  3850. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3851. advice.PatientId = patient
  3852. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3853. advice.IsSettle = 2
  3854. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3855. utils.ErrorLog("advice_name")
  3856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3857. return
  3858. }
  3859. adviceName, _ := adviceNameM["advice_name"].(string)
  3860. if len(adviceName) == 0 {
  3861. utils.ErrorLog("len(advice_name) == 0")
  3862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3863. return
  3864. }
  3865. advice.AdviceName = adviceName
  3866. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3867. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3868. advice.DrugSpec = drugSpec
  3869. }
  3870. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3871. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3872. advice.AdviceDesc = adviceDesc
  3873. }
  3874. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3875. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3876. advice.DrugSpecUnit = drugSpecUnit
  3877. }
  3878. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3879. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3880. // advice.SingleDose = singleDose
  3881. //}
  3882. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3883. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3884. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3885. }
  3886. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3887. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3888. advice.SingleDoseUnit = singleDoseUnit
  3889. }
  3890. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3891. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3892. // advice.PrescribingNumber = prescribingNumber
  3893. //}
  3894. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3895. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3896. }
  3897. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3898. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3899. advice.PrescribingNumberUnit = prescribingNumberUnit
  3900. }
  3901. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3902. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3903. advice.DeliveryWay = deliveryWay
  3904. }
  3905. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3906. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3907. advice.ExecutionFrequency = executionFrequency
  3908. }
  3909. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3910. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3911. advice.FrequencyType = frequency_type
  3912. }
  3913. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3914. day_count := int64(adviceNameM["day_count"].(float64))
  3915. advice.DayCount = day_count
  3916. }
  3917. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3918. way := int64(adviceNameM["way"].(float64))
  3919. advice.Way = way
  3920. }
  3921. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3922. drug_id := int64(adviceNameM["drug_id"].(float64))
  3923. advice.DrugId = drug_id
  3924. }
  3925. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3926. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3927. advice.DrugNameId = drug_name_id
  3928. }
  3929. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3930. week_day, _ := adviceNameM["week_day"].(string)
  3931. advice.WeekDay = week_day
  3932. }
  3933. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3934. template_id, _ := adviceNameM["template_id"].(string)
  3935. advice.TemplateId = template_id
  3936. }
  3937. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3938. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3939. advice.ExecutionFrequency = executionFrequency
  3940. }
  3941. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3942. children := adviceNameM["child"].([]interface{})
  3943. if len(children) > 0 {
  3944. for _, childrenMap := range children {
  3945. childMap := childrenMap.(map[string]interface{})
  3946. var child models.GroupAdvice
  3947. child.Remark = Remark
  3948. child.AdviceType = adviceType
  3949. child.StartTime = StartTime
  3950. child.AdviceDate = AdviceDate
  3951. child.RecordDate = RecordDate
  3952. child.Status = 1
  3953. child.CreatedTime = time.Now().Unix()
  3954. child.UpdatedTime = time.Now().Unix()
  3955. child.StopState = 2
  3956. child.ExecutionState = 2
  3957. child.UserOrgId = adminUserInfo.CurrentOrgId
  3958. child.PatientId = patient
  3959. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3960. child.IsSettle = 2
  3961. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3962. utils.ErrorLog("child advice_name")
  3963. return
  3964. }
  3965. childAdviceName, _ := childMap["advice_name"].(string)
  3966. if len(childAdviceName) == 0 {
  3967. utils.ErrorLog("len(child advice_name) == 0")
  3968. return
  3969. }
  3970. child.AdviceName = childAdviceName
  3971. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3972. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3973. child.AdviceDesc = childAdviceDesc
  3974. }
  3975. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3976. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3977. child.DrugSpec = childDrugSpec
  3978. }
  3979. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3980. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3981. child.DrugSpecUnit = childDrugSpecUnit
  3982. }
  3983. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3984. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3985. child.SingleDose = childSingleDose
  3986. }
  3987. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3988. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3989. child.SingleDose = childMap["single_dose"].(float64)
  3990. }
  3991. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3992. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3993. child.Remark = childMap["remark"].(string)
  3994. }
  3995. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3996. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3997. child.DrugId = int64(childMap["drug_id"].(float64))
  3998. }
  3999. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4000. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4001. child.SingleDoseUnit = childSingleDoseUnit
  4002. }
  4003. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4004. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4005. child.PrescribingNumber = childPrescribingNumber
  4006. }
  4007. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4008. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4009. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4010. }
  4011. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4012. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4013. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4014. }
  4015. child.DeliveryWay = advice.DeliveryWay
  4016. child.ExecutionFrequency = advice.ExecutionFrequency
  4017. advice.Children = append(advice.Children, &child)
  4018. }
  4019. }
  4020. }
  4021. advices = append(advices, &advice)
  4022. }
  4023. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4024. redis := service.RedisClient()
  4025. formatAdviceDate := theTime.Format("2006-01-02")
  4026. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4027. redis.Set(key, "", time.Second)
  4028. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4029. redis.Set(keyOne, "", time.Second)
  4030. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4031. redis.Set(keyFour, "", time.Second)
  4032. defer redis.Close()
  4033. if err != nil {
  4034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4035. return
  4036. }
  4037. c.ServeSuccessJSON(map[string]interface{}{
  4038. "msg": "ok",
  4039. "advices": list,
  4040. })
  4041. return
  4042. }
  4043. func (c *DialysisApiController) GetSolution() {
  4044. patient_id, _ := c.GetInt64("patient_id")
  4045. mode_id, _ := c.GetInt64("mode_id")
  4046. adminUserInfo := c.GetAdminUserInfo()
  4047. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4048. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4049. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  4050. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  4051. if err != nil {
  4052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4053. return
  4054. }
  4055. c.ServeSuccessJSON(map[string]interface{}{
  4056. "solution": solution,
  4057. "prescription": prescription,
  4058. "system_prescription": system_prescription,
  4059. "dialysisPrescription": dialysisPrescription,
  4060. })
  4061. }
  4062. func (c *DialysisApiController) GetSchedule() {
  4063. schedual_type, _ := c.GetInt64("schedual_type")
  4064. adminUserInfo := c.GetAdminUserInfo()
  4065. //timeLayout := "2006-01-02 15:04:05"
  4066. //
  4067. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  4068. //loc, _ := time.LoadLocation("Local")
  4069. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4070. //scheduleTime := theStartTime.Unix()
  4071. scheduleTime, _ := c.GetInt64("record_date")
  4072. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4073. c.ServeSuccessJSON(map[string]interface{}{
  4074. "number": deviceNumber,
  4075. })
  4076. }
  4077. func (this *DialysisApiController) GetTodayMonitor() {
  4078. thisTime := time.Now()
  4079. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4080. timeLayout := "2006-01-02 15:04:05"
  4081. loc, _ := time.LoadLocation("Local")
  4082. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4083. theAssessmentDateTime := theStartTime.Unix()
  4084. patientID, _ := this.GetInt64("patient_id")
  4085. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4086. adminInfo := this.GetAdminUserInfo()
  4087. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4088. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4089. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4090. var ultrafiltration_rate float64
  4091. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4092. //针对福建医师汇 获取透前评估预增脱水量
  4093. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4094. fmt.Println("透前评估数据", evaluation)
  4095. if prescription.ID > 0 {
  4096. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4097. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4098. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4099. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4100. record.UltrafiltrationRate = ultrafiltration_rate
  4101. }
  4102. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  4103. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4104. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  4108. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4109. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4110. record.UltrafiltrationRate = ultrafiltration_rate
  4111. }
  4112. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  4113. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4114. record.UltrafiltrationRate = ultrafiltration_rate
  4115. }
  4116. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  4117. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4118. record.UltrafiltrationRate = ultrafiltration_rate
  4119. }
  4120. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  4121. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4122. record.UltrafiltrationRate = ultrafiltration_rate
  4123. }
  4124. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  4125. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4126. record.UltrafiltrationRate = ultrafiltration_rate
  4127. }
  4128. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  4129. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4130. record.UltrafiltrationRate = ultrafiltration_rate
  4131. }
  4132. // 只针对方济医院
  4133. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4134. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4135. ultrafiltration_rate = value
  4136. record.UltrafiltrationRate = ultrafiltration_rate
  4137. }
  4138. //长沙南雅
  4139. 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 {
  4140. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4141. record.UltrafiltrationRate = ultrafiltration_rate
  4142. }
  4143. }
  4144. }
  4145. // record.UltrafiltrationRate = ultrafiltration_rate
  4146. record.UltrafiltrationVolume = 0
  4147. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4148. if ultrafiltration_rate > 0 {
  4149. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4150. record.UltrafiltrationVolume = value
  4151. }
  4152. }
  4153. 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 {
  4154. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4155. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4156. record.UltrafiltrationVolume = ultrafiltration_volume
  4157. }
  4158. }
  4159. //长沙南雅
  4160. 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 {
  4161. if ultrafiltration_rate > 0 {
  4162. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4163. record.UltrafiltrationVolume = ultrafiltration_volume
  4164. }
  4165. }
  4166. if template.TemplateId == 47 || template.TemplateId == 54 {
  4167. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4168. }
  4169. this.ServeSuccessJSON(map[string]interface{}{
  4170. "monitor": record,
  4171. })
  4172. }
  4173. func (c *DialysisApiController) UploadDryWeight() {
  4174. patient_id, _ := c.GetInt64("id")
  4175. dry_weight, _ := c.GetFloat("dry_weight")
  4176. doctor_id, _ := c.GetInt64("doctor_id")
  4177. remark := c.GetString("remark")
  4178. adminUserInfo := c.GetAdminUserInfo()
  4179. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4180. fmt.Println(err)
  4181. if err == gorm.ErrRecordNotFound {
  4182. dryWeight := &models.SgjPatientDryweight{
  4183. PatientId: patient_id,
  4184. DryWeight: dry_weight,
  4185. Remakes: remark,
  4186. Ctime: time.Now().Unix(),
  4187. Mtime: time.Now().Unix(),
  4188. Creator: doctor_id,
  4189. Status: 1,
  4190. UserOrgId: adminUserInfo.CurrentOrgId,
  4191. AdjustedValue: "/",
  4192. UserId: adminUserInfo.AdminUser.Id,
  4193. }
  4194. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4195. loc, _ := time.LoadLocation("Local")
  4196. nowTime := time.Now()
  4197. nowDay := nowTime.Format("2006-01-02")
  4198. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4199. redis := service.RedisClient()
  4200. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4201. redis.Set(keyOne, "", time.Second)
  4202. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4203. redis.Set(key, "", time.Second)
  4204. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4205. redis.Set(keyTwo, "", time.Second)
  4206. redis.Close()
  4207. if createErr == nil {
  4208. c.ServeSuccessJSON(map[string]interface{}{
  4209. "msg": "提交成功",
  4210. "weight": dryWeight,
  4211. })
  4212. }
  4213. } else {
  4214. dryWeight := &models.SgjPatientDryweight{
  4215. PatientId: patient_id,
  4216. DryWeight: dry_weight,
  4217. Remakes: remark,
  4218. Ctime: time.Now().Unix(),
  4219. Mtime: time.Now().Unix(),
  4220. Creator: doctor_id,
  4221. Status: 1,
  4222. UserOrgId: adminUserInfo.CurrentOrgId,
  4223. AdjustedValue: "/",
  4224. UserId: adminUserInfo.AdminUser.Id,
  4225. }
  4226. var value float64
  4227. value = dry_weight - weightAdjust.DryWeight
  4228. fmt.Println(value)
  4229. if value < 0 {
  4230. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4231. } else if value == 0 {
  4232. dryWeight.AdjustedValue = "/"
  4233. } else if value > 0 {
  4234. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4235. }
  4236. fmt.Println(value)
  4237. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4238. loc, _ := time.LoadLocation("Local")
  4239. nowTime := time.Now()
  4240. nowDay := nowTime.Format("2006-01-02")
  4241. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4242. redis := service.RedisClient()
  4243. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4244. redis.Set(keyOne, "", time.Second)
  4245. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4246. redis.Set(key, "", time.Second)
  4247. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4248. redis.Set(keyTwo, "", time.Second)
  4249. redis.Close()
  4250. if createErr == nil {
  4251. c.ServeSuccessJSON(map[string]interface{}{
  4252. "msg": "提交成功",
  4253. "weight": dryWeight,
  4254. })
  4255. }
  4256. }
  4257. }
  4258. func (this *DialysisApiController) GetFuncPurview() {
  4259. adminUserInfo := this.GetAdminUserInfo()
  4260. user_id := adminUserInfo.AdminUser.Id
  4261. app_id := adminUserInfo.CurrentAppId
  4262. org_id := adminUserInfo.CurrentOrgId
  4263. create_url := this.GetString("create_url")
  4264. modify_url := this.GetString("modify_url")
  4265. modify_other_url := this.GetString("modify_other_url")
  4266. del_url := this.GetString("del_url")
  4267. del_other_url := this.GetString("del_other_url")
  4268. exce_url := this.GetString("exce_url")
  4269. check_url := this.GetString("check_url")
  4270. modify_exce_url := this.GetString("modify_exce_url")
  4271. module, _ := this.GetInt64("module", 0)
  4272. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4273. var is_has_create bool
  4274. var is_has_modify bool
  4275. var is_has_modify_other bool
  4276. var is_has_del bool
  4277. var is_has_del_other bool
  4278. var is_has_exce bool
  4279. var is_has_check bool
  4280. var is_has_modify_exce bool
  4281. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4282. if adminUserInfo.AdminUser.Id != org.Creator {
  4283. if app_role != nil {
  4284. if len(app_role.RoleIds) > 0 {
  4285. roles := strings.Split(app_role.RoleIds, ",")
  4286. var userRolePurviews string
  4287. for _, item := range roles {
  4288. role_id, _ := strconv.ParseInt(item, 10, 64)
  4289. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4290. if len(userRolePurviews) == 0 {
  4291. userRolePurviews = purviews
  4292. } else {
  4293. userRolePurviews = userRolePurviews + "," + purviews
  4294. }
  4295. }
  4296. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4297. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4298. for _, item := range funcPurviews {
  4299. //for _, url := range strings.Split(item.Urlfor,","){
  4300. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4301. is_has_create = true
  4302. }
  4303. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4304. is_has_modify = true
  4305. }
  4306. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4307. is_has_modify_other = true
  4308. }
  4309. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4310. is_has_del = true
  4311. }
  4312. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4313. is_has_del_other = true
  4314. }
  4315. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4316. is_has_exce = true
  4317. }
  4318. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4319. is_has_check = true
  4320. }
  4321. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4322. is_has_modify_exce = true
  4323. }
  4324. }
  4325. } else {
  4326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4327. return
  4328. }
  4329. this.ServeSuccessJSON(map[string]interface{}{
  4330. "is_has_create": is_has_create,
  4331. "is_has_modify": is_has_modify,
  4332. "is_has_modify_other": is_has_modify_other,
  4333. "is_has_del": is_has_del,
  4334. "is_has_del_other": is_has_del_other,
  4335. "is_has_exce": is_has_exce,
  4336. "is_has_check": is_has_check,
  4337. "is_has_modify_exce": is_has_modify_exce,
  4338. "module": module,
  4339. })
  4340. } else {
  4341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4342. return
  4343. }
  4344. } else {
  4345. this.ServeSuccessJSON(map[string]interface{}{
  4346. "is_has_create": true,
  4347. "is_has_modify": true,
  4348. "is_has_modify_other": true,
  4349. "is_has_del": true,
  4350. "is_has_del_other": true,
  4351. "is_has_exce": true,
  4352. "is_has_check": true,
  4353. "is_has_modify_exce": true,
  4354. "module": true,
  4355. })
  4356. }
  4357. }
  4358. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4359. patient_id, _ := this.GetInt64("patient_id", 0)
  4360. advice_date, _ := this.GetInt64("advice_date")
  4361. adminUserInfo := this.GetAdminUserInfo()
  4362. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4363. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4364. this.ServeSuccessJSON(map[string]interface{}{
  4365. "doctorAdvice": doctorAdvice,
  4366. "hisDoctorAdvice": hisDoctorAdvice,
  4367. })
  4368. }
  4369. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4370. change_type, _ := this.GetInt64("type", 0)
  4371. record_date := this.GetString("record_time")
  4372. patient_id, _ := this.GetInt64("patient_id", 0)
  4373. timeLayout := "2006-01-02"
  4374. loc, _ := time.LoadLocation("Local")
  4375. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4376. record_time := theAdviceRecordTime.Unix()
  4377. adminUserInfo := this.GetAdminUserInfo()
  4378. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4379. if err == nil {
  4380. if len(advices) == 0 {
  4381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4382. return
  4383. } else {
  4384. this.ServeSuccessJSON(map[string]interface{}{
  4385. "advices": advices,
  4386. "schedule": sch,
  4387. })
  4388. return
  4389. }
  4390. } else {
  4391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4392. return
  4393. }
  4394. }
  4395. func (c *DialysisApiController) GetDialysisGoods() {
  4396. schedualDate := c.GetString("schedule_date")
  4397. schedule_type, _ := c.GetInt64("schedule_type")
  4398. partition_id, _ := c.GetInt64("partition_id")
  4399. page, _ := c.GetInt("page")
  4400. limit, _ := c.GetInt("limit")
  4401. keywords := c.GetString("keywords")
  4402. patient_id, _ := c.GetInt64("patient_id")
  4403. good_type, _ := c.GetInt64("good_type")
  4404. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4405. if parseDateErr != nil && len(schedualDate) != 0 {
  4406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. schedualEndDate := int64(0)
  4410. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4411. if parseDateErr != nil && len(schedualDate) != 0 {
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. return
  4414. }
  4415. schedualEndDate = endDate.Unix()
  4416. adminUser := c.GetAdminUserInfo()
  4417. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4418. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4419. if err == gorm.ErrRecordNotFound {
  4420. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4421. var ids []int64
  4422. for _, item := range list {
  4423. ids = append(ids, item.PatientId)
  4424. }
  4425. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4426. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4427. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4428. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4429. item.LastAutomaticReduceDetail = goodUser
  4430. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4431. }
  4432. c.ServeSuccessJSON(map[string]interface{}{
  4433. "dialysis_goods": dialysisGoods,
  4434. "good_type": goodTypes,
  4435. "total": total,
  4436. })
  4437. return
  4438. } else if err == nil {
  4439. //获取当天排班的每个患者的库存使用情况
  4440. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4441. var ids []int64
  4442. for _, item := range list {
  4443. ids = append(ids, item.PatientId)
  4444. }
  4445. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4446. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4447. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4448. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4449. fmt.Println(goodUser)
  4450. fmt.Println(lastGoodUserDetial)
  4451. item.LastAutomaticReduceDetail = goodUser
  4452. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4453. }
  4454. if err == nil {
  4455. c.ServeSuccessJSON(map[string]interface{}{
  4456. "dialysis_goods": dialysisGoods,
  4457. "good_type": goodTypes,
  4458. "total": total,
  4459. })
  4460. return
  4461. } else {
  4462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4463. return
  4464. }
  4465. } else if err != nil {
  4466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4467. return
  4468. }
  4469. }
  4470. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4471. start_time := c.GetString("start_time")
  4472. end_time := c.GetString("end_time")
  4473. timeLayout := "2006-01-02"
  4474. loc, _ := time.LoadLocation("Local")
  4475. var theStartTime int64
  4476. if len(start_time) > 0 {
  4477. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4478. if err != nil {
  4479. utils.ErrorLog(err.Error())
  4480. }
  4481. theStartTime = theTime.Unix()
  4482. }
  4483. var theEndtTime int64
  4484. if len(end_time) > 0 {
  4485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4486. if err != nil {
  4487. utils.ErrorLog(err.Error())
  4488. }
  4489. theEndtTime = theTime.Unix()
  4490. }
  4491. adminUser := c.GetAdminUserInfo()
  4492. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4493. if err == nil {
  4494. c.ServeSuccessJSON(map[string]interface{}{
  4495. "stock_out": outInfo,
  4496. })
  4497. return
  4498. } else {
  4499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4500. return
  4501. }
  4502. }
  4503. func (c *DialysisApiController) GetRoleList() {
  4504. orgId := c.GetAdminUserInfo().CurrentOrgId
  4505. admin_user_id, _ := c.GetInt64("admin_user_id")
  4506. list, err := service.GetRoleList(orgId, admin_user_id)
  4507. if err == nil {
  4508. c.ServeSuccessJSON(map[string]interface{}{
  4509. "adminRole": list,
  4510. })
  4511. return
  4512. } else {
  4513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4514. return
  4515. }
  4516. }
  4517. func (c *DialysisApiController) GetInitPrintData() {
  4518. patient_id, _ := c.GetInt64("patient_id")
  4519. record_date, _ := c.GetInt64("record_date")
  4520. orgId := c.GetAdminUserInfo().CurrentOrgId
  4521. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4522. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4523. if err == nil {
  4524. c.ServeSuccessJSON(map[string]interface{}{
  4525. "list": list,
  4526. "assessmentAfterDislysis": assessmentAfterDislysis,
  4527. })
  4528. return
  4529. } else {
  4530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4531. return
  4532. }
  4533. }
  4534. func (c *DialysisApiController) GetInitPrintDataOne() {
  4535. patient_id, _ := c.GetInt64("patient_id")
  4536. start_time := c.GetString("record_date")
  4537. timeLayout := "2006-01-02"
  4538. loc, _ := time.LoadLocation("Local")
  4539. var theStartTime int64
  4540. if len(start_time) > 0 {
  4541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4542. if err != nil {
  4543. utils.ErrorLog(err.Error())
  4544. }
  4545. theStartTime = theTime.Unix()
  4546. }
  4547. orgId := c.GetAdminUserInfo().CurrentOrgId
  4548. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4549. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4550. if err == nil {
  4551. c.ServeSuccessJSON(map[string]interface{}{
  4552. "list": list,
  4553. "assessmentAfterDislysis": assessmentAfterDislysis,
  4554. })
  4555. return
  4556. } else {
  4557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4558. return
  4559. }
  4560. }
  4561. // 新接口
  4562. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4563. keyword := this.GetString("keywords")
  4564. limit, _ := this.GetInt64("limit")
  4565. page, _ := this.GetInt64("page")
  4566. partition_id, _ := this.GetInt64("partition_id")
  4567. schedule_type, _ := this.GetInt64("schedule_type")
  4568. start_time := this.GetString("schedule_date")
  4569. advice_ids := this.GetString("ids")
  4570. var ids []string
  4571. if advice_ids != "" {
  4572. ids = strings.Split(advice_ids, ",")
  4573. }
  4574. timeLayout := "2006-01-02"
  4575. loc, _ := time.LoadLocation("Local")
  4576. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4577. orgId := this.GetAdminUserInfo().CurrentOrgId
  4578. _, config := service.FindXTHisRecordByOrgId(orgId)
  4579. goodType, _ := service.GetAllGoodType(orgId)
  4580. if config.IsOpen != 1 {
  4581. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4582. fmt.Println("list2232323223332323232", list)
  4583. if err == nil {
  4584. this.ServeSuccessJSON(map[string]interface{}{
  4585. "list": list,
  4586. "total": total,
  4587. "config": config,
  4588. "goodType": goodType,
  4589. })
  4590. return
  4591. } else {
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4593. return
  4594. }
  4595. }
  4596. if config.IsOpen == 1 {
  4597. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4598. if err == nil {
  4599. this.ServeSuccessJSON(map[string]interface{}{
  4600. "list": list,
  4601. "total": total,
  4602. "config": config,
  4603. "goodType": goodType,
  4604. })
  4605. return
  4606. }
  4607. }
  4608. }
  4609. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4610. keyword := this.GetString("keywords")
  4611. limit, _ := this.GetInt64("limit")
  4612. page, _ := this.GetInt64("page")
  4613. partition_id, _ := this.GetInt64("partition_id")
  4614. schedule_type, _ := this.GetInt64("schedule_type")
  4615. start_time := this.GetString("schedule_date")
  4616. ids := this.GetString("ids")
  4617. var idArray []string
  4618. if ids != "" {
  4619. idArray = strings.Split(ids, ",")
  4620. }
  4621. timeLayout := "2006-01-02"
  4622. loc, _ := time.LoadLocation("Local")
  4623. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4624. orgId := this.GetAdminUserInfo().CurrentOrgId
  4625. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4626. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4627. //获取长期医嘱
  4628. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4629. _, config := service.FindXTHisRecordByOrgId(orgId)
  4630. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4631. if err == nil {
  4632. this.ServeSuccessJSON(map[string]interface{}{
  4633. "list": list,
  4634. "total": total,
  4635. "adviceList": adviceList,
  4636. "config": config,
  4637. "drugList": drugList,
  4638. "tablelist": tablelist,
  4639. })
  4640. return
  4641. } else {
  4642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4643. return
  4644. }
  4645. }
  4646. func (this *DialysisApiController) SaveDialysisSetting() {
  4647. orgId := this.GetAdminUserInfo().CurrentOrgId
  4648. device_number_set, _ := this.GetInt64("device_number_set")
  4649. device_type_set, _ := this.GetInt64("device_type_set")
  4650. name_set, _ := this.GetInt64("name_set")
  4651. admission_number_set, _ := this.GetInt64("admission_number_set")
  4652. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4653. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4654. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4655. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4656. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4657. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4658. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4659. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4660. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4661. mode_id_set, _ := this.GetInt64("mode_id_set")
  4662. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4663. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4664. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4665. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4666. kalium_set, _ := this.GetInt64("kalium_set")
  4667. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4668. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4669. glucose_set, _ := this.GetInt64("glucose_set")
  4670. sodium_set, _ := this.GetInt64("sodium_set")
  4671. calcium_set, _ := this.GetInt64("calcium_set")
  4672. blood_access_set, _ := this.GetInt64("blood_access_set")
  4673. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4674. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4675. dialysisSetting := models.XtDialysisSetting{
  4676. Sodium: sodium_set,
  4677. Calcium: calcium_set,
  4678. BloodAccess: blood_access_set,
  4679. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4680. DisplaceLiquiPart: displace_liqui_part_set,
  4681. UserOrgId: orgId,
  4682. Status: 1,
  4683. DeviceNumber: device_number_set,
  4684. DeviceType: device_type_set,
  4685. Name: name_set,
  4686. AdmissionNumber: admission_number_set,
  4687. DialysisNo: dialysis_no_set,
  4688. WeightBefor: weight_befor_set,
  4689. DryWeight: dry_weight_set,
  4690. BloodPressure: blood_pressure_set,
  4691. UltrafiltrationVolume: ultrafiltration_volume_set,
  4692. InternalFistula: internal_fistula_set,
  4693. BloodFlowVolume: blood_flow_volume_set,
  4694. Anticoagulant: anticoagulant_set,
  4695. SealingFluidDispose: sealing_fluid_dispose_set,
  4696. ModeId: mode_id_set,
  4697. DialysisTime: dialysis_time_set,
  4698. DialysisDialyszers: dialysis_dialyszers_set,
  4699. DialysisIrrigation: dialysis_irrigation_set,
  4700. Gaijiliang: gaijiliang_set,
  4701. Kalium: kalium_set,
  4702. DisplaceLiquiValue: displace_liqui_value_set,
  4703. Bicarbonate: bicarbonate_set,
  4704. Glucose: glucose_set,
  4705. Ctime: time.Now().Unix(),
  4706. Mtime: time.Now().Unix(),
  4707. }
  4708. err := service.SaveDialysisSetting(dialysisSetting)
  4709. if err == nil {
  4710. this.ServeSuccessJSON(map[string]interface{}{
  4711. "dialysisSetting": dialysisSetting,
  4712. })
  4713. return
  4714. } else {
  4715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4716. return
  4717. }
  4718. }
  4719. func (this *DialysisApiController) GetDialysisSetting() {
  4720. orgId := this.GetAdminUserInfo().CurrentOrgId
  4721. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4722. this.ServeSuccessJSON(map[string]interface{}{
  4723. "dialysisSett": dialysisSett,
  4724. })
  4725. return
  4726. }
  4727. func (this *DialysisApiController) GetDialysisParameterList() {
  4728. keyword := this.GetString("keywords")
  4729. limit, _ := this.GetInt64("limit")
  4730. page, _ := this.GetInt64("page")
  4731. partition_id, _ := this.GetInt64("partition_id")
  4732. schedule_type, _ := this.GetInt64("schedule_type")
  4733. start_time := this.GetString("schedule_date")
  4734. timeLayout := "2006-01-02"
  4735. loc, _ := time.LoadLocation("Local")
  4736. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4737. orgId := this.GetAdminUserInfo().CurrentOrgId
  4738. scheduids := this.GetString("ids")
  4739. var ids []string
  4740. if scheduids != "" {
  4741. ids = strings.Split(scheduids, ",")
  4742. }
  4743. list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4744. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4745. if err == nil {
  4746. this.ServeSuccessJSON(map[string]interface{}{
  4747. "list": list,
  4748. "total": total,
  4749. "dialysisSett": dialysisSett,
  4750. })
  4751. return
  4752. } else {
  4753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4754. return
  4755. }
  4756. }
  4757. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4758. orgId := this.GetAdminUserInfo().CurrentOrgId
  4759. schedule_type, _ := this.GetInt64("schedule_type")
  4760. //partion_type, _ := this.GetInt64("partion_type")
  4761. start_time := this.GetString("selected_date")
  4762. partion_type := this.GetString("partion_type")
  4763. var ids []string
  4764. ids = strings.Split(partion_type, ",")
  4765. timeLayout := "2006-01-02"
  4766. loc, _ := time.LoadLocation("Local")
  4767. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4768. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4769. if err == nil {
  4770. this.ServeSuccessJSON(map[string]interface{}{
  4771. "list": list,
  4772. })
  4773. return
  4774. } else {
  4775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4776. return
  4777. }
  4778. }
  4779. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4780. orgId := this.GetAdminUserInfo().CurrentOrgId
  4781. schedule_type, _ := this.GetInt64("schedule_type")
  4782. //partion_type, _ := this.GetInt64("partion_type")
  4783. partion_type := this.GetString("partion_type")
  4784. var ids []string
  4785. ids = strings.Split(partion_type, ",")
  4786. start_time := this.GetString("selected_date")
  4787. timeLayout := "2006-01-02"
  4788. loc, _ := time.LoadLocation("Local")
  4789. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4790. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4791. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4792. //获取长期医嘱
  4793. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4794. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4795. _, config := service.FindXTHisRecordByOrgId(orgId)
  4796. if err == nil {
  4797. this.ServeSuccessJSON(map[string]interface{}{
  4798. "list": list,
  4799. "drug": drug,
  4800. "adviceList": adviceList,
  4801. "config": config,
  4802. "tablelist": tablelist,
  4803. })
  4804. return
  4805. } else {
  4806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4807. return
  4808. }
  4809. }
  4810. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4811. orgId := this.GetAdminUserInfo().CurrentOrgId
  4812. schedule_type, _ := this.GetInt64("schedule_type")
  4813. partion_type, _ := this.GetInt64("partion_type")
  4814. start_time := this.GetString("selected_date")
  4815. timeLayout := "2006-01-02"
  4816. loc, _ := time.LoadLocation("Local")
  4817. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4818. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4819. if err == nil {
  4820. this.ServeSuccessJSON(map[string]interface{}{
  4821. "list": list,
  4822. })
  4823. return
  4824. } else {
  4825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4826. return
  4827. }
  4828. }
  4829. func (this *DialysisApiController) SaveHisDialysis() {
  4830. var ids []string
  4831. advice_ids := this.GetString("ids")
  4832. ids = strings.Split(advice_ids, ",")
  4833. orgId := this.GetAdminUserInfo().CurrentOrgId
  4834. service.SaveHisDialysis(orgId, ids)
  4835. returnData := make(map[string]interface{}, 0)
  4836. returnData["msg"] = "ok"
  4837. this.ServeSuccessJSON(returnData)
  4838. return
  4839. }
  4840. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4841. orgId := this.GetAdminUserInfo().CurrentOrgId
  4842. schedule_type, _ := this.GetInt64("schedule_type")
  4843. //partion_type, _ := this.GetInt64("partion_type")
  4844. partion_type := this.GetString("partion_type")
  4845. var ids []string
  4846. ids = strings.Split(partion_type, ",")
  4847. start_time := this.GetString("selected_date")
  4848. timeLayout := "2006-01-02"
  4849. loc, _ := time.LoadLocation("Local")
  4850. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4851. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4852. this.ServeSuccessJSON(map[string]interface{}{
  4853. "list": list,
  4854. })
  4855. return
  4856. }
  4857. func (this *DialysisApiController) GetPatientSchedule() {
  4858. orgId := this.GetAdminUserInfo().CurrentOrgId
  4859. patient_id, _ := this.GetInt64("patient_id")
  4860. schedule_date, _ := this.GetInt64("schedule_date")
  4861. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4862. this.ServeSuccessJSON(map[string]interface{}{
  4863. "schedulePatient": schedulePatient,
  4864. })
  4865. }
  4866. func (c *DialysisApiController) GetSchedulePrintList() {
  4867. page, _ := c.GetInt64("page", 1)
  4868. limit, _ := c.GetInt64("limit", 10)
  4869. schedulType, _ := c.GetInt64("schedule_type", 0)
  4870. partitionType, _ := c.GetInt64("partition_type", 0)
  4871. keywords := c.GetString("keywords")
  4872. schedule_date := c.GetString("schedule_date")
  4873. timeLayout := "2006-01-02"
  4874. loc, _ := time.LoadLocation("Local")
  4875. var theStartTime int64
  4876. if len(schedule_date) > 0 {
  4877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4878. if err != nil {
  4879. utils.ErrorLog(err.Error())
  4880. }
  4881. theStartTime = theTime.Unix()
  4882. }
  4883. adminUserInfo := c.GetAdminUserInfo()
  4884. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4885. for _, item := range list {
  4886. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4887. item.DialysisOrderTwenty = order
  4888. }
  4889. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4890. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4891. c.ServeSuccessJSON(map[string]interface{}{
  4892. "list": list,
  4893. "total": total,
  4894. "numberList": numberList,
  4895. "listOne": listOne,
  4896. })
  4897. }
  4898. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4899. orgId := this.GetAdminUserInfo().CurrentOrgId
  4900. list, _ := service.GetSolutionListByOrgId(orgId)
  4901. for _, item := range list {
  4902. //获取该模式最新的1条数据
  4903. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4904. //更新状态值
  4905. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4906. }
  4907. this.ServeSuccessJSON(map[string]interface{}{
  4908. "list": list,
  4909. })
  4910. }
  4911. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4912. orgId := this.GetAdminUserInfo().CurrentOrgId
  4913. is_open, _ := this.GetInt64("is_open")
  4914. idsStr := this.GetString("str")
  4915. recordIDStrs := strings.Split(idsStr, ",")
  4916. start_time := this.GetString("advice_date")
  4917. exec_time, _ := this.GetInt64("exec_time")
  4918. timeLayout := "2006-01-02"
  4919. loc, _ := time.LoadLocation("Local")
  4920. var startTime int64
  4921. if len(start_time) > 0 {
  4922. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4923. if err != nil {
  4924. //fmt.Println(err)
  4925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4926. return
  4927. }
  4928. startTime = theTime.Unix()
  4929. }
  4930. config, _ := service.GetDrugOpenConfigOne(orgId)
  4931. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4932. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4933. //his医嘱
  4934. if is_open == 1 {
  4935. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4936. //查找未执行医嘱
  4937. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4938. for _, item := range list {
  4939. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4940. this.ServeSuccessJSON(map[string]interface{}{
  4941. "msg": "3",
  4942. })
  4943. return
  4944. }
  4945. }
  4946. for _, item := range groupList {
  4947. for _, it := range list {
  4948. if item.DrugId == it.DrugId {
  4949. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4950. }
  4951. }
  4952. }
  4953. for _, item := range groupList {
  4954. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4955. var sum_out_count int64
  4956. for _, it := range item.ChildDoctorAdvice {
  4957. var prescribing_number int64
  4958. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4959. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4960. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4961. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4962. }
  4963. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4964. prescribing_number = parseIntPrescribingNumber
  4965. }
  4966. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4967. prescribing_number = parseIntPrescribingNumber
  4968. }
  4969. sum_out_count += prescribing_number
  4970. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4971. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4972. //库存不足
  4973. if sum_out_count > drugStockOut.FlushCount {
  4974. this.ServeSuccessJSON(map[string]interface{}{
  4975. "msg": "2",
  4976. "drug": medical,
  4977. })
  4978. return
  4979. }
  4980. }
  4981. }
  4982. creater := this.GetAdminUserInfo().AdminUser.Id
  4983. //执行出库逻辑
  4984. for _, item := range list {
  4985. hisadvice := &models.HisDoctorAdviceInfo{
  4986. ID: item.ID,
  4987. UserOrgId: item.UserOrgId,
  4988. PatientId: item.PatientId,
  4989. AdviceType: item.AdviceType,
  4990. AdviceDate: item.AdviceDate,
  4991. StartTime: item.StartTime,
  4992. AdviceName: item.AdviceName,
  4993. AdviceDesc: item.AdviceDesc,
  4994. ReminderDate: item.ReminderDate,
  4995. SingleDose: item.SingleDose,
  4996. SingleDoseUnit: item.SingleDoseUnit,
  4997. DrugSpec: item.DrugSpec,
  4998. DrugSpecUnit: item.DrugSpecUnit,
  4999. PrescribingNumber: item.PrescribingNumber,
  5000. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5001. DeliveryWay: item.DeliveryWay,
  5002. ExecutionFrequency: item.ExecutionFrequency,
  5003. AdviceDoctor: item.AdviceDoctor,
  5004. Status: 1,
  5005. CreatedTime: item.CreatedTime,
  5006. UpdatedTime: item.UpdatedTime,
  5007. AdviceAffirm: item.AdviceAffirm,
  5008. Remark: item.Remark,
  5009. StopTime: item.StopTime,
  5010. StopReason: item.StopReason,
  5011. StopDoctor: item.StopDoctor,
  5012. StopState: item.StopState,
  5013. ParentId: item.ParentId,
  5014. ExecutionTime: item.ExecutionTime,
  5015. ExecutionStaff: creater,
  5016. ExecutionState: item.ExecutionState,
  5017. Checker: item.Checker,
  5018. RecordDate: item.RecordDate,
  5019. DialysisOrderId: item.DialysisOrderId,
  5020. CheckTime: item.CheckTime,
  5021. CheckState: item.CheckState,
  5022. RemindType: item.RemindType,
  5023. FrequencyType: item.FrequencyType,
  5024. DayCount: item.DayCount,
  5025. WeekDay: item.WeekDay,
  5026. TemplateId: item.TemplateId,
  5027. Modifier: item.Modifier,
  5028. Way: item.Way,
  5029. DrugId: item.DrugId,
  5030. ExecutionFrequencyId: item.ExecutionFrequencyId,
  5031. }
  5032. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5033. if medical.IsUse == 2 {
  5034. if config.IsOpen != 1 {
  5035. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5036. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5037. }
  5038. //不通过药房发药
  5039. if pharmacyConfig.IsOpen != 1 {
  5040. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5041. }
  5042. //查询默认仓库
  5043. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5044. //查询默认仓库剩余多少库存
  5045. var sum_count int64
  5046. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5047. for _, its := range stockInfo {
  5048. if its.MaxUnit == medical.MaxUnit {
  5049. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5050. }
  5051. sum_count += its.StockMaxNumber + its.StockMinNumber
  5052. }
  5053. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5054. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5055. }
  5056. }
  5057. info := models.HisDoctorAdviceInfo{
  5058. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5059. ExecutionTime: exec_time,
  5060. ExecutionState: 1,
  5061. UpdatedTime: time.Now().Unix(),
  5062. }
  5063. //执行医嘱
  5064. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  5065. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5066. redis := service.RedisClient()
  5067. //清空key 值
  5068. redis.Set(key, "", time.Second)
  5069. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5070. redis.Set(keyTwo, "", time.Second)
  5071. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5072. redis.Set(keyThree, "", time.Second)
  5073. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5074. theTime := toTime.Format("2006-01-02")
  5075. fmt.Println("theTIME", theTime)
  5076. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5077. redis.Set(keyFour, "", time.Second)
  5078. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5079. redis.Set(keyFive, "", time.Second)
  5080. }
  5081. } else {
  5082. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  5083. //查找未执行医嘱
  5084. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5085. for _, item := range groupList {
  5086. for _, it := range list {
  5087. if item.DrugId == it.DrugId {
  5088. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5089. }
  5090. }
  5091. }
  5092. for _, item := range groupList {
  5093. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5094. var sum_out_count int64
  5095. for _, it := range item.ChildDoctorAdvice {
  5096. var prescribing_number int64
  5097. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5098. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5099. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5100. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5101. }
  5102. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5103. prescribing_number = parseIntPrescribingNumber
  5104. }
  5105. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5106. prescribing_number = parseIntPrescribingNumber
  5107. }
  5108. sum_out_count += prescribing_number
  5109. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5110. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5111. //库存不足
  5112. if sum_out_count > drugStockOut.FlushCount {
  5113. this.ServeSuccessJSON(map[string]interface{}{
  5114. "msg": "2",
  5115. "drug": medical,
  5116. })
  5117. return
  5118. }
  5119. }
  5120. }
  5121. for _, item := range list {
  5122. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5123. dadvice := &models.DoctorAdvice{
  5124. ID: item.ID,
  5125. UserOrgId: item.UserOrgId,
  5126. PatientId: item.PatientId,
  5127. AdviceType: item.AdviceType,
  5128. AdviceDate: item.AdviceDate,
  5129. StartTime: item.StartTime,
  5130. AdviceName: item.AdviceName,
  5131. AdviceDesc: item.AdviceDesc,
  5132. ReminderDate: item.ReminderDate,
  5133. SingleDose: item.SingleDose,
  5134. SingleDoseUnit: item.SingleDoseUnit,
  5135. DrugSpec: item.DrugSpec,
  5136. DrugSpecUnit: item.DrugSpecUnit,
  5137. PrescribingNumber: item.PrescribingNumber,
  5138. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5139. DeliveryWay: item.DeliveryWay,
  5140. ExecutionFrequency: item.ExecutionFrequency,
  5141. AdviceDoctor: item.AdviceDoctor,
  5142. Status: 1,
  5143. CreatedTime: item.CreatedTime,
  5144. UpdatedTime: item.UpdatedTime,
  5145. AdviceAffirm: item.AdviceAffirm,
  5146. Remark: item.Remark,
  5147. StopTime: item.StopTime,
  5148. StopReason: item.StopReason,
  5149. StopDoctor: item.StopDoctor,
  5150. StopState: item.StopState,
  5151. ParentId: item.ParentId,
  5152. ExecutionTime: item.ExecutionTime,
  5153. ExecutionStaff: item.ExecutionStaff,
  5154. ExecutionState: item.ExecutionState,
  5155. Checker: item.Checker,
  5156. RecordDate: item.ReminderDate,
  5157. DialysisOrderId: item.DialysisOrderId,
  5158. CheckTime: item.CheckTime,
  5159. CheckState: item.CheckState,
  5160. RemindType: item.RemindType,
  5161. FrequencyType: item.FrequencyType,
  5162. DayCount: item.DayCount,
  5163. WeekDay: item.WeekDay,
  5164. TemplateId: item.TemplateId,
  5165. Modifier: item.Modifier,
  5166. Way: item.Way,
  5167. DrugId: item.DrugId,
  5168. }
  5169. if medical.IsUse == 2 {
  5170. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5171. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5172. }
  5173. if pharmacyConfig.IsOpen != 1 {
  5174. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5175. }
  5176. //更新字典里面的库存
  5177. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5178. var sum_count int64
  5179. for _, its := range stockInfo {
  5180. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5181. if its.MaxUnit == baseDrug.MaxUnit {
  5182. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5183. }
  5184. sum_count += its.StockMaxNumber + its.StockMinNumber
  5185. }
  5186. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5187. //剩余库存
  5188. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5189. }
  5190. info := models.DoctorAdvice{
  5191. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5192. ExecutionTime: exec_time,
  5193. ExecutionState: 1,
  5194. UpdatedTime: time.Now().Unix(),
  5195. }
  5196. //执行医嘱
  5197. service.UpdateDoctorAdviceExecution(info, item.ID)
  5198. }
  5199. }
  5200. this.ServeSuccessJSON(map[string]interface{}{
  5201. "msg": "1",
  5202. })
  5203. return
  5204. }
  5205. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  5206. orgId := this.GetAdminUserInfo().CurrentOrgId
  5207. idsStr := this.GetString("str")
  5208. recordIDStrs := strings.Split(idsStr, ",")
  5209. start_time := this.GetString("advice_date")
  5210. timeLayout := "2006-01-02"
  5211. loc, _ := time.LoadLocation("Local")
  5212. var startTime int64
  5213. if len(start_time) > 0 {
  5214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5215. if err != nil {
  5216. //fmt.Println(err)
  5217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5218. return
  5219. }
  5220. startTime = theTime.Unix()
  5221. }
  5222. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5223. if config.IsOpen == 1 {
  5224. creater := this.GetAdminUserInfo().AdminUser.Id
  5225. //查询未核对的医嘱
  5226. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5227. for _, item := range advicelist {
  5228. if item.ExecutionStaff == creater {
  5229. this.ServeSuccessJSON(map[string]interface{}{
  5230. "msg": "2",
  5231. "advice": item,
  5232. })
  5233. return
  5234. }
  5235. service.CheckHisDoctorAdvice(item.ID, creater)
  5236. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5237. redis := service.RedisClient()
  5238. //清空key 值
  5239. redis.Set(key, "", time.Second)
  5240. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5241. redis.Set(keyTwo, "", time.Second)
  5242. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5243. redis.Set(keyThree, "", time.Second)
  5244. theTime := time.Now()
  5245. recordDate := theTime.Format("2006-01-02")
  5246. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5247. redis.Set(keyFour, "", time.Second)
  5248. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5249. redis.Set(keyFive, "", time.Second)
  5250. }
  5251. } else {
  5252. //查询未核对的医嘱
  5253. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5254. creater := this.GetAdminUserInfo().AdminUser.Id
  5255. for _, item := range advicelist {
  5256. if item.ExecutionStaff == creater {
  5257. this.ServeSuccessJSON(map[string]interface{}{
  5258. "msg": "2",
  5259. "advice": item,
  5260. })
  5261. return
  5262. }
  5263. service.CheckDoctorAdvice(item.ID, creater)
  5264. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5265. redis := service.RedisClient()
  5266. //清空key 值
  5267. redis.Set(key, "", time.Second)
  5268. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5269. redis.Set(keyTwo, "", time.Second)
  5270. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5271. redis.Set(keyThree, "", time.Second)
  5272. theTime := time.Now()
  5273. recordDate := theTime.Format("2006-01-02")
  5274. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5275. redis.Set(keyFour, "", time.Second)
  5276. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5277. redis.Set(keyFive, "", time.Second)
  5278. }
  5279. }
  5280. this.ServeSuccessJSON(map[string]interface{}{
  5281. "msg": "1",
  5282. })
  5283. return
  5284. }
  5285. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5286. orgId := this.GetAdminUserInfo().CurrentOrgId
  5287. is_open, _ := this.GetInt64("is_open")
  5288. idsStr := this.GetString("str")
  5289. recordIDStrs := strings.Split(idsStr, ",")
  5290. start_time := this.GetString("advice_date")
  5291. timeLayout := "2006-01-02"
  5292. loc, _ := time.LoadLocation("Local")
  5293. var startTime int64
  5294. if len(start_time) > 0 {
  5295. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5296. if err != nil {
  5297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5298. return
  5299. }
  5300. startTime = theTime.Unix()
  5301. }
  5302. if is_open == 1 {
  5303. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5304. } else {
  5305. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5306. }
  5307. this.ServeSuccessJSON(map[string]interface{}{
  5308. "msg": "1",
  5309. })
  5310. return
  5311. }
  5312. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5313. advice_id, _ := this.GetInt64("advice_id")
  5314. start_time := this.GetString("advice_date")
  5315. orgId := this.GetAdminUserInfo().CurrentOrgId
  5316. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5317. exec_time, _ := this.GetInt64("exec_time")
  5318. //his医嘱
  5319. if config.IsOpen == 1 {
  5320. //查询医嘱
  5321. advice, _ := service.GetHisDocById(advice_id, orgId)
  5322. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5323. this.ServeSuccessJSON(map[string]interface{}{
  5324. "msg": "3",
  5325. })
  5326. return
  5327. }
  5328. medical, _ := service.GetBaseDrugMedical(orgId)
  5329. var prescribing_number int64
  5330. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5331. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5332. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5333. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5334. }
  5335. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5336. prescribing_number = parseIntPrescribingNumber
  5337. }
  5338. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5339. prescribing_number = parseIntPrescribingNumber
  5340. }
  5341. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5342. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5343. //库存不足
  5344. if prescribing_number > drugStockOut.FlushCount {
  5345. this.ServeSuccessJSON(map[string]interface{}{
  5346. "msg": "2",
  5347. "drug": medical,
  5348. })
  5349. return
  5350. }
  5351. info := models.HisDoctorAdviceInfo{
  5352. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5353. ExecutionTime: exec_time,
  5354. ExecutionState: 1,
  5355. UpdatedTime: time.Now().Unix(),
  5356. }
  5357. //执行医嘱
  5358. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5359. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5360. redis := service.RedisClient()
  5361. //清空key 值
  5362. redis.Set(key, "", time.Second)
  5363. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5364. redis.Set(keyTwo, "", time.Second)
  5365. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5366. redis.Set(keyThree, "", time.Second)
  5367. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5368. theTime := toTime.Format("2006-01-02")
  5369. fmt.Println("theTIME", theTime)
  5370. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5371. redis.Set(keyFour, "", time.Second)
  5372. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5373. redis.Set(keyFive, "", time.Second)
  5374. //出库
  5375. if prescribing_number <= drugStockOut.FlushCount {
  5376. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5377. //执行出库逻辑
  5378. hisadvice := &models.HisDoctorAdviceInfo{
  5379. ID: advice.ID,
  5380. UserOrgId: advice.UserOrgId,
  5381. PatientId: advice.PatientId,
  5382. AdviceType: advice.AdviceType,
  5383. AdviceDate: advice.AdviceDate,
  5384. StartTime: advice.StartTime,
  5385. AdviceName: advice.AdviceName,
  5386. AdviceDesc: advice.AdviceDesc,
  5387. ReminderDate: advice.ReminderDate,
  5388. SingleDose: advice.SingleDose,
  5389. SingleDoseUnit: advice.SingleDoseUnit,
  5390. DrugSpec: advice.DrugSpec,
  5391. DrugSpecUnit: advice.DrugSpecUnit,
  5392. PrescribingNumber: advice.PrescribingNumber,
  5393. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5394. DeliveryWay: advice.DeliveryWay,
  5395. ExecutionFrequency: advice.ExecutionFrequency,
  5396. AdviceDoctor: advice.AdviceDoctor,
  5397. Status: 1,
  5398. CreatedTime: advice.CreatedTime,
  5399. UpdatedTime: advice.UpdatedTime,
  5400. AdviceAffirm: advice.AdviceAffirm,
  5401. Remark: advice.Remark,
  5402. StopTime: advice.StopTime,
  5403. StopReason: advice.StopReason,
  5404. StopDoctor: advice.StopDoctor,
  5405. StopState: advice.StopState,
  5406. ParentId: advice.ParentId,
  5407. ExecutionTime: advice.ExecutionTime,
  5408. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5409. ExecutionState: advice.ExecutionState,
  5410. Checker: advice.Checker,
  5411. RecordDate: advice.RecordDate,
  5412. DialysisOrderId: advice.DialysisOrderId,
  5413. CheckTime: advice.CheckTime,
  5414. CheckState: advice.CheckState,
  5415. RemindType: advice.RemindType,
  5416. FrequencyType: advice.FrequencyType,
  5417. DayCount: advice.DayCount,
  5418. WeekDay: advice.WeekDay,
  5419. TemplateId: advice.TemplateId,
  5420. Modifier: advice.Modifier,
  5421. Way: advice.Way,
  5422. DrugId: advice.DrugId,
  5423. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5424. }
  5425. if medical.IsUse == 2 {
  5426. if config.IsOpen != 1 {
  5427. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5428. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5429. }
  5430. //不通过药房发药
  5431. if pharmacyConfig.IsOpen != 1 {
  5432. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5433. }
  5434. //查询默认仓库
  5435. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5436. //查询默认仓库剩余多少库存
  5437. var sum_count int64
  5438. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5439. for _, its := range stockInfo {
  5440. if its.MaxUnit == medical.MaxUnit {
  5441. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5442. }
  5443. sum_count += its.StockMaxNumber + its.StockMinNumber
  5444. }
  5445. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5446. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5447. }
  5448. }
  5449. }
  5450. this.ServeSuccessJSON(map[string]interface{}{
  5451. "msg": "1",
  5452. })
  5453. return
  5454. }
  5455. if config.IsOpen == 2 || config.IsOpen == 0 {
  5456. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5457. medical, _ := service.GetBaseDrugMedical(orgId)
  5458. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5459. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5460. var prescribing_number int64
  5461. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5462. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5463. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5464. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5465. }
  5466. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5467. prescribing_number = parseIntPrescribingNumber
  5468. }
  5469. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5470. prescribing_number = parseIntPrescribingNumber
  5471. }
  5472. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5473. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5474. //库存不足
  5475. if prescribing_number > drugStockOut.FlushCount {
  5476. this.ServeSuccessJSON(map[string]interface{}{
  5477. "msg": "2",
  5478. "drug": medical,
  5479. })
  5480. return
  5481. }
  5482. info := models.DoctorAdvice{
  5483. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5484. ExecutionTime: exec_time,
  5485. ExecutionState: 1,
  5486. UpdatedTime: time.Now().Unix(),
  5487. }
  5488. //执行医嘱
  5489. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5490. dadvice := &models.DoctorAdvice{
  5491. ID: advice.ID,
  5492. UserOrgId: advice.UserOrgId,
  5493. PatientId: advice.PatientId,
  5494. AdviceType: advice.AdviceType,
  5495. AdviceDate: advice.AdviceDate,
  5496. StartTime: advice.StartTime,
  5497. AdviceName: advice.AdviceName,
  5498. AdviceDesc: advice.AdviceDesc,
  5499. ReminderDate: advice.ReminderDate,
  5500. SingleDose: advice.SingleDose,
  5501. SingleDoseUnit: advice.SingleDoseUnit,
  5502. DrugSpec: advice.DrugSpec,
  5503. DrugSpecUnit: advice.DrugSpecUnit,
  5504. PrescribingNumber: advice.PrescribingNumber,
  5505. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5506. DeliveryWay: advice.DeliveryWay,
  5507. ExecutionFrequency: advice.ExecutionFrequency,
  5508. AdviceDoctor: advice.AdviceDoctor,
  5509. Status: 1,
  5510. CreatedTime: advice.CreatedTime,
  5511. UpdatedTime: advice.UpdatedTime,
  5512. AdviceAffirm: advice.AdviceAffirm,
  5513. Remark: advice.Remark,
  5514. StopTime: advice.StopTime,
  5515. StopReason: advice.StopReason,
  5516. StopDoctor: advice.StopDoctor,
  5517. StopState: advice.StopState,
  5518. ParentId: advice.ParentId,
  5519. ExecutionTime: advice.ExecutionTime,
  5520. ExecutionStaff: advice.ExecutionStaff,
  5521. ExecutionState: advice.ExecutionState,
  5522. Checker: advice.Checker,
  5523. RecordDate: advice.ReminderDate,
  5524. DialysisOrderId: advice.DialysisOrderId,
  5525. CheckTime: advice.CheckTime,
  5526. CheckState: advice.CheckState,
  5527. RemindType: advice.RemindType,
  5528. FrequencyType: advice.FrequencyType,
  5529. DayCount: advice.DayCount,
  5530. WeekDay: advice.WeekDay,
  5531. TemplateId: advice.TemplateId,
  5532. Modifier: advice.Modifier,
  5533. Way: advice.Way,
  5534. DrugId: advice.DrugId,
  5535. }
  5536. if medical.IsUse == 2 {
  5537. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5538. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5539. }
  5540. if pharmacyConfig.IsOpen != 1 {
  5541. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5542. }
  5543. //更新字典里面的库存
  5544. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5545. var sum_count int64
  5546. for _, its := range stockInfo {
  5547. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5548. if its.MaxUnit == baseDrug.MaxUnit {
  5549. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5550. }
  5551. sum_count += its.StockMaxNumber + its.StockMinNumber
  5552. }
  5553. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5554. //剩余库存
  5555. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5556. }
  5557. }
  5558. this.ServeSuccessJSON(map[string]interface{}{
  5559. "msg": "1",
  5560. })
  5561. return
  5562. }
  5563. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5564. orgId := this.GetAdminUserInfo().CurrentOrgId
  5565. schedule_type, _ := this.GetInt64("schedule_type")
  5566. //partion_type, _ := this.GetInt64("partion_type")
  5567. partion_type := this.GetString("partion_type")
  5568. var ids []string
  5569. ids = strings.Split(partion_type, ",")
  5570. start_time := this.GetString("selected_date")
  5571. timeLayout := "2006-01-02"
  5572. loc, _ := time.LoadLocation("Local")
  5573. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5574. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5575. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5576. _, config := service.FindXTHisRecordByOrgId(orgId)
  5577. appId := this.GetAdminUserInfo().CurrentAppId
  5578. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5579. if err == nil {
  5580. this.ServeSuccessJSON(map[string]interface{}{
  5581. "list": list,
  5582. "drug": drug,
  5583. "config": config,
  5584. "doctorList": doctorList,
  5585. })
  5586. return
  5587. } else {
  5588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5589. return
  5590. }
  5591. }
  5592. func (this *DialysisApiController) GetMobileScheduleList() {
  5593. orgId := this.GetAdminUserInfo().CurrentOrgId
  5594. schedule, _ := service.GetMobileScheduleList(orgId)
  5595. if len(schedule) > 0 {
  5596. for _, its := range schedule {
  5597. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5598. //its.DialysisPrescription = prescription
  5599. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5600. //its.MonitoringRecord = monitor
  5601. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5602. //its.XtAssessmentAfterDislysis = after
  5603. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5604. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5605. }
  5606. }
  5607. this.ServeSuccessJSON(map[string]interface{}{
  5608. "schedule": schedule,
  5609. })
  5610. return
  5611. }
  5612. func (this *DialysisApiController) SaveInformation() {
  5613. patient_id, _ := this.GetInt64("patient_id")
  5614. record_date, _ := this.GetInt64("record_date")
  5615. adviceDate := this.GetString("selected_date")
  5616. timeLayout2 := "2006-01-02"
  5617. loc2, _ := time.LoadLocation("Local")
  5618. theTime, _ := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5619. AdviceDate := theTime.Unix()
  5620. module, _ := this.GetInt64("module")
  5621. remark := this.GetString("remark")
  5622. orgId := this.GetAdminUserInfo().CurrentOrgId
  5623. creater := this.GetAdminUserInfo().AdminUser.Id
  5624. information := models.XtDialysisInformation{
  5625. Module: module,
  5626. PatientId: patient_id,
  5627. RecordDate: record_date,
  5628. ApplicationDate: AdviceDate,
  5629. Creater: creater,
  5630. ApplicationStatus: 2,
  5631. Checker: 0,
  5632. CheckTime: 0,
  5633. Remark: remark,
  5634. UserOrgId: orgId,
  5635. Ctime: time.Now().Unix(),
  5636. Status: 1,
  5637. Mtime: 0,
  5638. }
  5639. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  5640. if infor.ID == 0 {
  5641. err := service.CreatedDialysisInformation(information)
  5642. if err == nil {
  5643. this.ServeSuccessJSON(map[string]interface{}{
  5644. "information": information,
  5645. })
  5646. return
  5647. }
  5648. }
  5649. if infor.ID > 0 {
  5650. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, AdviceDate, remark)
  5651. if err == nil {
  5652. this.ServeSuccessJSON(map[string]interface{}{
  5653. "information": information,
  5654. })
  5655. return
  5656. }
  5657. }
  5658. }