dialysis_api_controller.go 281KB

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