dialysis_api_controller.go 284KB

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