dialysis_api_controller.go 289KB

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