dialysis_api_controller.go 299KB

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