dialysis_api_controller.go 253KB

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