dialysis_api_controller.go 258KB

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