dialysis_api_controller.go 280KB

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