dialysis_api_controller.go 259KB

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