dialysis_api_controller.go 310KB

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