dialysis_api_controller.go 289KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906
  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. if adminUserInfo.CurrentOrgId == 10644 {
  2225. assessmentBeforeDislysis.PunctureNeedle = ""
  2226. }
  2227. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2228. //记录日志
  2229. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2230. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2231. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2232. AdminUserId: adminUserInfo.AdminUser.Id,
  2233. ErrLog: string(byterequest),
  2234. PatientId: assessmentBeforeDislysis.PatientId,
  2235. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2236. Ctime: time.Now().Unix(),
  2237. Mtime: 0,
  2238. Status: 1,
  2239. Source: "电脑端保存透前评估",
  2240. }
  2241. service.CreateBeforLog(beforeDislysisLog)
  2242. //创建步骤表
  2243. finish := models.XtDialysisFinish{
  2244. IsFinish: 1,
  2245. UserOrgId: adminUserInfo.CurrentOrgId,
  2246. Status: 1,
  2247. Ctime: time.Now().Unix(),
  2248. Mtime: 0,
  2249. Module: 3,
  2250. RecordDate: recordDate.Unix(),
  2251. Sourse: 1,
  2252. PatientId: patient,
  2253. }
  2254. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2255. if dialysisFinish.ID == 0 {
  2256. service.CreateDialysisFinish(finish)
  2257. }
  2258. 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 {
  2259. var dewater_amount float64
  2260. dewater_amount = 0
  2261. if dry_weight > 0 {
  2262. dewater_amount = weight_before - dry_weight - additional_weight
  2263. if adminUserInfo.CurrentOrgId != 10551 && adminUserInfo.CurrentOrgId != 10579 && adminUserInfo.CurrentOrgId != 10580 && adminUserInfo.CurrentOrgId != 10585 && adminUserInfo.CurrentOrgId != 10344 && adminUserInfo.CurrentOrgId != 10622 && adminUserInfo.CurrentOrgId != 10702 {
  2264. dewater_amount = dewater_amount * 1000
  2265. }
  2266. if dewater_amount <= 0 {
  2267. dewater_amount = 0
  2268. }
  2269. } else {
  2270. dewater_amount = 0
  2271. }
  2272. // 计算透析处方的相关超滤量
  2273. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2274. var lastDialysisPrescribe *models.DialysisPrescription
  2275. var dialysisSolution *models.DialysisSolution
  2276. var dialysisPrescribe *models.DialysisPrescription
  2277. var mode_id int64
  2278. if schedual != nil {
  2279. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2280. if dialysisPrescribe == nil {
  2281. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2282. }
  2283. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2284. // 获取透析模版
  2285. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2286. mode_id = schedual.ModeId
  2287. } else {
  2288. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2289. // 获取透析模版
  2290. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2291. // 获取透析模版
  2292. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2293. if dialysisPrescribe == nil && dialysisSolution != nil {
  2294. mode_id = dialysisSolution.ModeId
  2295. }
  2296. if dialysisPrescribe == nil && dialysisSolution == nil {
  2297. mode_id = 0
  2298. }
  2299. }
  2300. // 插入透析处方
  2301. if dialysisPrescribe == nil && dialysisSolution != nil {
  2302. var newprescribe models.DialysisPrescription
  2303. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2304. newprescribe.PatientId = patient
  2305. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2306. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2307. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2308. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2309. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2310. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2311. newprescribe.ModeId = dialysisSolution.ModeId
  2312. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2313. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2314. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2315. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2316. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2317. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2318. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2319. newprescribe.Glucose = dialysisSolution.Glucose
  2320. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2321. newprescribe.Kalium = dialysisSolution.Kalium
  2322. newprescribe.Sodium = dialysisSolution.Sodium
  2323. newprescribe.Calcium = dialysisSolution.Calcium
  2324. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2325. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2326. newprescribe.Conductivity = dialysisSolution.Conductivity
  2327. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2328. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2329. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2330. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2331. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2332. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2333. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2334. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2335. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2336. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2337. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2338. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2339. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2340. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2341. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2342. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2343. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2344. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2345. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2346. newprescribe.CreatedTime = time.Now().Unix()
  2347. newprescribe.UpdatedTime = time.Now().Unix()
  2348. newprescribe.RecordDate = recordDate.Unix()
  2349. newprescribe.DewaterAmount = dewater_amount
  2350. newprescribe.TargetUltrafiltration = dewater_amount
  2351. newprescribe.PrescriptionWater = dewater_amount
  2352. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2353. newprescribe.Status = 1
  2354. if adminUserInfo.CurrentOrgId == 10579 {
  2355. newprescribe.Modifier = 0
  2356. newprescribe.PrescriptionDoctor = 0
  2357. newprescribe.Creater = 0
  2358. }
  2359. err := service.AddSigleRecord(&newprescribe)
  2360. //记录日志
  2361. byterequest, _ := json.Marshal(newprescribe)
  2362. prescriptionLog := models.XtDialysisPrescriptionLog{
  2363. UserOrgId: newprescribe.UserOrgId,
  2364. Ctime: time.Now().Unix(),
  2365. Mtime: 0,
  2366. ErrLog: string(byterequest),
  2367. AdminUserId: adminUserInfo.AdminUser.Id,
  2368. RecordDate: newprescribe.RecordDate,
  2369. PatientId: newprescribe.PatientId,
  2370. Source: "电脑端透前评估保存",
  2371. Status: 1,
  2372. }
  2373. service.CreatePrescriptionLog(prescriptionLog)
  2374. if err != nil {
  2375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2376. }
  2377. }
  2378. if dialysisPrescribe == nil && dialysisSolution == nil {
  2379. if lastDialysisPrescribe != nil {
  2380. var newprescribe models.DialysisPrescription
  2381. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2382. newprescribe.PatientId = patient
  2383. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2384. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2385. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2386. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2387. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2388. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2389. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2390. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2391. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2392. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2393. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2394. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2395. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2396. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2397. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2398. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2399. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2400. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2401. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2402. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2403. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2404. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2405. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2406. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2407. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2408. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2409. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2410. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2411. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2412. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2413. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2414. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2415. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2416. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2417. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2418. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2419. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2420. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2421. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2422. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2423. newprescribe.CreatedTime = time.Now().Unix()
  2424. newprescribe.UpdatedTime = time.Now().Unix()
  2425. newprescribe.RecordDate = recordDate.Unix()
  2426. newprescribe.DewaterAmount = dewater_amount
  2427. newprescribe.PrescriptionWater = dewater_amount
  2428. newprescribe.TargetUltrafiltration = dewater_amount
  2429. newprescribe.Status = 1
  2430. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2431. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2432. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2433. if adminUserInfo.CurrentOrgId == 10579 {
  2434. newprescribe.Modifier = 0
  2435. newprescribe.PrescriptionDoctor = 0
  2436. newprescribe.Creater = 0
  2437. }
  2438. err := service.AddSigleRecord(&newprescribe)
  2439. //记录日志
  2440. byterequest, _ := json.Marshal(newprescribe)
  2441. prescriptionLog := models.XtDialysisPrescriptionLog{
  2442. UserOrgId: newprescribe.UserOrgId,
  2443. Ctime: time.Now().Unix(),
  2444. Mtime: 0,
  2445. ErrLog: string(byterequest),
  2446. AdminUserId: adminUserInfo.AdminUser.Id,
  2447. RecordDate: newprescribe.RecordDate,
  2448. PatientId: newprescribe.PatientId,
  2449. Source: "电脑端透前评估保存",
  2450. Status: 1,
  2451. }
  2452. service.CreatePrescriptionLog(prescriptionLog)
  2453. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2454. redis := service.RedisClient()
  2455. defer redis.Close()
  2456. //清空key 值
  2457. redis.Set(key, "", time.Second)
  2458. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2459. redis.Set(keyOne, "", time.Second)
  2460. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2461. redis.Set(keyThree, "", time.Second)
  2462. if err != nil {
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2464. }
  2465. } else {
  2466. var newprescribe models.DialysisPrescription
  2467. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2468. newprescribe.PatientId = patient
  2469. newprescribe.ModeId = mode_id
  2470. newprescribe.CreatedTime = time.Now().Unix()
  2471. newprescribe.UpdatedTime = time.Now().Unix()
  2472. newprescribe.RecordDate = recordDate.Unix()
  2473. newprescribe.DewaterAmount = dewater_amount
  2474. newprescribe.TargetUltrafiltration = dewater_amount
  2475. newprescribe.Status = 1
  2476. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2477. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2478. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2479. if adminUserInfo.CurrentOrgId == 10579 {
  2480. newprescribe.Modifier = 0
  2481. newprescribe.PrescriptionDoctor = 0
  2482. newprescribe.Creater = 0
  2483. }
  2484. err := service.AddSigleRecord(&newprescribe)
  2485. //记录日志
  2486. byterequest, _ := json.Marshal(newprescribe)
  2487. prescriptionLog := models.XtDialysisPrescriptionLog{
  2488. UserOrgId: newprescribe.UserOrgId,
  2489. Ctime: time.Now().Unix(),
  2490. Mtime: 0,
  2491. ErrLog: string(byterequest),
  2492. AdminUserId: adminUserInfo.AdminUser.Id,
  2493. RecordDate: newprescribe.RecordDate,
  2494. PatientId: newprescribe.PatientId,
  2495. Source: "电脑端透前评估保存",
  2496. Status: 1,
  2497. }
  2498. service.CreatePrescriptionLog(prescriptionLog)
  2499. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2500. redis := service.RedisClient()
  2501. defer redis.Close()
  2502. //清空key 值
  2503. redis.Set(key, "", time.Second)
  2504. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2505. redis.Set(keyOne, "", time.Second)
  2506. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2507. redis.Set(keyThree, "", time.Second)
  2508. if err != nil {
  2509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2510. }
  2511. }
  2512. }
  2513. }
  2514. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2515. redis := service.RedisClient()
  2516. //清空key 值
  2517. redis.Set(key, "", time.Second)
  2518. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2519. redis.Set(keyOne, "", time.Second)
  2520. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2521. redis.Set(keyTwo, "", time.Second)
  2522. defer redis.Close()
  2523. if err == nil {
  2524. c.ServeSuccessJSON(map[string]interface{}{
  2525. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2526. })
  2527. } else {
  2528. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2530. }
  2531. } else { //修改
  2532. //if appRole.UserType == 3 {
  2533. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2534. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2535. // if getPermissionErr != nil {
  2536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2537. // return
  2538. // } else if headNursePermission == nil {
  2539. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2540. // return
  2541. // }
  2542. // }
  2543. //}
  2544. if appRole.UserType == 2 || appRole.UserType == 1 {
  2545. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2546. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2547. } else {
  2548. if evaluation.Creater == 0 {
  2549. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2550. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2551. } else {
  2552. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2553. }
  2554. }
  2555. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2556. assessmentBeforeDislysis.ID = evaluation.ID
  2557. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2558. //
  2559. //新增逻辑
  2560. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2561. var dewater_amount float64
  2562. dewater_amount = 0
  2563. if evaluation.DryWeight > 0 {
  2564. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2565. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 || adminUserInfo.CurrentOrgId == 10551 {
  2566. if adminUserInfo.CurrentOrgId != 10551 {
  2567. dewater_amount = dewater_amount * 1000
  2568. }
  2569. }
  2570. if dewater_amount <= 0 {
  2571. dewater_amount = 0
  2572. }
  2573. } else {
  2574. dewater_amount = 0
  2575. }
  2576. // 计算透析处方的相关超滤量
  2577. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2578. var lastDialysisPrescribe *models.DialysisPrescription
  2579. var dialysisSolution *models.DialysisSolution
  2580. var dialysisPrescribe *models.DialysisPrescription
  2581. var mode_id int64
  2582. if schedual != nil {
  2583. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2584. if dialysisPrescribe == nil {
  2585. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2586. }
  2587. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2588. // 获取透析模版
  2589. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2590. mode_id = schedual.ModeId
  2591. } else {
  2592. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2593. // 获取透析模版
  2594. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2595. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2596. if dialysisPrescribe == nil && dialysisSolution != nil {
  2597. mode_id = dialysisSolution.ModeId
  2598. }
  2599. if dialysisPrescribe == nil && dialysisSolution == nil {
  2600. mode_id = 0
  2601. }
  2602. }
  2603. // 插入透析处方
  2604. if dialysisPrescribe == nil && dialysisSolution != nil {
  2605. var newprescribe models.DialysisPrescription
  2606. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2607. newprescribe.PatientId = patient
  2608. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2609. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2610. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2611. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2612. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2613. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2614. newprescribe.ModeId = dialysisSolution.ModeId
  2615. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2616. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2617. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2618. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2619. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2620. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2621. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2622. newprescribe.Glucose = dialysisSolution.Glucose
  2623. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2624. newprescribe.Kalium = dialysisSolution.Kalium
  2625. newprescribe.Sodium = dialysisSolution.Sodium
  2626. newprescribe.Calcium = dialysisSolution.Calcium
  2627. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2628. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2629. newprescribe.Conductivity = dialysisSolution.Conductivity
  2630. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2631. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2632. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2633. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2634. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2635. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2636. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2637. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2638. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2639. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2640. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2641. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2642. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2643. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2644. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2645. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2646. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2647. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2648. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2649. newprescribe.CreatedTime = time.Now().Unix()
  2650. newprescribe.UpdatedTime = time.Now().Unix()
  2651. newprescribe.RecordDate = recordDate.Unix()
  2652. newprescribe.DewaterAmount = dewater_amount
  2653. newprescribe.TargetUltrafiltration = dewater_amount
  2654. newprescribe.PrescriptionWater = dewater_amount
  2655. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2656. newprescribe.Status = 1
  2657. if adminUserInfo.CurrentOrgId == 10579 {
  2658. newprescribe.Modifier = 0
  2659. newprescribe.PrescriptionDoctor = 0
  2660. newprescribe.Creater = 0
  2661. }
  2662. err := service.AddSigleRecord(&newprescribe)
  2663. //记录日志
  2664. byterequest, _ := json.Marshal(newprescribe)
  2665. prescriptionLog := models.XtDialysisPrescriptionLog{
  2666. UserOrgId: newprescribe.UserOrgId,
  2667. Ctime: time.Now().Unix(),
  2668. Mtime: 0,
  2669. ErrLog: string(byterequest),
  2670. AdminUserId: adminUserInfo.AdminUser.Id,
  2671. RecordDate: newprescribe.RecordDate,
  2672. PatientId: newprescribe.PatientId,
  2673. Source: "电脑端透前评估保存",
  2674. Status: 1,
  2675. }
  2676. service.CreatePrescriptionLog(prescriptionLog)
  2677. if err != nil {
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2679. }
  2680. }
  2681. if dialysisPrescribe == nil && dialysisSolution == nil {
  2682. if lastDialysisPrescribe != nil {
  2683. var newprescribe models.DialysisPrescription
  2684. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2685. newprescribe.PatientId = patient
  2686. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2687. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2688. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2689. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2690. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2691. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2692. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2693. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2694. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2695. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2696. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2697. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2698. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2699. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2700. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2701. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2702. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2703. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2704. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2705. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2706. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2707. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2708. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2709. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2710. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2711. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2712. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2713. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2714. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2715. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2716. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2717. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2718. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2719. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2720. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2721. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2722. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2723. newprescribe.CreatedTime = time.Now().Unix()
  2724. newprescribe.UpdatedTime = time.Now().Unix()
  2725. newprescribe.RecordDate = recordDate.Unix()
  2726. newprescribe.DewaterAmount = dewater_amount
  2727. newprescribe.TargetUltrafiltration = dewater_amount
  2728. newprescribe.PrescriptionWater = dewater_amount
  2729. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2730. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2731. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2732. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2733. newprescribe.Status = 1
  2734. if adminUserInfo.CurrentOrgId == 10579 {
  2735. newprescribe.Modifier = 0
  2736. newprescribe.PrescriptionDoctor = 0
  2737. newprescribe.Creater = 0
  2738. }
  2739. err := service.AddSigleRecord(&newprescribe)
  2740. //记录日志
  2741. byterequest, _ := json.Marshal(newprescribe)
  2742. prescriptionLog := models.XtDialysisPrescriptionLog{
  2743. UserOrgId: newprescribe.UserOrgId,
  2744. Ctime: time.Now().Unix(),
  2745. Mtime: 0,
  2746. ErrLog: string(byterequest),
  2747. AdminUserId: adminUserInfo.AdminUser.Id,
  2748. RecordDate: newprescribe.RecordDate,
  2749. PatientId: newprescribe.PatientId,
  2750. Source: "电脑端透前评估保存",
  2751. Status: 1,
  2752. }
  2753. service.CreatePrescriptionLog(prescriptionLog)
  2754. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2755. redis := service.RedisClient()
  2756. defer redis.Close()
  2757. //清空key 值
  2758. redis.Set(key, "", time.Second)
  2759. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2760. redis.Set(keyOne, "", time.Second)
  2761. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2762. redis.Set(keyThree, "", time.Second)
  2763. if err != nil {
  2764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2765. }
  2766. } else {
  2767. var newprescribe models.DialysisPrescription
  2768. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2769. newprescribe.PatientId = patient
  2770. newprescribe.ModeId = mode_id
  2771. newprescribe.CreatedTime = time.Now().Unix()
  2772. newprescribe.UpdatedTime = time.Now().Unix()
  2773. newprescribe.RecordDate = recordDate.Unix()
  2774. newprescribe.DewaterAmount = dewater_amount
  2775. newprescribe.TargetUltrafiltration = dewater_amount
  2776. newprescribe.Status = 1
  2777. err := service.AddSigleRecord(&newprescribe)
  2778. //记录日志
  2779. byterequest, _ := json.Marshal(newprescribe)
  2780. prescriptionLog := models.XtDialysisPrescriptionLog{
  2781. UserOrgId: newprescribe.UserOrgId,
  2782. Ctime: time.Now().Unix(),
  2783. Mtime: 0,
  2784. ErrLog: string(byterequest),
  2785. AdminUserId: adminUserInfo.AdminUser.Id,
  2786. RecordDate: newprescribe.RecordDate,
  2787. PatientId: newprescribe.PatientId,
  2788. Source: "电脑端透前评估保存",
  2789. Status: 1,
  2790. }
  2791. service.CreatePrescriptionLog(prescriptionLog)
  2792. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2793. redis := service.RedisClient()
  2794. defer redis.Close()
  2795. //清空key 值
  2796. redis.Set(key, "", time.Second)
  2797. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2798. redis.Set(keyOne, "", time.Second)
  2799. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2800. redis.Set(keyThree, "", time.Second)
  2801. if err != nil {
  2802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2803. }
  2804. }
  2805. }
  2806. // 查询信息规挡的设置天数
  2807. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2808. if infor.ID > 0 {
  2809. var cha_time int64
  2810. timeNowStr := time.Now().Format("2006-01-02")
  2811. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2812. //今日的日期减去设置的日期
  2813. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2814. if cha_time >= recordDate.Unix() {
  2815. //查询审核是否允许
  2816. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2817. //申请状态不允许的情况 拒绝修改
  2818. if infor.ApplicationStatus != 1 {
  2819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2820. return
  2821. }
  2822. }
  2823. }
  2824. //针对孝昌康桥超滤率计算问题
  2825. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 {
  2826. if assessmentBeforeDislysis.ID == 0 {
  2827. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2828. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  2829. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  2830. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  2831. }
  2832. }
  2833. if assessmentBeforeDislysis.ID > 0 {
  2834. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2835. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  2836. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  2837. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  2838. }
  2839. }
  2840. }
  2841. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2842. //创建步骤表
  2843. finish := models.XtDialysisFinish{
  2844. IsFinish: 1,
  2845. UserOrgId: adminUserInfo.CurrentOrgId,
  2846. Status: 1,
  2847. Ctime: time.Now().Unix(),
  2848. Mtime: 0,
  2849. Module: 3,
  2850. RecordDate: recordDate.Unix(),
  2851. Sourse: 1,
  2852. PatientId: patient,
  2853. }
  2854. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2855. if dialysisFinish.ID == 0 {
  2856. service.CreateDialysisFinish(finish)
  2857. }
  2858. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2859. redis := service.RedisClient()
  2860. //清空key 值
  2861. redis.Set(key, "", time.Second)
  2862. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2863. redis.Set(keyOne, "", time.Second)
  2864. defer redis.Close()
  2865. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2866. redis.Set(keyTwo, "", time.Second)
  2867. if err == nil {
  2868. c.ServeSuccessJSON(map[string]interface{}{
  2869. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2870. })
  2871. } else {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2873. }
  2874. }
  2875. }
  2876. func (c *DialysisApiController) PostTreatmentSummary() {
  2877. patient, _ := c.GetInt64("patient", 0)
  2878. recordDateStr := c.GetString("record_date")
  2879. if patient <= 0 {
  2880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2881. return
  2882. }
  2883. adminUserInfo := c.GetAdminUserInfo()
  2884. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2885. if patientInfo.ID == 0 {
  2886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2887. return
  2888. }
  2889. if len(recordDateStr) == 0 {
  2890. recordDateStr = time.Now().Format("2006-01-02")
  2891. }
  2892. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2893. if parseDateErr != nil {
  2894. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. mission := c.GetString("mission")
  2899. dialysis_summary := c.GetString("dialysis_summary")
  2900. nursingRecord := c.GetString("nursing_record")
  2901. specialRecord := c.GetString("special_record")
  2902. sj_nurse := adminUserInfo.AdminUser.Id
  2903. zl_nurse := adminUserInfo.AdminUser.Id
  2904. hd_nurse := adminUserInfo.AdminUser.Id
  2905. xj_nurse := adminUserInfo.AdminUser.Id
  2906. zl_doctor := adminUserInfo.AdminUser.Id
  2907. treatmentSummary := models.TreatmentSummary{
  2908. UserOrgId: adminUserInfo.CurrentOrgId,
  2909. PatientId: patient,
  2910. AssessmentDate: recordDate.Unix(),
  2911. Mission: mission,
  2912. DialysisSummary: dialysis_summary,
  2913. SjNurse: sj_nurse,
  2914. ZlNurse: zl_nurse,
  2915. HdNurse: hd_nurse,
  2916. XjNurse: xj_nurse,
  2917. ZlDoctor: zl_doctor,
  2918. Status: 1,
  2919. CreatedTime: time.Now().Unix(),
  2920. NursingRecord: nursingRecord,
  2921. SpecialRecord: specialRecord,
  2922. }
  2923. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2924. if tempTreatmentSummary.ID == 0 { //新增
  2925. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2926. // 查询信息规挡的设置天数
  2927. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2928. if infor.ID > 0 && infor.WeekDay > 0 {
  2929. var cha_time int64
  2930. timeNowStr := time.Now().Format("2006-01-02")
  2931. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2932. //今日的日期减去设置的日期
  2933. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2934. if cha_time >= recordDate.Unix() {
  2935. //查询审核是否允许
  2936. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2937. //申请状态不允许的情况 拒绝修改
  2938. if infor.ApplicationStatus != 1 {
  2939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2940. return
  2941. }
  2942. }
  2943. }
  2944. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2945. finish := models.XtDialysisFinish{
  2946. IsFinish: 1,
  2947. UserOrgId: adminUserInfo.CurrentOrgId,
  2948. Status: 1,
  2949. Ctime: time.Now().Unix(),
  2950. Mtime: 0,
  2951. Module: 10,
  2952. RecordDate: recordDate.Unix(),
  2953. Sourse: 1,
  2954. PatientId: patient,
  2955. }
  2956. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  2957. if dialysisFinish.ID == 0 {
  2958. service.CreateDialysisFinish(finish)
  2959. }
  2960. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2961. redis := service.RedisClient()
  2962. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2963. redis.Set(keyOne, "", time.Second)
  2964. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2965. redis.Set(keyThree, "", time.Second)
  2966. defer redis.Close()
  2967. //清空key 值
  2968. redis.Set(key, "", time.Second)
  2969. if err == nil {
  2970. c.ServeSuccessJSON(map[string]interface{}{
  2971. "summary": treatmentSummary,
  2972. })
  2973. } else {
  2974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2975. }
  2976. } else { //修改
  2977. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2978. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2979. // if getPermissionErr != nil {
  2980. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2981. // return
  2982. // } else if headNursePermission == nil {
  2983. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2984. // return
  2985. // }
  2986. //}
  2987. // 查询信息规挡的设置天数
  2988. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2989. if infor.ID > 0 && infor.WeekDay > 0 {
  2990. var cha_time int64
  2991. timeNowStr := time.Now().Format("2006-01-02")
  2992. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2993. //今日的日期减去设置的日期
  2994. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2995. if cha_time >= recordDate.Unix() {
  2996. //查询审核是否允许
  2997. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2998. //申请状态不允许的情况 拒绝修改
  2999. if infor.ApplicationStatus != 1 {
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3001. return
  3002. }
  3003. }
  3004. }
  3005. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3006. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3007. treatmentSummary.UpdatedTime = time.Now().Unix()
  3008. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3009. treatmentSummary.ID = tempTreatmentSummary.ID
  3010. err := service.UpdateSummeRecord(&treatmentSummary)
  3011. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3012. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3013. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3014. //清空key 值
  3015. redis := service.RedisClient()
  3016. redis.Set(key, "", time.Second)
  3017. redis.Set(keyOne, "", time.Second)
  3018. redis.Set(keyThree, "", time.Second)
  3019. defer redis.Close()
  3020. if err == nil {
  3021. c.ServeSuccessJSON(map[string]interface{}{
  3022. "summary": treatmentSummary,
  3023. })
  3024. } else {
  3025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3026. }
  3027. }
  3028. }
  3029. func (c *DialysisApiController) GetDeviceList() {
  3030. adminUserInfo := c.GetAdminUserInfo()
  3031. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3032. c.ServeSuccessJSON(map[string]interface{}{
  3033. "device": device,
  3034. })
  3035. }
  3036. func (c *DialysisApiController) GetAllDeviceZone() {
  3037. adminUserInfo := c.GetAdminUserInfo()
  3038. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3039. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  3040. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  3041. if err == nil {
  3042. c.ServeSuccessJSON(map[string]interface{}{
  3043. "zone": zone,
  3044. "dics": dics,
  3045. "efs": efs,
  3046. })
  3047. }
  3048. }
  3049. func (c *DialysisApiController) GetDialysisWatch() {
  3050. page, _ := c.GetInt64("page", 1)
  3051. limit, _ := c.GetInt64("limit", 10)
  3052. schedulType, _ := c.GetInt64("schedul_type", 0)
  3053. startTime, _ := c.GetInt64("schedul_time", 0)
  3054. partitionType, _ := c.GetInt64("partition_type", 0)
  3055. keywords := c.GetString("keywords")
  3056. start_time, _ := c.GetInt64("start_time")
  3057. end_time, _ := c.GetInt64("end_time")
  3058. adminUserInfo := c.GetAdminUserInfo()
  3059. if len(keywords) > 0 {
  3060. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3061. if err == nil {
  3062. c.ServeSuccessJSON(map[string]interface{}{
  3063. "schedule": dialysisSchedule,
  3064. "total": total,
  3065. })
  3066. } else {
  3067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3068. }
  3069. } else {
  3070. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3071. for _, item := range dialysisSchedule {
  3072. patients, _ := service.GetMonitorPatients(item.PatientId)
  3073. item.MonitorPatients = patients
  3074. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  3075. item.DialysisOrder = orderObj
  3076. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  3077. item.Prescription = prescription
  3078. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  3079. item.AssessmentBeforeDislysis = evaluation
  3080. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  3081. item.AssessmentAfterDislysis = afterdislysis
  3082. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  3083. item.MonitoringRecord = monitorRecord
  3084. }
  3085. if err == nil {
  3086. c.ServeSuccessJSON(map[string]interface{}{
  3087. "schedule": dialysisSchedule,
  3088. "total": total,
  3089. })
  3090. } else {
  3091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3092. }
  3093. }
  3094. }
  3095. //func (c *DialysisApiController) GetDialysisWatch() {
  3096. // page, _ := c.GetInt64("page", 1)
  3097. // limit, _ := c.GetInt64("limit", 10)
  3098. // schedulType, _ := c.GetInt64("schedul_type", 0)
  3099. // startTime, _ := c.GetInt64("schedul_time", 0)
  3100. // partitionType, _ := c.GetInt64("partition_type", 0)
  3101. // keywords := c.GetString("keywords")
  3102. //
  3103. // adminUserInfo := c.GetAdminUserInfo()
  3104. // if len(keywords) > 0 {
  3105. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3106. //
  3107. // //获取所有床位号
  3108. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  3109. //
  3110. // //获取透析处方
  3111. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  3112. // //获取透前评估
  3113. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3114. // //获取上机
  3115. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3116. // //获取透后
  3117. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3118. //
  3119. // //获取透后监测
  3120. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3121. //
  3122. // //获取所有的患者
  3123. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3124. //
  3125. // //获取所有透析模式
  3126. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3127. //
  3128. // for key, scheduals := range dialysisSchedule {
  3129. // // 获取患者信息
  3130. // for _, patient := range patients {
  3131. // if scheduals.PatientId == patient.ID {
  3132. // dialysisSchedule[key].MonitorPatients = patient
  3133. // break
  3134. // }
  3135. // }
  3136. // // 床位信息
  3137. // for _, device := range numberList {
  3138. // if scheduals.BedId == device.ID {
  3139. // dialysisSchedule[key].DeviceNumber = device
  3140. // break
  3141. // }
  3142. // }
  3143. //
  3144. // // 医嘱信息
  3145. // for _, prescription := range prescriptions {
  3146. // if scheduals.PatientId == prescription.PatientId {
  3147. // dialysisSchedule[key].Prescription = prescription
  3148. // break
  3149. // }
  3150. // }
  3151. //
  3152. // // 透前评估
  3153. // for _, assessmentBefore := range assessmentBefores {
  3154. // if scheduals.PatientId == assessmentBefore.PatientId {
  3155. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3156. // break
  3157. // }
  3158. // }
  3159. //
  3160. // // 透析上下机
  3161. // for _, dialysisOrder := range dialysisOrders {
  3162. // if scheduals.PatientId == dialysisOrder.PatientId {
  3163. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3164. // break
  3165. // }
  3166. // }
  3167. //
  3168. // records := make([]*models.MonitoringRecord, 0)
  3169. // // 透析监测
  3170. // for _, it := range monitorlist {
  3171. // records := append(records, it)
  3172. // if scheduals.PatientId == it.PatientId {
  3173. // dialysisSchedule[key].MonitoringRecord = records
  3174. // }
  3175. // }
  3176. //
  3177. // // 透后评估
  3178. // for _, afterDislysis := range AssessmentAfterDislysis {
  3179. // if scheduals.PatientId == afterDislysis.PatientId {
  3180. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3181. // break
  3182. // }
  3183. // }
  3184. //
  3185. // //透析模式
  3186. // for _, treatment := range treatments {
  3187. // if scheduals.ModeId == treatment.ID {
  3188. // dialysisSchedule[key].TreatmentMode = treatment
  3189. // break
  3190. // }
  3191. // }
  3192. // }
  3193. // //获取所有床位号
  3194. // if err == nil {
  3195. // c.ServeSuccessJSON(map[string]interface{}{
  3196. // "schedule": dialysisSchedule,
  3197. // "total": total,
  3198. // })
  3199. // } else {
  3200. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3201. // }
  3202. //
  3203. // } else {
  3204. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3205. // if err == nil {
  3206. // c.ServeSuccessJSON(map[string]interface{}{
  3207. // "schedule": dialysisSchedule,
  3208. // "total": total,
  3209. // })
  3210. // } else {
  3211. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3212. // }
  3213. // }
  3214. //}
  3215. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3216. patientId, _ := c.GetInt64("id", 0)
  3217. record_date, _ := c.GetInt64("record_date", 0)
  3218. adminUserInfo := c.GetAdminUserInfo()
  3219. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3220. var dialysisStatus int64
  3221. if dialysisOrder == nil { //没有透析记录
  3222. dialysisStatus = 0 //未透析
  3223. } else {
  3224. dialysisStatus = dialysisOrder.Stage
  3225. }
  3226. //用户基本信息
  3227. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3228. //接诊评估
  3229. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3230. //透前评估
  3231. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3232. //临时医嘱
  3233. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3234. //双人核对
  3235. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3236. //透析监测
  3237. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3238. //透后评估
  3239. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3240. //透析小结
  3241. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3242. //透析处方
  3243. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3244. if dialysisPrescription.ID == 0 {
  3245. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3246. c.ServeSuccessJSON(map[string]interface{}{
  3247. "patientInfo": schedualPatientInfo,
  3248. "dialysisPrescription": solution,
  3249. "receiverTreatmentAccess": receiverTreatmentAccess,
  3250. "predialysisEvaluation": PredialysisEvaluation,
  3251. "doctorAdvice": DoctorAdvice,
  3252. "doubleCheck": DoubleCheck,
  3253. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3254. "treatmentSummary": TreatmentSummary,
  3255. "monitorRecord": Record,
  3256. "dialysisStatus": dialysisStatus,
  3257. "dialysisOrder": dialysisOrder,
  3258. "isSolution": 1,
  3259. })
  3260. } else {
  3261. c.ServeSuccessJSON(map[string]interface{}{
  3262. "patientInfo": schedualPatientInfo,
  3263. "dialysisPrescription": dialysisPrescription,
  3264. "receiverTreatmentAccess": receiverTreatmentAccess,
  3265. "predialysisEvaluation": PredialysisEvaluation,
  3266. "doctorAdvice": DoctorAdvice,
  3267. "doubleCheck": DoubleCheck,
  3268. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3269. "treatmentSummary": TreatmentSummary,
  3270. "monitorRecord": Record,
  3271. "dialysisStatus": dialysisStatus,
  3272. "dialysisOrder": dialysisOrder,
  3273. "isSolution": 2,
  3274. })
  3275. }
  3276. }
  3277. func (c *DialysisApiController) CreateDoctorAdvice() {
  3278. patient, _ := c.GetInt64("id", 0)
  3279. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3280. record_date, _ := c.GetInt64("record_date", 0)
  3281. if patient <= 0 {
  3282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3283. return
  3284. }
  3285. adminUserInfo := c.GetAdminUserInfo()
  3286. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3287. if patientInfo.ID == 0 {
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3289. return
  3290. }
  3291. var advice models.DoctorAdvice
  3292. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3293. if code > 0 {
  3294. c.ServeFailJSONWithSGJErrorCode(code)
  3295. return
  3296. }
  3297. if advice.ParentId > 0 {
  3298. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3299. if old.ID == 0 || old.PatientId != patient {
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3301. return
  3302. }
  3303. if old.StopState == 1 || old.ExecutionState == 1 {
  3304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3305. return
  3306. }
  3307. if old.ParentId > 0 {
  3308. advice.ParentId = old.ParentId
  3309. }
  3310. advice.StartTime = old.StartTime
  3311. advice.AdviceDoctor = old.AdviceDoctor
  3312. advice.DeliveryWay = old.DeliveryWay
  3313. advice.ExecutionFrequency = old.ExecutionFrequency
  3314. }
  3315. advice.RecordDate = record_date
  3316. advice.DialysisOrderId = dialysis_id
  3317. advice.Status = 1
  3318. advice.CreatedTime = time.Now().Unix()
  3319. advice.UpdatedTime = time.Now().Unix()
  3320. advice.StopState = 2
  3321. advice.ExecutionState = 2
  3322. advice.AdviceType = 2
  3323. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3324. advice.PatientId = patient
  3325. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3326. err := service.CreateDoctorAdvice(&advice)
  3327. if err != nil {
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3329. return
  3330. }
  3331. for _, subAdvice := range subAdivice {
  3332. subAdvice.ParentId = advice.ID
  3333. subAdvice.PatientId = patient
  3334. subAdvice.RecordDate = record_date
  3335. subAdvice.CreatedTime = time.Now().Unix()
  3336. subAdvice.UpdatedTime = time.Now().Unix()
  3337. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3338. }
  3339. service.CreateSubDoctorAdvice(subAdivice)
  3340. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3341. c.ServeSuccessJSON(map[string]interface{}{
  3342. "msg": "ok",
  3343. "advice": advice,
  3344. "subAdvice": subAdivices,
  3345. })
  3346. return
  3347. }
  3348. func (c *DialysisApiController) EditDoctorAdvice() {
  3349. patient, _ := c.GetInt64("patient", 0)
  3350. id, _ := c.GetInt64("id", 0)
  3351. parent_id, _ := c.GetInt64("parent_id", 0)
  3352. execution_time := c.GetString("execution_time")
  3353. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3354. // checker, _ := c.GetInt64("checker", 0)
  3355. if id <= 0 || patient <= 0 {
  3356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3357. return
  3358. }
  3359. adminUserInfo := c.GetAdminUserInfo()
  3360. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3361. if advice.ID == 0 || advice.PatientId != patient {
  3362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3363. return
  3364. }
  3365. if len(execution_time) <= 0 {
  3366. utils.ErrorLog("execution_time")
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3368. return
  3369. }
  3370. execution_staff := adminUserInfo.AdminUser.Id
  3371. checker := adminUserInfo.AdminUser.Id
  3372. timeLayout2 := "2006-01-02 15:04"
  3373. loc, _ := time.LoadLocation("Local")
  3374. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3375. if errs != nil {
  3376. utils.ErrorLog(errs.Error())
  3377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3378. return
  3379. }
  3380. advices := models.DoctorAdvice{
  3381. ExecutionStaff: execution_staff,
  3382. ExecutionTime: theTime.Unix(),
  3383. Checker: checker,
  3384. UpdatedTime: time.Now().Unix(),
  3385. }
  3386. var err error
  3387. if parent_id > 0 {
  3388. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3389. } else {
  3390. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3391. }
  3392. if err != nil {
  3393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3394. return
  3395. }
  3396. c.ServeSuccessJSON(map[string]interface{}{
  3397. "msg": "ok",
  3398. "advice": advice,
  3399. })
  3400. return
  3401. }
  3402. func (c *DialysisApiController) GetDoctorAdvice() {
  3403. patient, _ := c.GetInt64("patient_id", 0)
  3404. parent_id, _ := c.GetInt64("parent_id", 0)
  3405. adviceId, _ := c.GetInt64("id", 0)
  3406. if patient <= 0 {
  3407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3408. return
  3409. }
  3410. dminUserInfo := c.GetAdminUserInfo()
  3411. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3412. if patientInfo.ID == 0 {
  3413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3414. return
  3415. }
  3416. var subAdvice []*models.DoctorAdvice
  3417. var advice models.DoctorAdvice
  3418. if parent_id > 0 {
  3419. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3420. if advice.ID == 0 || advice.PatientId != patient {
  3421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3422. return
  3423. }
  3424. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3425. } else {
  3426. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3427. if advice.ID == 0 || advice.PatientId != patient {
  3428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3429. return
  3430. }
  3431. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3432. }
  3433. c.ServeSuccessJSON(map[string]interface{}{
  3434. "msg": "ok",
  3435. "advice": advice,
  3436. "subAdvice": subAdvice,
  3437. })
  3438. }
  3439. func (this *DialysisApiController) DelMonitor() {
  3440. recordID, _ := this.GetInt64("record_id")
  3441. patientID, _ := this.GetInt64("patient_id")
  3442. if recordID <= 0 || patientID <= 0 {
  3443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3444. return
  3445. }
  3446. adminInfo := this.GetAdminUserInfo()
  3447. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3448. if getPatientErr != nil {
  3449. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3451. return
  3452. } else if patient == nil {
  3453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3454. return
  3455. }
  3456. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3457. if getMonitorErr != nil {
  3458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3459. return
  3460. }
  3461. //if monitor != nil {
  3462. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3463. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3464. // if getPermissionErr != nil {
  3465. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3466. // return
  3467. // } else if headNursePermission == nil {
  3468. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3469. // return
  3470. // }
  3471. // }
  3472. //}
  3473. // 查询信息规挡的设置天数
  3474. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3475. if infor.ID > 0 && infor.WeekDay > 0 {
  3476. var cha_time int64
  3477. timeNowStr := time.Now().Format("2006-01-02")
  3478. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3479. //今日的日期减去设置的日期
  3480. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3481. if cha_time >= monitor.MonitoringDate {
  3482. //查询审核是否允许
  3483. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3484. //申请状态不允许的情况 拒绝修改
  3485. if infor.ApplicationStatus != 1 {
  3486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3487. return
  3488. }
  3489. }
  3490. }
  3491. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3492. //记录日志
  3493. byterequest, _ := json.Marshal(monitor)
  3494. monitorRecordLog := models.XtMonitorRecordLog{
  3495. RecordDate: monitor.MonitoringDate,
  3496. PatientId: monitor.PatientId,
  3497. Module: 3,
  3498. AdminUserId: adminInfo.AdminUser.Id,
  3499. Ctime: time.Now().Unix(),
  3500. Mtime: 0,
  3501. Status: 1,
  3502. UserOrgId: monitor.UserOrgId,
  3503. ErrLog: string(byterequest),
  3504. Source: "电脑端删除监测",
  3505. }
  3506. service.CreateMonitorRecordLog(monitorRecordLog)
  3507. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3508. redis := service.RedisClient()
  3509. //清空key 值
  3510. redis.Set(key, "", time.Second)
  3511. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3512. redis.Set(keyOne, "", time.Second)
  3513. defer redis.Close()
  3514. if err != nil {
  3515. this.ErrorLog("删除透析监测记录失败:%v", err)
  3516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3517. return
  3518. }
  3519. this.ServeSuccessJSON(map[string]interface{}{
  3520. "record_id": monitor.ID,
  3521. })
  3522. }
  3523. func (c *DialysisApiController) CreateMonitor() {
  3524. patient, _ := c.GetInt64("id", 0)
  3525. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3526. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3527. operate_time, _ := c.GetInt64("operate_time", 0)
  3528. // monitoring_time := c.GetString("monitoring_time")
  3529. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3530. breathing_rated := c.GetString("breathing_rated")
  3531. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3532. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3533. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3534. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3535. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3536. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3537. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3538. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3539. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3540. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3541. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3542. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3543. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3544. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3545. temperature, _ := c.GetFloat("temperature", 0)
  3546. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3547. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3548. conductivity, _ := c.GetFloat("conductivity", 0)
  3549. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3550. heparin, _ := c.GetFloat("heparin", 0)
  3551. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3552. ktv, _ := c.GetFloat("ktv", 0)
  3553. symptom := c.GetString("symptom")
  3554. dispose := c.GetString("dispose")
  3555. result := c.GetString("results")
  3556. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3557. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3558. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3559. replacement_speed, _ := c.GetFloat("replacement_speed")
  3560. dicarbonate, _ := c.GetFloat("dicarbonate")
  3561. monitoring_date = monitoring_date / 1000
  3562. // operate_time = operate_time / 1000
  3563. if patient <= 0 {
  3564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3565. return
  3566. }
  3567. adminUserInfo := c.GetAdminUserInfo()
  3568. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3569. if patientInfo.ID == 0 {
  3570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3571. return
  3572. }
  3573. monitorRecord := models.MonitoringRecord{
  3574. PatientId: patient,
  3575. MonitoringDate: monitoring_date,
  3576. DialysisOrderId: dialysis_order_id,
  3577. OperateTime: operate_time,
  3578. // MonitoringTime: monitoring_time,
  3579. PulseFrequency: pulse_frequency,
  3580. BreathingRate: breathing_rated,
  3581. SystolicBloodPressure: systolic_blood_pressure,
  3582. DiastolicBloodPressure: diastolic_blood_pressure,
  3583. BloodPressureType: blood_pressure_type,
  3584. BloodFlowVolume: blood_flow_volume,
  3585. VenousPressure: venous_pressure,
  3586. VenousPressureType: venous_pressure_type,
  3587. TransmembranePressure: transmembrane_pressure,
  3588. TransmembranePressureType: transmembrane_pressure_type,
  3589. UltrafiltrationRate: ultrafiltration_rate,
  3590. UltrafiltrationVolume: ultrafiltration_volume,
  3591. SodiumConcentration: sodium_concentration,
  3592. ArterialPressure: arterial_pressure,
  3593. ArterialPressureType: arterial_pressure_type,
  3594. DialysateTemperature: dialysate_temperature,
  3595. Temperature: temperature,
  3596. ReplacementRate: replacement_rate,
  3597. DisplacementQuantity: displacement_quantity,
  3598. Ktv: ktv,
  3599. Symptom: symptom,
  3600. Dispose: dispose,
  3601. Result: result,
  3602. MonitoringNurse: monitoring_nurse,
  3603. Status: 1,
  3604. CreatedTime: time.Now().Unix(),
  3605. UpdatedTime: time.Now().Unix(),
  3606. UserOrgId: adminUserInfo.CurrentOrgId,
  3607. Conductivity: conductivity,
  3608. DisplacementFlowQuantity: displacement_flow_quantity,
  3609. Heparin: heparin,
  3610. DialysateFlow: dialysate_flow,
  3611. MonitorAnticoagulant: monitor_anticoagulant,
  3612. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3613. ReplacementSpeed: replacement_speed,
  3614. Dicarbonate: dicarbonate,
  3615. }
  3616. // 查询信息规挡的设置天数
  3617. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3618. if infor.ID > 0 && infor.WeekDay > 0 {
  3619. var cha_time int64
  3620. timeNowStr := time.Now().Format("2006-01-02")
  3621. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3622. //今日的日期减去设置的日期
  3623. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3624. if cha_time >= monitoring_date {
  3625. //查询审核是否允许
  3626. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  3627. //申请状态不允许的情况 拒绝修改
  3628. if infor.ApplicationStatus != 1 {
  3629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3630. return
  3631. }
  3632. }
  3633. }
  3634. err := service.CreateMonitor(&monitorRecord)
  3635. finish := models.XtDialysisFinish{
  3636. IsFinish: 1,
  3637. UserOrgId: adminUserInfo.CurrentOrgId,
  3638. Status: 1,
  3639. Ctime: time.Now().Unix(),
  3640. Mtime: 0,
  3641. Module: 7,
  3642. RecordDate: monitoring_date,
  3643. Sourse: 1,
  3644. PatientId: patient,
  3645. }
  3646. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3647. if dialysisFinish.ID == 0 {
  3648. service.CreateDialysisFinish(finish)
  3649. }
  3650. redis := service.RedisClient()
  3651. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3652. redis.Set(key, "", time.Second)
  3653. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3654. redis.Set(keyOne, "", time.Second)
  3655. redis.Close()
  3656. if err != nil {
  3657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3658. return
  3659. }
  3660. c.ServeSuccessJSON(map[string]interface{}{
  3661. "msg": "ok",
  3662. "monitor": monitorRecord,
  3663. })
  3664. return
  3665. }
  3666. // 已弃用
  3667. // func (c *DialysisApiController) CreateRecordData() {
  3668. // patient, _ := c.GetInt64("id", 0)
  3669. // status, _ := c.GetInt64("status", 0)
  3670. // now := time.Now()
  3671. // year, month, day := now.Date()
  3672. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3673. // todayTimeStamp := today_time.Unix()
  3674. // if patient <= 0 {
  3675. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3676. // return
  3677. // }
  3678. // adminUserInfo := c.GetAdminUserInfo()
  3679. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3680. // if patientInfo.ID == 0 {
  3681. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3682. // return
  3683. // }
  3684. // record := &models.DialysisOrder{
  3685. // DialysisDate: todayTimeStamp,
  3686. // UserOrgId: adminUserInfo.CurrentOrgId,
  3687. // PatientId: patient,
  3688. // Stage: status,
  3689. // Status: 1,
  3690. // CreatedTime: time.Now().Unix(),
  3691. // UpdatedTime: time.Now().Unix(),
  3692. // }
  3693. // if status == 1 {
  3694. // //创建透析记录
  3695. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3696. // if err == nil {
  3697. // c.ServeSuccessJSON(map[string]interface{}{
  3698. // "dialysisOrder": record,
  3699. // })
  3700. // } else {
  3701. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3702. // }
  3703. // } else {
  3704. // record_id, _ := c.GetInt64("record_id", 0)
  3705. // //修改透析记录状态
  3706. // errs := service.ModifyDialysisRecord(record_id)
  3707. // //结束时候透析次数加1
  3708. // service.UpdateSolutionByPatientId(patient)
  3709. // if errs == nil {
  3710. // c.ServeSuccessJSON(map[string]interface{}{
  3711. // "dialysisOrder": record,
  3712. // })
  3713. // } else {
  3714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3715. // }
  3716. // }
  3717. // }
  3718. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3719. dataBody := make(map[string]interface{}, 0)
  3720. err := json.Unmarshal(data, &dataBody)
  3721. if err != nil {
  3722. utils.ErrorLog(err.Error())
  3723. code = enums.ErrorCodeParamWrong
  3724. return
  3725. }
  3726. timeLayout := "2006-01-02 "
  3727. timeLayout2 := "2006-01-02 15:04"
  3728. loc, _ := time.LoadLocation("Local")
  3729. if action == "create" {
  3730. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3731. utils.ErrorLog("advice_type")
  3732. code = enums.ErrorCodeParamWrong
  3733. return
  3734. }
  3735. adviceType := int64(dataBody["advice_type"].(float64))
  3736. if adviceType != 1 && adviceType != 2 {
  3737. utils.ErrorLog("advice_type != 1&&2")
  3738. code = enums.ErrorCodeParamWrong
  3739. return
  3740. }
  3741. advice.AdviceType = adviceType
  3742. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3743. utils.ErrorLog("advice_date")
  3744. code = enums.ErrorCodeParamWrong
  3745. return
  3746. }
  3747. adviceDate, _ := dataBody["advice_date"].(string)
  3748. if len(adviceDate) == 0 {
  3749. utils.ErrorLog("len(adviceDate) == 0")
  3750. code = enums.ErrorCodeParamWrong
  3751. return
  3752. }
  3753. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3754. if err != nil {
  3755. utils.ErrorLog(err.Error())
  3756. code = enums.ErrorCodeParamWrong
  3757. return
  3758. }
  3759. advice.AdviceDate = theTime.Unix()
  3760. }
  3761. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3762. utils.ErrorLog("start_time")
  3763. code = enums.ErrorCodeParamWrong
  3764. return
  3765. }
  3766. startDate, _ := dataBody["start_time"].(string)
  3767. if len(startDate) == 0 {
  3768. utils.ErrorLog("len(startDate) == 0")
  3769. code = enums.ErrorCodeParamWrong
  3770. return
  3771. }
  3772. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3773. if err != nil {
  3774. utils.ErrorLog(err.Error())
  3775. code = enums.ErrorCodeParamWrong
  3776. return
  3777. }
  3778. advice.StartTime = theTime.Unix()
  3779. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3780. utils.ErrorLog("advice_name")
  3781. code = enums.ErrorCodeParamWrong
  3782. return
  3783. }
  3784. adviceName, _ := dataBody["advice_name"].(string)
  3785. if len(adviceName) == 0 {
  3786. utils.ErrorLog("len(advice_name) == 0")
  3787. code = enums.ErrorCodeParamWrong
  3788. return
  3789. }
  3790. advice.AdviceName = adviceName
  3791. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3792. utils.ErrorLog("delivery_way")
  3793. code = enums.ErrorCodeParamWrong
  3794. return
  3795. }
  3796. deliveryWay, _ := dataBody["delivery_way"].(string)
  3797. if len(deliveryWay) == 0 {
  3798. utils.ErrorLog("len(deliveryWay) == 0")
  3799. code = enums.ErrorCodeParamWrong
  3800. return
  3801. }
  3802. advice.DeliveryWay = deliveryWay
  3803. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3804. utils.ErrorLog("execution_frequency")
  3805. code = enums.ErrorCodeParamWrong
  3806. return
  3807. }
  3808. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3809. if len(execution_frequency) == 0 {
  3810. utils.ErrorLog("len(execution_frequency) == 0")
  3811. code = enums.ErrorCodeParamWrong
  3812. return
  3813. }
  3814. advice.ExecutionFrequency = execution_frequency
  3815. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3816. adviceDsc, _ := dataBody["advice_desc"].(string)
  3817. advice.AdviceDesc = adviceDsc
  3818. }
  3819. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3820. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3821. advice.DrugSpecUnit = drugSpecUnit
  3822. }
  3823. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3824. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3825. advice.SingleDose = singleDose
  3826. }
  3827. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3828. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3829. advice.SingleDoseUnit = singleDoseUnit
  3830. }
  3831. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3832. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3833. advice.PrescribingNumber = prescribingNumber
  3834. }
  3835. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3836. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3837. advice.PrescribingNumberUnit = prescribingNumberUnit
  3838. }
  3839. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3840. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3841. if len(thisContagions) > 0 {
  3842. for _, item := range thisContagions {
  3843. items := item.(map[string]interface{})
  3844. advice_name, _ := items["advice_name"].(string)
  3845. advice_desc, _ := items["advice_desc"].(string)
  3846. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3847. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3848. single_dose_unit, _ := items["single_dose_unit"].(string)
  3849. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3850. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3851. advice := &models.DoctorAdvice{
  3852. AdviceName: advice_name,
  3853. AdviceDesc: advice_desc,
  3854. SingleDose: single_dose,
  3855. SingleDoseUnit: single_dose_unit,
  3856. DrugSpecUnit: drug_spec_unit,
  3857. PrescribingNumber: prescribing_number,
  3858. PrescribingNumberUnit: prescribing_number_unit,
  3859. }
  3860. subAdvice = append(subAdvice, advice)
  3861. }
  3862. }
  3863. }
  3864. return
  3865. }
  3866. func (c *DialysisApiController) GetDialysisOrder() {
  3867. //xtno := c.GetString("xtno")
  3868. xtdate := c.GetString("xtdate")
  3869. patient_id, _ := c.GetInt64("patient_id")
  3870. timeLayout := "2006-01-02"
  3871. loc, _ := time.LoadLocation("Local")
  3872. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3873. if err != nil {
  3874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3875. return
  3876. }
  3877. xttime := theTime.Unix()
  3878. operatorIDs := make([]int64, 0)
  3879. adminUserInfo := c.GetAdminUserInfo()
  3880. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3881. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3882. //透析单
  3883. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3884. if dialysisOrder != nil {
  3885. if dialysisOrder.FinishNurse > 0 {
  3886. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3887. }
  3888. if dialysisOrder.StartNurse > 0 {
  3889. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3890. }
  3891. }
  3892. //透前评估
  3893. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3894. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3895. //透后评估
  3896. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3897. if AssessmentAfterDislysis.Modifier > 0 {
  3898. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3899. }
  3900. //上次透前评估
  3901. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3902. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3903. //透析处方
  3904. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3905. if dialysisPrescription.PrescriptionDoctor > 0 {
  3906. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3907. }
  3908. //获取病人的透析模式
  3909. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3910. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3911. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3912. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3913. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3914. //获取透析处方
  3915. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3916. //获取临时医嘱
  3917. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3918. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3919. //获取医嘱内容
  3920. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3921. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3922. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3923. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3924. //获取上次的透后体重
  3925. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3926. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3927. //获取透析次数
  3928. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3929. if len(DoctorAdvice) > 0 {
  3930. for _, item := range DoctorAdvice {
  3931. if item.AdviceDoctor > 0 {
  3932. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3933. }
  3934. if item.ExecutionStaff > 0 {
  3935. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3936. }
  3937. if item.Checker > 0 {
  3938. operatorIDs = append(operatorIDs, item.Checker)
  3939. }
  3940. }
  3941. }
  3942. //透析监测
  3943. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3944. //透析检测
  3945. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3946. //透析小结
  3947. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3948. //接诊评估
  3949. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3950. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3951. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3952. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3953. patientInfo.TotalDialysis = dialysis_count
  3954. }
  3955. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3956. if xttime <= 1703952000 {
  3957. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3958. patientInfo.TotalDialysis = dialysis_count
  3959. }
  3960. if xttime >= 1704038400 {
  3961. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3962. patientInfo.TotalDialysis = dialysis_count
  3963. }
  3964. }
  3965. //相关操作对应的操作人
  3966. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3967. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3968. //fmt.Println("operators------------------------------------", operators)
  3969. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3970. //获取当前日期月份的第一天
  3971. firstmonth := service.GetFirstDateOfMonth(theTime)
  3972. firstMonthDate := firstmonth.Unix()
  3973. //获取当前月份的病人透析次数
  3974. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3975. var hisAdvice []*models.HisDoctorAdviceInfo
  3976. var his_advices_one []*models.HisDoctorAdviceInfo
  3977. //获取his数据
  3978. hisAdvice, _ = service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3979. //针对茂名舒和
  3980. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  3981. if len(hisAdvice) > 0 {
  3982. for _, item := range hisAdvice {
  3983. drug, _ := service.GetDrugIsShow(item.DrugId, adminUserInfo.CurrentOrgId)
  3984. if drug.IsShow == 1 {
  3985. his_advices_one = append(his_advices_one, item)
  3986. }
  3987. }
  3988. }
  3989. } else {
  3990. if len(hisAdvice) > 0 {
  3991. for _, item := range hisAdvice {
  3992. his_advices_one = append(his_advices_one, item)
  3993. }
  3994. }
  3995. }
  3996. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3997. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3998. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3999. var projects []*models.HisPrescriptionProject
  4000. projects, _ = service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4001. var projectsOne []*models.HisPrescriptionProject
  4002. //针对茂名舒和
  4003. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4004. if len(projects) > 0 {
  4005. for _, item := range projects {
  4006. if item.Type == 2 {
  4007. if item.HisProject.IsShow == 1 {
  4008. projectsOne = append(projectsOne, item)
  4009. }
  4010. }
  4011. if item.Type == 3 {
  4012. if item.GoodInfo.IsShow == 1 {
  4013. projectsOne = append(projectsOne, item)
  4014. }
  4015. }
  4016. }
  4017. }
  4018. } else {
  4019. for _, item := range projects {
  4020. projectsOne = append(projectsOne, item)
  4021. }
  4022. }
  4023. //获取诊断
  4024. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4025. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  4026. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4027. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  4028. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4029. // for _, item := range projects {
  4030. // var advice *models.HisDoctorAdviceInfo
  4031. // advice.ID = item.ID
  4032. // advice.Checker = item.Checker
  4033. // advice.CheckTime = item.CheckTime
  4034. // advice.CheckState = item.CheckState
  4035. // advice.ExecutionState = item.ExecutionState
  4036. // advice.ExecutionStaff = item.ExecutionStaff
  4037. // advice.PrescribingNumber = float64(item.Count)
  4038. // advice.PrescribingNumberUnit = item.Unit
  4039. // advice.AdviceDoctor = item.Doctor
  4040. // if item.Type == 3 {
  4041. // advice.AdviceName = item.GoodInfo.GoodName
  4042. // } else if item.Type == 2 {
  4043. // advice.AdviceName = item.HisProject.ProjectName
  4044. // }
  4045. // advice.StartTime = item.StartTime
  4046. // hisAdvice = append(hisAdvice, advice)
  4047. // }
  4048. //}
  4049. if config.IsOpen == 1 {
  4050. c.ServeSuccessJSON(map[string]interface{}{
  4051. "xtdate": xtdate,
  4052. "users": adminUser,
  4053. "patientInfo": patientInfo,
  4054. "PredialysisEvaluation": PredialysisEvaluation,
  4055. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4056. "dialysisPrescription": dialysisPrescription,
  4057. "advices": his_advices_one,
  4058. "monitors": Record,
  4059. "summary": TreatmentSummary,
  4060. "receiverTreatmentAccess": receiverTreatmentAccess,
  4061. "dialysisOrder": dialysisOrder,
  4062. "operators": operators,
  4063. "org_template_info": templateInfo,
  4064. "check": check,
  4065. "schedule": schedule,
  4066. "dialysisway": dialysisway,
  4067. "order": order,
  4068. "doctorAdvice": doctorAdvice,
  4069. "doctor": doctor,
  4070. "nurse": nurse,
  4071. "doctorAdevieInfo": doctorAdevieInfo,
  4072. "total": total,
  4073. "startNuse": startNuse,
  4074. "DoctorName": DoctorName,
  4075. "assessmentAfterDislysis": assessmentAfterDislysis,
  4076. "predialysName": predialysName,
  4077. "FinishNuse": FinishNuse,
  4078. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4079. "dialysiscount": dialysiscount,
  4080. "last_order": lastOrder,
  4081. "project_config": project_config,
  4082. "projects": projectsOne,
  4083. "prescriptionInfo": prescriptionInfo,
  4084. "patientDiagnose": patientDiagnose,
  4085. "lastSchedule": lastSchedule,
  4086. "numberList": numberList,
  4087. })
  4088. }
  4089. if config.IsOpen == 0 || config.IsOpen == 2 {
  4090. c.ServeSuccessJSON(map[string]interface{}{
  4091. "xtdate": xtdate,
  4092. "users": adminUser,
  4093. "patientInfo": patientInfo,
  4094. "PredialysisEvaluation": PredialysisEvaluation,
  4095. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4096. "dialysisPrescription": dialysisPrescription,
  4097. "advices": DoctorAdvice,
  4098. "monitors": Record,
  4099. "summary": TreatmentSummary,
  4100. "receiverTreatmentAccess": receiverTreatmentAccess,
  4101. "dialysisOrder": dialysisOrder,
  4102. "operators": operators,
  4103. "org_template_info": templateInfo,
  4104. "check": check,
  4105. "schedule": schedule,
  4106. "dialysisway": dialysisway,
  4107. "order": order,
  4108. "doctorAdvice": doctorAdvice,
  4109. "doctor": doctor,
  4110. "nurse": nurse,
  4111. "doctorAdevieInfo": doctorAdevieInfo,
  4112. "total": total,
  4113. "startNuse": startNuse,
  4114. "DoctorName": DoctorName,
  4115. "assessmentAfterDislysis": assessmentAfterDislysis,
  4116. "predialysName": predialysName,
  4117. "FinishNuse": FinishNuse,
  4118. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4119. "dialysiscount": dialysiscount,
  4120. "last_order": lastOrder,
  4121. "project_config": project_config,
  4122. "projects": projects,
  4123. "prescriptionInfo": prescriptionInfo,
  4124. "patientDiagnose": patientDiagnose,
  4125. "lastSchedule": lastSchedule,
  4126. "numberList": numberList,
  4127. })
  4128. }
  4129. }
  4130. func (c *DialysisApiController) GetLongAdvice() {
  4131. patient_id, _ := c.GetInt64("patient_id")
  4132. adminUserInfo := c.GetAdminUserInfo()
  4133. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4134. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4135. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4136. c.ServeSuccessJSON(map[string]interface{}{
  4137. "status": "1",
  4138. })
  4139. return
  4140. } else { //开启推送提醒
  4141. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4142. var advice_three []*models.DoctorAdvice
  4143. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4144. recordDateStr := time.Now().Format("2006-01-02")
  4145. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4146. nowtime := recordDate.Unix()
  4147. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4148. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4149. for _, advice := range advices {
  4150. if advice.FrequencyType == 3 {
  4151. t := time.Now()
  4152. week := int(t.Weekday())
  4153. switch week {
  4154. case 1:
  4155. if strings.Index(advice.WeekDay, "周一") == -1 {
  4156. advice_three = append(advice_three, advice)
  4157. }
  4158. break
  4159. case 2:
  4160. if strings.Index(advice.WeekDay, "周二") == -1 {
  4161. advice_three = append(advice_three, advice)
  4162. }
  4163. break
  4164. case 3:
  4165. if strings.Index(advice.WeekDay, "周三") == -1 {
  4166. advice_three = append(advice_three, advice)
  4167. }
  4168. break
  4169. case 4:
  4170. if strings.Index(advice.WeekDay, "周四") == -1 {
  4171. advice_three = append(advice_three, advice)
  4172. }
  4173. break
  4174. case 5:
  4175. if strings.Index(advice.WeekDay, "周五") == -1 {
  4176. advice_three = append(advice_three, advice)
  4177. }
  4178. break
  4179. case 6:
  4180. if strings.Index(advice.WeekDay, "周六") == -1 {
  4181. advice_three = append(advice_three, advice)
  4182. }
  4183. break
  4184. case 0:
  4185. if strings.Index(advice.WeekDay, "周日") == -1 {
  4186. advice_three = append(advice_three, advice)
  4187. }
  4188. break
  4189. }
  4190. }
  4191. }
  4192. for _, advice := range advices_two {
  4193. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4194. now := p.Unix()
  4195. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4196. dayStr2 := "-" + dayStr
  4197. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4198. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4199. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4200. for _, ad := range advices {
  4201. advice_three = append(advice_three, ad)
  4202. }
  4203. }
  4204. if err == nil {
  4205. c.ServeSuccessJSON(map[string]interface{}{
  4206. "status": "2",
  4207. "advices": advices,
  4208. "advices_two": RemoveRepeatedElement(advice_three),
  4209. "is_open_remind": config.IsOpenRemind,
  4210. })
  4211. }
  4212. }
  4213. }
  4214. func (c *DialysisApiController) GetLongAdviceOne() {
  4215. patient_id, _ := c.GetInt64("patient_id")
  4216. schedule_date := c.GetString("schedule_date")
  4217. adminUserInfo := c.GetAdminUserInfo()
  4218. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4219. timeLayout := "2006-01-02"
  4220. loc, _ := time.LoadLocation("Local")
  4221. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4222. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4223. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4224. c.ServeSuccessJSON(map[string]interface{}{
  4225. "status": "1",
  4226. })
  4227. return
  4228. } else { //开启推送提醒
  4229. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4230. var advice_three []*models.DoctorAdvice
  4231. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4232. //recordDateStr := time.Now().Format("2006-01-02")
  4233. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4234. //
  4235. //nowtime := recordDate.Unix()
  4236. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4237. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4238. for _, advice := range advices {
  4239. if advice.FrequencyType == 3 {
  4240. t := time.Now()
  4241. week := int(t.Weekday())
  4242. switch week {
  4243. case 1:
  4244. if strings.Index(advice.WeekDay, "周一") == -1 {
  4245. advice_three = append(advice_three, advice)
  4246. }
  4247. break
  4248. case 2:
  4249. if strings.Index(advice.WeekDay, "周二") == -1 {
  4250. advice_three = append(advice_three, advice)
  4251. }
  4252. break
  4253. case 3:
  4254. if strings.Index(advice.WeekDay, "周三") == -1 {
  4255. advice_three = append(advice_three, advice)
  4256. }
  4257. break
  4258. case 4:
  4259. if strings.Index(advice.WeekDay, "周四") == -1 {
  4260. advice_three = append(advice_three, advice)
  4261. }
  4262. break
  4263. case 5:
  4264. if strings.Index(advice.WeekDay, "周五") == -1 {
  4265. advice_three = append(advice_three, advice)
  4266. }
  4267. break
  4268. case 6:
  4269. if strings.Index(advice.WeekDay, "周六") == -1 {
  4270. advice_three = append(advice_three, advice)
  4271. }
  4272. break
  4273. case 0:
  4274. if strings.Index(advice.WeekDay, "周日") == -1 {
  4275. advice_three = append(advice_three, advice)
  4276. }
  4277. break
  4278. }
  4279. }
  4280. }
  4281. for _, advice := range advices_two {
  4282. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4283. now := p.Unix()
  4284. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4285. dayStr2 := "-" + dayStr
  4286. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4287. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4288. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4289. for _, ad := range advices {
  4290. advice_three = append(advice_three, ad)
  4291. }
  4292. }
  4293. if err == nil {
  4294. c.ServeSuccessJSON(map[string]interface{}{
  4295. "status": "2",
  4296. "advices": advices,
  4297. "advices_two": RemoveRepeatedElement(advice_three),
  4298. "is_open_remind": config.IsOpenRemind,
  4299. })
  4300. }
  4301. }
  4302. }
  4303. func (c *DialysisApiController) GetLongAdviceTwo() {
  4304. patient_id, _ := c.GetInt64("patient_id")
  4305. schedule_date, _ := c.GetInt64("schedule_date")
  4306. adminUserInfo := c.GetAdminUserInfo()
  4307. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4308. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4309. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4310. c.ServeSuccessJSON(map[string]interface{}{
  4311. "status": "1",
  4312. })
  4313. return
  4314. } else { //开启推送提醒
  4315. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4316. var advice_three []*models.DoctorAdvice
  4317. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4318. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4319. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4320. for _, advice := range advices {
  4321. if advice.FrequencyType == 3 {
  4322. t := time.Now()
  4323. week := int(t.Weekday())
  4324. switch week {
  4325. case 1:
  4326. if strings.Index(advice.WeekDay, "周一") == -1 {
  4327. advice_three = append(advice_three, advice)
  4328. }
  4329. break
  4330. case 2:
  4331. if strings.Index(advice.WeekDay, "周二") == -1 {
  4332. advice_three = append(advice_three, advice)
  4333. }
  4334. break
  4335. case 3:
  4336. if strings.Index(advice.WeekDay, "周三") == -1 {
  4337. advice_three = append(advice_three, advice)
  4338. }
  4339. break
  4340. case 4:
  4341. if strings.Index(advice.WeekDay, "周四") == -1 {
  4342. advice_three = append(advice_three, advice)
  4343. }
  4344. break
  4345. case 5:
  4346. if strings.Index(advice.WeekDay, "周五") == -1 {
  4347. advice_three = append(advice_three, advice)
  4348. }
  4349. break
  4350. case 6:
  4351. if strings.Index(advice.WeekDay, "周六") == -1 {
  4352. advice_three = append(advice_three, advice)
  4353. }
  4354. break
  4355. case 0:
  4356. if strings.Index(advice.WeekDay, "周日") == -1 {
  4357. advice_three = append(advice_three, advice)
  4358. }
  4359. break
  4360. }
  4361. }
  4362. }
  4363. for _, advice := range advices_two {
  4364. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4365. now := p.Unix()
  4366. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4367. dayStr2 := "-" + dayStr
  4368. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4369. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4370. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4371. for _, ad := range advices {
  4372. advice_three = append(advice_three, ad)
  4373. }
  4374. }
  4375. if err == nil {
  4376. c.ServeSuccessJSON(map[string]interface{}{
  4377. "status": "2",
  4378. "advices": advices,
  4379. "advices_two": RemoveRepeatedElement(advice_three),
  4380. "is_open_remind": config.IsOpenRemind,
  4381. })
  4382. }
  4383. }
  4384. }
  4385. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4386. newArr = make([]*models.DoctorAdvice, 0)
  4387. for i := 0; i < len(arr); i++ {
  4388. repeat := false
  4389. for j := i + 1; j < len(arr); j++ {
  4390. if arr[i].ID == arr[j].ID {
  4391. repeat = true
  4392. break
  4393. }
  4394. }
  4395. if !repeat {
  4396. newArr = append(newArr, arr[i])
  4397. }
  4398. }
  4399. return
  4400. }
  4401. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4402. patient, _ := c.GetInt64("id", 0)
  4403. groupNo, _ := c.GetInt64("groupno", 0)
  4404. if patient <= 0 {
  4405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4406. return
  4407. }
  4408. adminUserInfo := c.GetAdminUserInfo()
  4409. dataBody := make(map[string]interface{}, 0)
  4410. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4411. if err != nil {
  4412. utils.ErrorLog(err.Error())
  4413. return
  4414. }
  4415. utils.ErrorLog("%v", dataBody)
  4416. timeLayout := "2006-01-02 15:04"
  4417. loc, _ := time.LoadLocation("Local")
  4418. timeLayout2 := "2006-01-02"
  4419. loc2, _ := time.LoadLocation("Local")
  4420. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4421. utils.ErrorLog("advice_type")
  4422. return
  4423. }
  4424. adviceType := int64(2)
  4425. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4426. utils.ErrorLog("advice_date")
  4427. return
  4428. }
  4429. adviceDate, _ := dataBody["advice_date"].(string)
  4430. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4431. AdviceDate := theTime.Unix()
  4432. RecordDate := theTime.Unix()
  4433. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4434. utils.ErrorLog("start_time")
  4435. return
  4436. }
  4437. startTime, _ := dataBody["start_time"].(string)
  4438. if len(startTime) == 0 {
  4439. utils.ErrorLog("len(start_time) == 0")
  4440. return
  4441. }
  4442. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4443. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4444. //if err != nil {
  4445. // utils.ErrorLog(err.Error())
  4446. // return
  4447. //}
  4448. StartTime := theTimeUnix.Unix()
  4449. fmt.Println("startTIME", StartTime)
  4450. Remark := ""
  4451. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4452. remark, _ := dataBody["remark"].(string)
  4453. Remark = remark
  4454. }
  4455. var advices []*models.GroupAdvice
  4456. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4457. utils.ErrorLog("advices")
  4458. return
  4459. }
  4460. adviceNames := dataBody["advices"].([]interface{})
  4461. for _, adviceNameMap := range adviceNames {
  4462. adviceNameM := adviceNameMap.(map[string]interface{})
  4463. var advice models.GroupAdvice
  4464. advice.Remark = Remark
  4465. advice.AdviceType = adviceType
  4466. advice.StartTime = StartTime
  4467. if advice.StartTime < 0 {
  4468. advice.StartTime = time.Now().Unix()
  4469. }
  4470. advice.AdviceDate = AdviceDate
  4471. advice.RecordDate = RecordDate
  4472. advice.Status = 1
  4473. advice.CreatedTime = time.Now().Unix()
  4474. advice.UpdatedTime = time.Now().Unix()
  4475. advice.StopState = 2
  4476. advice.ExecutionState = 2
  4477. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4478. advice.PatientId = patient
  4479. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4480. advice.IsSettle = 2
  4481. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4482. utils.ErrorLog("advice_name")
  4483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4484. return
  4485. }
  4486. adviceName, _ := adviceNameM["advice_name"].(string)
  4487. if len(adviceName) == 0 {
  4488. utils.ErrorLog("len(advice_name) == 0")
  4489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4490. return
  4491. }
  4492. advice.AdviceName = adviceName
  4493. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4494. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4495. advice.DrugSpec = drugSpec
  4496. }
  4497. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4498. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4499. advice.AdviceDesc = adviceDesc
  4500. }
  4501. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4502. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4503. advice.DrugSpecUnit = drugSpecUnit
  4504. }
  4505. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4506. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4507. // advice.SingleDose = singleDose
  4508. //}
  4509. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4510. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4511. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4512. }
  4513. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4514. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4515. advice.SingleDoseUnit = singleDoseUnit
  4516. }
  4517. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4518. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4519. // advice.PrescribingNumber = prescribingNumber
  4520. //}
  4521. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4522. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4523. }
  4524. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4525. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4526. advice.PrescribingNumberUnit = prescribingNumberUnit
  4527. }
  4528. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4529. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4530. advice.DeliveryWay = deliveryWay
  4531. }
  4532. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4533. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4534. advice.ExecutionFrequency = executionFrequency
  4535. }
  4536. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4537. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4538. advice.FrequencyType = frequency_type
  4539. }
  4540. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4541. day_count := int64(adviceNameM["day_count"].(float64))
  4542. advice.DayCount = day_count
  4543. }
  4544. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4545. way := int64(adviceNameM["way"].(float64))
  4546. advice.Way = way
  4547. }
  4548. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4549. drug_id := int64(adviceNameM["drug_id"].(float64))
  4550. advice.DrugId = drug_id
  4551. }
  4552. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4553. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4554. advice.DrugNameId = drug_name_id
  4555. }
  4556. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4557. week_day, _ := adviceNameM["week_day"].(string)
  4558. advice.WeekDay = week_day
  4559. }
  4560. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4561. template_id, _ := adviceNameM["template_id"].(string)
  4562. advice.TemplateId = template_id
  4563. }
  4564. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4565. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4566. advice.ExecutionFrequency = executionFrequency
  4567. }
  4568. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4569. children := adviceNameM["child"].([]interface{})
  4570. if len(children) > 0 {
  4571. for _, childrenMap := range children {
  4572. childMap := childrenMap.(map[string]interface{})
  4573. var child models.GroupAdvice
  4574. child.Remark = Remark
  4575. child.AdviceType = adviceType
  4576. child.StartTime = StartTime
  4577. if child.StartTime < 0 {
  4578. child.StartTime = time.Now().Unix()
  4579. }
  4580. child.AdviceDate = AdviceDate
  4581. child.RecordDate = RecordDate
  4582. child.Status = 1
  4583. child.CreatedTime = time.Now().Unix()
  4584. child.UpdatedTime = time.Now().Unix()
  4585. child.StopState = 2
  4586. child.ExecutionState = 2
  4587. child.UserOrgId = adminUserInfo.CurrentOrgId
  4588. child.PatientId = patient
  4589. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4590. child.IsSettle = 2
  4591. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4592. utils.ErrorLog("child advice_name")
  4593. return
  4594. }
  4595. childAdviceName, _ := childMap["advice_name"].(string)
  4596. if len(childAdviceName) == 0 {
  4597. utils.ErrorLog("len(child advice_name) == 0")
  4598. return
  4599. }
  4600. child.AdviceName = childAdviceName
  4601. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4602. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4603. child.AdviceDesc = childAdviceDesc
  4604. }
  4605. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4606. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4607. child.DrugSpec = childDrugSpec
  4608. }
  4609. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4610. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4611. child.DrugSpecUnit = childDrugSpecUnit
  4612. }
  4613. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4614. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4615. child.SingleDose = childSingleDose
  4616. }
  4617. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4618. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4619. child.SingleDose = childMap["single_dose"].(float64)
  4620. }
  4621. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4622. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4623. child.Remark = childMap["remark"].(string)
  4624. }
  4625. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4626. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4627. child.DrugId = int64(childMap["drug_id"].(float64))
  4628. }
  4629. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4630. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4631. child.SingleDoseUnit = childSingleDoseUnit
  4632. }
  4633. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4634. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4635. child.PrescribingNumber = childPrescribingNumber
  4636. }
  4637. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4638. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4639. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4640. }
  4641. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4642. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4643. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4644. }
  4645. child.DeliveryWay = advice.DeliveryWay
  4646. child.ExecutionFrequency = advice.ExecutionFrequency
  4647. advice.Children = append(advice.Children, &child)
  4648. }
  4649. }
  4650. }
  4651. advices = append(advices, &advice)
  4652. }
  4653. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4654. for _, item := range advices {
  4655. //记录日志
  4656. byterequest, _ := json.Marshal(item)
  4657. adviceLog := models.XtDoctorAdviceLog{
  4658. UserOrgId: item.UserOrgId,
  4659. PatientId: item.PatientId,
  4660. AdminUserId: adminUserInfo.AdminUser.Id,
  4661. Module: 1,
  4662. ErrLog: string(byterequest),
  4663. Status: 1,
  4664. Ctime: time.Now().Unix(),
  4665. Mtime: 0,
  4666. Source: "电脑端医嘱推送",
  4667. RecordDate: item.AdviceDate,
  4668. }
  4669. service.CreateDoctorAdviceLog(adviceLog)
  4670. }
  4671. //创建步骤表
  4672. finish := models.XtDialysisFinish{
  4673. IsFinish: 1,
  4674. UserOrgId: adminUserInfo.CurrentOrgId,
  4675. Status: 1,
  4676. Ctime: time.Now().Unix(),
  4677. Mtime: 0,
  4678. Module: 4,
  4679. RecordDate: AdviceDate,
  4680. Sourse: 1,
  4681. PatientId: patient,
  4682. }
  4683. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4684. if dialysisFinish.ID == 0 {
  4685. service.CreateDialysisFinish(finish)
  4686. }
  4687. redis := service.RedisClient()
  4688. formatAdviceDate := theTime.Format("2006-01-02")
  4689. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4690. redis.Set(key, "", time.Second)
  4691. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4692. redis.Set(keyOne, "", time.Second)
  4693. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4694. redis.Set(keyFour, "", time.Second)
  4695. defer redis.Close()
  4696. if err != nil {
  4697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4698. return
  4699. }
  4700. c.ServeSuccessJSON(map[string]interface{}{
  4701. "msg": "ok",
  4702. "advices": list,
  4703. })
  4704. return
  4705. }
  4706. func (c *DialysisApiController) GetSolution() {
  4707. patient_id, _ := c.GetInt64("patient_id")
  4708. mode_id, _ := c.GetInt64("mode_id")
  4709. adminUserInfo := c.GetAdminUserInfo()
  4710. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4711. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4712. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  4713. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  4714. if err != nil {
  4715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4716. return
  4717. }
  4718. c.ServeSuccessJSON(map[string]interface{}{
  4719. "solution": solution,
  4720. "prescription": prescription,
  4721. "system_prescription": system_prescription,
  4722. "dialysisPrescription": dialysisPrescription,
  4723. })
  4724. }
  4725. func (c *DialysisApiController) GetSchedule() {
  4726. schedual_type, _ := c.GetInt64("schedual_type")
  4727. adminUserInfo := c.GetAdminUserInfo()
  4728. //timeLayout := "2006-01-02 15:04:05"
  4729. //
  4730. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  4731. //loc, _ := time.LoadLocation("Local")
  4732. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4733. //scheduleTime := theStartTime.Unix()
  4734. scheduleTime, _ := c.GetInt64("record_date")
  4735. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4736. c.ServeSuccessJSON(map[string]interface{}{
  4737. "number": deviceNumber,
  4738. })
  4739. }
  4740. func (this *DialysisApiController) GetTodayMonitor() {
  4741. thisTime := time.Now()
  4742. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4743. timeLayout := "2006-01-02 15:04:05"
  4744. loc, _ := time.LoadLocation("Local")
  4745. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4746. theAssessmentDateTime := theStartTime.Unix()
  4747. patientID, _ := this.GetInt64("patient_id")
  4748. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4749. adminInfo := this.GetAdminUserInfo()
  4750. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4751. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4752. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4753. var ultrafiltration_rate float64
  4754. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4755. //针对福建医师汇 获取透前评估预增脱水量
  4756. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4757. fmt.Println("透前评估数据", evaluation)
  4758. if prescription.ID > 0 {
  4759. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4760. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4761. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4762. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4763. record.UltrafiltrationRate = ultrafiltration_rate
  4764. }
  4765. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  4766. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4767. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4768. record.UltrafiltrationRate = ultrafiltration_rate
  4769. }
  4770. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  4771. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4772. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4773. record.UltrafiltrationRate = ultrafiltration_rate
  4774. }
  4775. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  4776. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4777. record.UltrafiltrationRate = ultrafiltration_rate
  4778. }
  4779. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  4780. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4781. record.UltrafiltrationRate = ultrafiltration_rate
  4782. }
  4783. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  4784. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4785. record.UltrafiltrationRate = ultrafiltration_rate
  4786. }
  4787. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  4788. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4789. record.UltrafiltrationRate = ultrafiltration_rate
  4790. }
  4791. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  4792. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4793. record.UltrafiltrationRate = ultrafiltration_rate
  4794. }
  4795. // 只针对方济医院
  4796. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4797. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4798. ultrafiltration_rate = value
  4799. record.UltrafiltrationRate = ultrafiltration_rate
  4800. }
  4801. //长沙南雅
  4802. 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 {
  4803. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4804. record.UltrafiltrationRate = ultrafiltration_rate
  4805. }
  4806. if adminInfo.CurrentOrgId == 10694 || adminInfo.CurrentOrgId == 10697 {
  4807. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4808. ultrafiltration_rate = ultrafiltration_rate
  4809. }
  4810. }
  4811. }
  4812. // record.UltrafiltrationRate = ultrafiltration_rate
  4813. record.UltrafiltrationVolume = 0
  4814. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4815. if ultrafiltration_rate > 0 {
  4816. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4817. record.UltrafiltrationVolume = value
  4818. }
  4819. }
  4820. 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 {
  4821. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4822. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4823. record.UltrafiltrationVolume = ultrafiltration_volume
  4824. }
  4825. }
  4826. //长沙南雅
  4827. 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 {
  4828. if ultrafiltration_rate > 0 {
  4829. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4830. record.UltrafiltrationVolume = ultrafiltration_volume
  4831. }
  4832. }
  4833. if template.TemplateId == 47 || template.TemplateId == 54 {
  4834. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4835. }
  4836. if adminInfo.CurrentOrgId == 10697 || adminInfo.CurrentOrgId == 10694 {
  4837. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate * 1000)
  4838. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4839. }
  4840. this.ServeSuccessJSON(map[string]interface{}{
  4841. "monitor": record,
  4842. })
  4843. }
  4844. func (c *DialysisApiController) UploadDryWeight() {
  4845. patient_id, _ := c.GetInt64("id")
  4846. dry_weight, _ := c.GetFloat("dry_weight")
  4847. doctor_id, _ := c.GetInt64("doctor_id")
  4848. remark := c.GetString("remark")
  4849. adminUserInfo := c.GetAdminUserInfo()
  4850. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4851. fmt.Println(err)
  4852. if err == gorm.ErrRecordNotFound {
  4853. dryWeight := &models.SgjPatientDryweight{
  4854. PatientId: patient_id,
  4855. DryWeight: dry_weight,
  4856. Remakes: remark,
  4857. Ctime: time.Now().Unix(),
  4858. Mtime: time.Now().Unix(),
  4859. Creator: doctor_id,
  4860. Status: 1,
  4861. UserOrgId: adminUserInfo.CurrentOrgId,
  4862. AdjustedValue: "/",
  4863. UserId: adminUserInfo.AdminUser.Id,
  4864. }
  4865. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4866. loc, _ := time.LoadLocation("Local")
  4867. nowTime := time.Now()
  4868. nowDay := nowTime.Format("2006-01-02")
  4869. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4870. redis := service.RedisClient()
  4871. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4872. redis.Set(keyOne, "", time.Second)
  4873. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4874. redis.Set(key, "", time.Second)
  4875. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4876. redis.Set(keyTwo, "", time.Second)
  4877. redis.Close()
  4878. if createErr == nil {
  4879. c.ServeSuccessJSON(map[string]interface{}{
  4880. "msg": "提交成功",
  4881. "weight": dryWeight,
  4882. })
  4883. }
  4884. } else {
  4885. dryWeight := &models.SgjPatientDryweight{
  4886. PatientId: patient_id,
  4887. DryWeight: dry_weight,
  4888. Remakes: remark,
  4889. Ctime: time.Now().Unix(),
  4890. Mtime: time.Now().Unix(),
  4891. Creator: doctor_id,
  4892. Status: 1,
  4893. UserOrgId: adminUserInfo.CurrentOrgId,
  4894. AdjustedValue: "/",
  4895. UserId: adminUserInfo.AdminUser.Id,
  4896. }
  4897. var value float64
  4898. value = dry_weight - weightAdjust.DryWeight
  4899. fmt.Println(value)
  4900. if value < 0 {
  4901. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4902. } else if value == 0 {
  4903. dryWeight.AdjustedValue = "/"
  4904. } else if value > 0 {
  4905. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4906. }
  4907. fmt.Println(value)
  4908. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4909. loc, _ := time.LoadLocation("Local")
  4910. nowTime := time.Now()
  4911. nowDay := nowTime.Format("2006-01-02")
  4912. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4913. redis := service.RedisClient()
  4914. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4915. redis.Set(keyOne, "", time.Second)
  4916. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4917. redis.Set(key, "", time.Second)
  4918. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4919. redis.Set(keyTwo, "", time.Second)
  4920. redis.Close()
  4921. if createErr == nil {
  4922. c.ServeSuccessJSON(map[string]interface{}{
  4923. "msg": "提交成功",
  4924. "weight": dryWeight,
  4925. })
  4926. }
  4927. }
  4928. }
  4929. func (this *DialysisApiController) GetFuncPurview() {
  4930. adminUserInfo := this.GetAdminUserInfo()
  4931. user_id := adminUserInfo.AdminUser.Id
  4932. app_id := adminUserInfo.CurrentAppId
  4933. org_id := adminUserInfo.CurrentOrgId
  4934. create_url := this.GetString("create_url")
  4935. modify_url := this.GetString("modify_url")
  4936. modify_other_url := this.GetString("modify_other_url")
  4937. del_url := this.GetString("del_url")
  4938. del_other_url := this.GetString("del_other_url")
  4939. exce_url := this.GetString("exce_url")
  4940. check_url := this.GetString("check_url")
  4941. modify_exce_url := this.GetString("modify_exce_url")
  4942. module, _ := this.GetInt64("module", 0)
  4943. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4944. var is_has_create bool
  4945. var is_has_modify bool
  4946. var is_has_modify_other bool
  4947. var is_has_del bool
  4948. var is_has_del_other bool
  4949. var is_has_exce bool
  4950. var is_has_check bool
  4951. var is_has_modify_exce bool
  4952. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4953. if adminUserInfo.AdminUser.Id != org.Creator {
  4954. if app_role != nil {
  4955. if len(app_role.RoleIds) > 0 {
  4956. roles := strings.Split(app_role.RoleIds, ",")
  4957. var userRolePurviews string
  4958. for _, item := range roles {
  4959. role_id, _ := strconv.ParseInt(item, 10, 64)
  4960. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4961. if len(userRolePurviews) == 0 {
  4962. userRolePurviews = purviews
  4963. } else {
  4964. userRolePurviews = userRolePurviews + "," + purviews
  4965. }
  4966. }
  4967. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4968. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4969. for _, item := range funcPurviews {
  4970. //for _, url := range strings.Split(item.Urlfor,","){
  4971. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4972. is_has_create = true
  4973. }
  4974. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4975. is_has_modify = true
  4976. }
  4977. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4978. is_has_modify_other = true
  4979. }
  4980. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4981. is_has_del = true
  4982. }
  4983. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4984. is_has_del_other = true
  4985. }
  4986. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4987. is_has_exce = true
  4988. }
  4989. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4990. is_has_check = true
  4991. }
  4992. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4993. is_has_modify_exce = true
  4994. }
  4995. }
  4996. } else {
  4997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4998. return
  4999. }
  5000. this.ServeSuccessJSON(map[string]interface{}{
  5001. "is_has_create": is_has_create,
  5002. "is_has_modify": is_has_modify,
  5003. "is_has_modify_other": is_has_modify_other,
  5004. "is_has_del": is_has_del,
  5005. "is_has_del_other": is_has_del_other,
  5006. "is_has_exce": is_has_exce,
  5007. "is_has_check": is_has_check,
  5008. "is_has_modify_exce": is_has_modify_exce,
  5009. "module": module,
  5010. })
  5011. } else {
  5012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  5013. return
  5014. }
  5015. } else {
  5016. this.ServeSuccessJSON(map[string]interface{}{
  5017. "is_has_create": true,
  5018. "is_has_modify": true,
  5019. "is_has_modify_other": true,
  5020. "is_has_del": true,
  5021. "is_has_del_other": true,
  5022. "is_has_exce": true,
  5023. "is_has_check": true,
  5024. "is_has_modify_exce": true,
  5025. "module": true,
  5026. })
  5027. }
  5028. }
  5029. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  5030. patient_id, _ := this.GetInt64("patient_id", 0)
  5031. advice_date, _ := this.GetInt64("advice_date")
  5032. adminUserInfo := this.GetAdminUserInfo()
  5033. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5034. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5035. this.ServeSuccessJSON(map[string]interface{}{
  5036. "doctorAdvice": doctorAdvice,
  5037. "hisDoctorAdvice": hisDoctorAdvice,
  5038. })
  5039. }
  5040. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  5041. change_type, _ := this.GetInt64("type", 0)
  5042. record_date := this.GetString("record_time")
  5043. patient_id, _ := this.GetInt64("patient_id", 0)
  5044. timeLayout := "2006-01-02"
  5045. loc, _ := time.LoadLocation("Local")
  5046. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5047. record_time := theAdviceRecordTime.Unix()
  5048. adminUserInfo := this.GetAdminUserInfo()
  5049. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  5050. if err == nil {
  5051. if len(advices) == 0 {
  5052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5053. return
  5054. } else {
  5055. this.ServeSuccessJSON(map[string]interface{}{
  5056. "advices": advices,
  5057. "schedule": sch,
  5058. })
  5059. return
  5060. }
  5061. } else {
  5062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5063. return
  5064. }
  5065. }
  5066. func (c *DialysisApiController) GetDialysisGoods() {
  5067. schedualDate := c.GetString("schedule_date")
  5068. schedule_type, _ := c.GetInt64("schedule_type")
  5069. partition_id, _ := c.GetInt64("partition_id")
  5070. page, _ := c.GetInt("page")
  5071. limit, _ := c.GetInt("limit")
  5072. keywords := c.GetString("keywords")
  5073. patient_id, _ := c.GetInt64("patient_id")
  5074. good_type, _ := c.GetInt64("good_type")
  5075. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5076. if parseDateErr != nil && len(schedualDate) != 0 {
  5077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5078. return
  5079. }
  5080. schedualEndDate := int64(0)
  5081. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5082. if parseDateErr != nil && len(schedualDate) != 0 {
  5083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5084. return
  5085. }
  5086. schedualEndDate = endDate.Unix()
  5087. adminUser := c.GetAdminUserInfo()
  5088. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  5089. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  5090. if err == gorm.ErrRecordNotFound {
  5091. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5092. var ids []int64
  5093. for _, item := range list {
  5094. ids = append(ids, item.PatientId)
  5095. }
  5096. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5097. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5098. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5099. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5100. item.LastAutomaticReduceDetail = goodUser
  5101. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5102. }
  5103. c.ServeSuccessJSON(map[string]interface{}{
  5104. "dialysis_goods": dialysisGoods,
  5105. "good_type": goodTypes,
  5106. "total": total,
  5107. })
  5108. return
  5109. } else if err == nil {
  5110. //获取当天排班的每个患者的库存使用情况
  5111. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5112. var ids []int64
  5113. for _, item := range list {
  5114. ids = append(ids, item.PatientId)
  5115. }
  5116. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5117. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5118. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5119. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5120. fmt.Println(goodUser)
  5121. fmt.Println(lastGoodUserDetial)
  5122. item.LastAutomaticReduceDetail = goodUser
  5123. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5124. }
  5125. if err == nil {
  5126. c.ServeSuccessJSON(map[string]interface{}{
  5127. "dialysis_goods": dialysisGoods,
  5128. "good_type": goodTypes,
  5129. "total": total,
  5130. })
  5131. return
  5132. } else {
  5133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5134. return
  5135. }
  5136. } else if err != nil {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5138. return
  5139. }
  5140. }
  5141. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  5142. start_time := c.GetString("start_time")
  5143. end_time := c.GetString("end_time")
  5144. timeLayout := "2006-01-02"
  5145. loc, _ := time.LoadLocation("Local")
  5146. var theStartTime int64
  5147. if len(start_time) > 0 {
  5148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5149. if err != nil {
  5150. utils.ErrorLog(err.Error())
  5151. }
  5152. theStartTime = theTime.Unix()
  5153. }
  5154. var theEndtTime int64
  5155. if len(end_time) > 0 {
  5156. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5157. if err != nil {
  5158. utils.ErrorLog(err.Error())
  5159. }
  5160. theEndtTime = theTime.Unix()
  5161. }
  5162. adminUser := c.GetAdminUserInfo()
  5163. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  5164. if err == nil {
  5165. c.ServeSuccessJSON(map[string]interface{}{
  5166. "stock_out": outInfo,
  5167. })
  5168. return
  5169. } else {
  5170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5171. return
  5172. }
  5173. }
  5174. func (c *DialysisApiController) GetRoleList() {
  5175. orgId := c.GetAdminUserInfo().CurrentOrgId
  5176. admin_user_id, _ := c.GetInt64("admin_user_id")
  5177. list, err := service.GetRoleList(orgId, admin_user_id)
  5178. if err == nil {
  5179. c.ServeSuccessJSON(map[string]interface{}{
  5180. "adminRole": list,
  5181. })
  5182. return
  5183. } else {
  5184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5185. return
  5186. }
  5187. }
  5188. func (c *DialysisApiController) GetInitPrintData() {
  5189. patient_id, _ := c.GetInt64("patient_id")
  5190. record_date, _ := c.GetInt64("record_date")
  5191. orgId := c.GetAdminUserInfo().CurrentOrgId
  5192. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  5193. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5194. if err == nil {
  5195. c.ServeSuccessJSON(map[string]interface{}{
  5196. "list": list,
  5197. "assessmentAfterDislysis": assessmentAfterDislysis,
  5198. })
  5199. return
  5200. } else {
  5201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5202. return
  5203. }
  5204. }
  5205. func (c *DialysisApiController) GetInitPrintDataOne() {
  5206. patient_id, _ := c.GetInt64("patient_id")
  5207. start_time := c.GetString("record_date")
  5208. timeLayout := "2006-01-02"
  5209. loc, _ := time.LoadLocation("Local")
  5210. var theStartTime int64
  5211. if len(start_time) > 0 {
  5212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5213. if err != nil {
  5214. utils.ErrorLog(err.Error())
  5215. }
  5216. theStartTime = theTime.Unix()
  5217. }
  5218. orgId := c.GetAdminUserInfo().CurrentOrgId
  5219. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  5220. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5221. if err == nil {
  5222. c.ServeSuccessJSON(map[string]interface{}{
  5223. "list": list,
  5224. "assessmentAfterDislysis": assessmentAfterDislysis,
  5225. })
  5226. return
  5227. } else {
  5228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5229. return
  5230. }
  5231. }
  5232. // 新接口
  5233. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5234. keyword := this.GetString("keywords")
  5235. limit, _ := this.GetInt64("limit")
  5236. page, _ := this.GetInt64("page")
  5237. partition_id, _ := this.GetInt64("partition_id")
  5238. schedule_type, _ := this.GetInt64("schedule_type")
  5239. start_time := this.GetString("schedule_date")
  5240. advice_ids := this.GetString("ids")
  5241. var ids []string
  5242. if advice_ids != "" {
  5243. ids = strings.Split(advice_ids, ",")
  5244. }
  5245. timeLayout := "2006-01-02"
  5246. loc, _ := time.LoadLocation("Local")
  5247. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5248. orgId := this.GetAdminUserInfo().CurrentOrgId
  5249. _, config := service.FindXTHisRecordByOrgId(orgId)
  5250. goodType, _ := service.GetAllGoodType(orgId)
  5251. if config.IsOpen != 1 {
  5252. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5253. if err == nil {
  5254. this.ServeSuccessJSON(map[string]interface{}{
  5255. "list": list,
  5256. "total": total,
  5257. "config": config,
  5258. "goodType": goodType,
  5259. })
  5260. return
  5261. } else {
  5262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5263. return
  5264. }
  5265. }
  5266. if config.IsOpen == 1 {
  5267. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5268. if err == nil {
  5269. this.ServeSuccessJSON(map[string]interface{}{
  5270. "list": list,
  5271. "total": total,
  5272. "config": config,
  5273. "goodType": goodType,
  5274. })
  5275. return
  5276. }
  5277. }
  5278. }
  5279. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5280. keyword := this.GetString("keywords")
  5281. limit, _ := this.GetInt64("limit")
  5282. page, _ := this.GetInt64("page")
  5283. partition_id, _ := this.GetInt64("partition_id")
  5284. schedule_type, _ := this.GetInt64("schedule_type")
  5285. start_time := this.GetString("schedule_date")
  5286. ids := this.GetString("ids")
  5287. var idArray []string
  5288. if ids != "" {
  5289. idArray = strings.Split(ids, ",")
  5290. }
  5291. timeLayout := "2006-01-02"
  5292. loc, _ := time.LoadLocation("Local")
  5293. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5294. orgId := this.GetAdminUserInfo().CurrentOrgId
  5295. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5296. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5297. //获取长期医嘱
  5298. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5299. _, config := service.FindXTHisRecordByOrgId(orgId)
  5300. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5301. if err == nil {
  5302. this.ServeSuccessJSON(map[string]interface{}{
  5303. "list": list,
  5304. "total": total,
  5305. "adviceList": adviceList,
  5306. "config": config,
  5307. "drugList": drugList,
  5308. "tablelist": tablelist,
  5309. })
  5310. return
  5311. } else {
  5312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5313. return
  5314. }
  5315. }
  5316. func (this *DialysisApiController) SaveDialysisSetting() {
  5317. orgId := this.GetAdminUserInfo().CurrentOrgId
  5318. device_number_set, _ := this.GetInt64("device_number_set")
  5319. device_type_set, _ := this.GetInt64("device_type_set")
  5320. name_set, _ := this.GetInt64("name_set")
  5321. admission_number_set, _ := this.GetInt64("admission_number_set")
  5322. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5323. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5324. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5325. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5326. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5327. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5328. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5329. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5330. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5331. mode_id_set, _ := this.GetInt64("mode_id_set")
  5332. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5333. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5334. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5335. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5336. kalium_set, _ := this.GetInt64("kalium_set")
  5337. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5338. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5339. glucose_set, _ := this.GetInt64("glucose_set")
  5340. sodium_set, _ := this.GetInt64("sodium_set")
  5341. calcium_set, _ := this.GetInt64("calcium_set")
  5342. blood_access_set, _ := this.GetInt64("blood_access_set")
  5343. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5344. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5345. cuhong_set, _ := this.GetInt64("cuhong_set")
  5346. zuoka_set, _ := this.GetInt64("zuoka_set")
  5347. difenzi_set, _ := this.GetInt64("difenzi_set")
  5348. gansuna_set, _ := this.GetInt64("gansuna_set")
  5349. zhetangtie_set, _ := this.GetInt64("zhetangtie_set")
  5350. niaojimei_set, _ := this.GetInt64("niaojimei_set")
  5351. dialysisSetting := models.XtDialysisSetting{
  5352. Sodium: sodium_set,
  5353. Calcium: calcium_set,
  5354. BloodAccess: blood_access_set,
  5355. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5356. DisplaceLiquiPart: displace_liqui_part_set,
  5357. UserOrgId: orgId,
  5358. Status: 1,
  5359. DeviceNumber: device_number_set,
  5360. DeviceType: device_type_set,
  5361. Name: name_set,
  5362. AdmissionNumber: admission_number_set,
  5363. DialysisNo: dialysis_no_set,
  5364. WeightBefor: weight_befor_set,
  5365. DryWeight: dry_weight_set,
  5366. BloodPressure: blood_pressure_set,
  5367. UltrafiltrationVolume: ultrafiltration_volume_set,
  5368. InternalFistula: internal_fistula_set,
  5369. BloodFlowVolume: blood_flow_volume_set,
  5370. Anticoagulant: anticoagulant_set,
  5371. SealingFluidDispose: sealing_fluid_dispose_set,
  5372. ModeId: mode_id_set,
  5373. DialysisTime: dialysis_time_set,
  5374. DialysisDialyszers: dialysis_dialyszers_set,
  5375. DialysisIrrigation: dialysis_irrigation_set,
  5376. Gaijiliang: gaijiliang_set,
  5377. Kalium: kalium_set,
  5378. DisplaceLiquiValue: displace_liqui_value_set,
  5379. Bicarbonate: bicarbonate_set,
  5380. Glucose: glucose_set,
  5381. Ctime: time.Now().Unix(),
  5382. Mtime: time.Now().Unix(),
  5383. CuhongSet: cuhong_set,
  5384. ZuokaSet: zuoka_set,
  5385. DifenziSet: difenzi_set,
  5386. GansunaSet: gansuna_set,
  5387. ZhetangtieSet: zhetangtie_set,
  5388. NiaojimeiSet: niaojimei_set,
  5389. }
  5390. err := service.SaveDialysisSetting(dialysisSetting)
  5391. if err == nil {
  5392. this.ServeSuccessJSON(map[string]interface{}{
  5393. "dialysisSetting": dialysisSetting,
  5394. })
  5395. return
  5396. } else {
  5397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5398. return
  5399. }
  5400. }
  5401. func (this *DialysisApiController) GetDialysisSetting() {
  5402. orgId := this.GetAdminUserInfo().CurrentOrgId
  5403. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5404. this.ServeSuccessJSON(map[string]interface{}{
  5405. "dialysisSett": dialysisSett,
  5406. })
  5407. return
  5408. }
  5409. func (this *DialysisApiController) GetDialysisParameterList() {
  5410. keyword := this.GetString("keywords")
  5411. limit, _ := this.GetInt64("limit")
  5412. page, _ := this.GetInt64("page")
  5413. //partition_id, _ := this.GetInt64("partition_id")
  5414. partion_type := this.GetString("partition_id")
  5415. idSplit := strings.Split(partion_type, ",")
  5416. schedule_type, _ := this.GetInt64("schedule_type")
  5417. start_time := this.GetString("schedule_date")
  5418. timeLayout := "2006-01-02"
  5419. loc, _ := time.LoadLocation("Local")
  5420. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5421. orgId := this.GetAdminUserInfo().CurrentOrgId
  5422. scheduids := this.GetString("ids")
  5423. var ids []string
  5424. if scheduids != "" {
  5425. ids = strings.Split(scheduids, ",")
  5426. }
  5427. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5428. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5429. if err == nil {
  5430. this.ServeSuccessJSON(map[string]interface{}{
  5431. "list": list,
  5432. "total": total,
  5433. "dialysisSett": dialysisSett,
  5434. })
  5435. return
  5436. } else {
  5437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5438. return
  5439. }
  5440. }
  5441. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5442. orgId := this.GetAdminUserInfo().CurrentOrgId
  5443. schedule_type, _ := this.GetInt64("schedule_type")
  5444. //partion_type, _ := this.GetInt64("partion_type")
  5445. start_time := this.GetString("selected_date")
  5446. partion_type := this.GetString("partion_type")
  5447. var ids []string
  5448. ids = strings.Split(partion_type, ",")
  5449. timeLayout := "2006-01-02"
  5450. loc, _ := time.LoadLocation("Local")
  5451. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5452. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5453. if err == nil {
  5454. this.ServeSuccessJSON(map[string]interface{}{
  5455. "list": list,
  5456. })
  5457. return
  5458. } else {
  5459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5460. return
  5461. }
  5462. }
  5463. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5464. orgId := this.GetAdminUserInfo().CurrentOrgId
  5465. schedule_type, _ := this.GetInt64("schedule_type")
  5466. //partion_type, _ := this.GetInt64("partion_type")
  5467. partion_type := this.GetString("partion_type")
  5468. var ids []string
  5469. ids = strings.Split(partion_type, ",")
  5470. start_time := this.GetString("selected_date")
  5471. timeLayout := "2006-01-02"
  5472. loc, _ := time.LoadLocation("Local")
  5473. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5474. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5475. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5476. //获取长期医嘱
  5477. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5478. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5479. _, config := service.FindXTHisRecordByOrgId(orgId)
  5480. if err == nil {
  5481. this.ServeSuccessJSON(map[string]interface{}{
  5482. "list": list,
  5483. "drug": drug,
  5484. "adviceList": adviceList,
  5485. "config": config,
  5486. "tablelist": tablelist,
  5487. })
  5488. return
  5489. } else {
  5490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5491. return
  5492. }
  5493. }
  5494. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5495. orgId := this.GetAdminUserInfo().CurrentOrgId
  5496. schedule_type, _ := this.GetInt64("schedule_type")
  5497. partion_type, _ := this.GetInt64("partion_type")
  5498. start_time := this.GetString("selected_date")
  5499. timeLayout := "2006-01-02"
  5500. loc, _ := time.LoadLocation("Local")
  5501. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5502. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5503. if err == nil {
  5504. this.ServeSuccessJSON(map[string]interface{}{
  5505. "list": list,
  5506. })
  5507. return
  5508. } else {
  5509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5510. return
  5511. }
  5512. }
  5513. func (this *DialysisApiController) SaveHisDialysis() {
  5514. var ids []string
  5515. advice_ids := this.GetString("ids")
  5516. ids = strings.Split(advice_ids, ",")
  5517. orgId := this.GetAdminUserInfo().CurrentOrgId
  5518. service.SaveHisDialysis(orgId, ids)
  5519. returnData := make(map[string]interface{}, 0)
  5520. returnData["msg"] = "ok"
  5521. this.ServeSuccessJSON(returnData)
  5522. return
  5523. }
  5524. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5525. orgId := this.GetAdminUserInfo().CurrentOrgId
  5526. schedule_type, _ := this.GetInt64("schedule_type")
  5527. //partion_type, _ := this.GetInt64("partion_type")
  5528. partion_type := this.GetString("partion_type")
  5529. var ids []string
  5530. ids = strings.Split(partion_type, ",")
  5531. start_time := this.GetString("selected_date")
  5532. timeLayout := "2006-01-02"
  5533. loc, _ := time.LoadLocation("Local")
  5534. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5535. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5536. this.ServeSuccessJSON(map[string]interface{}{
  5537. "list": list,
  5538. })
  5539. return
  5540. }
  5541. func (this *DialysisApiController) GetPatientSchedule() {
  5542. orgId := this.GetAdminUserInfo().CurrentOrgId
  5543. patient_id, _ := this.GetInt64("patient_id")
  5544. schedule_date, _ := this.GetInt64("schedule_date")
  5545. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5546. this.ServeSuccessJSON(map[string]interface{}{
  5547. "schedulePatient": schedulePatient,
  5548. })
  5549. }
  5550. func (c *DialysisApiController) GetSchedulePrintList() {
  5551. page, _ := c.GetInt64("page", 1)
  5552. limit, _ := c.GetInt64("limit", 10)
  5553. schedulType, _ := c.GetInt64("schedule_type", 0)
  5554. partitionType, _ := c.GetInt64("partition_type", 0)
  5555. keywords := c.GetString("keywords")
  5556. schedule_date := c.GetString("schedule_date")
  5557. timeLayout := "2006-01-02"
  5558. loc, _ := time.LoadLocation("Local")
  5559. var theStartTime int64
  5560. if len(schedule_date) > 0 {
  5561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5562. if err != nil {
  5563. utils.ErrorLog(err.Error())
  5564. }
  5565. theStartTime = theTime.Unix()
  5566. }
  5567. adminUserInfo := c.GetAdminUserInfo()
  5568. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5569. for _, item := range list {
  5570. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5571. item.DialysisOrderTwenty = order
  5572. }
  5573. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5574. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5575. c.ServeSuccessJSON(map[string]interface{}{
  5576. "list": list,
  5577. "total": total,
  5578. "numberList": numberList,
  5579. "listOne": listOne,
  5580. })
  5581. }
  5582. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5583. orgId := this.GetAdminUserInfo().CurrentOrgId
  5584. list, _ := service.GetSolutionListByOrgId(orgId)
  5585. for _, item := range list {
  5586. //获取该模式最新的1条数据
  5587. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5588. //更新状态值
  5589. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5590. }
  5591. this.ServeSuccessJSON(map[string]interface{}{
  5592. "list": list,
  5593. })
  5594. }
  5595. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5596. orgId := this.GetAdminUserInfo().CurrentOrgId
  5597. is_open, _ := this.GetInt64("is_open")
  5598. idsStr := this.GetString("str")
  5599. recordIDStrs := strings.Split(idsStr, ",")
  5600. start_time := this.GetString("advice_date")
  5601. exec_time, _ := this.GetInt64("exec_time")
  5602. timeLayout := "2006-01-02"
  5603. loc, _ := time.LoadLocation("Local")
  5604. var startTime int64
  5605. if len(start_time) > 0 {
  5606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5607. if err != nil {
  5608. //fmt.Println(err)
  5609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5610. return
  5611. }
  5612. startTime = theTime.Unix()
  5613. }
  5614. config, _ := service.GetDrugOpenConfigOne(orgId)
  5615. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5616. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5617. //his医嘱
  5618. if is_open == 1 {
  5619. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5620. //查找未执行医嘱
  5621. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5622. for _, item := range list {
  5623. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5624. this.ServeSuccessJSON(map[string]interface{}{
  5625. "msg": "3",
  5626. })
  5627. return
  5628. }
  5629. }
  5630. for _, item := range groupList {
  5631. for _, it := range list {
  5632. if item.DrugId == it.DrugId {
  5633. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5634. }
  5635. }
  5636. }
  5637. for _, item := range groupList {
  5638. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5639. var sum_out_count int64
  5640. for _, it := range item.ChildDoctorAdvice {
  5641. var prescribing_number int64
  5642. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5643. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5644. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5645. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5646. }
  5647. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5648. prescribing_number = parseIntPrescribingNumber
  5649. }
  5650. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5651. prescribing_number = parseIntPrescribingNumber
  5652. }
  5653. sum_out_count += prescribing_number
  5654. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5655. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5656. //库存不足
  5657. if sum_out_count > drugStockOut.FlushCount {
  5658. this.ServeSuccessJSON(map[string]interface{}{
  5659. "msg": "2",
  5660. "drug": medical,
  5661. })
  5662. return
  5663. }
  5664. }
  5665. }
  5666. creater := this.GetAdminUserInfo().AdminUser.Id
  5667. //执行出库逻辑
  5668. for _, item := range list {
  5669. hisadvice := &models.HisDoctorAdviceInfo{
  5670. ID: item.ID,
  5671. UserOrgId: item.UserOrgId,
  5672. PatientId: item.PatientId,
  5673. AdviceType: item.AdviceType,
  5674. AdviceDate: item.AdviceDate,
  5675. StartTime: item.StartTime,
  5676. AdviceName: item.AdviceName,
  5677. AdviceDesc: item.AdviceDesc,
  5678. ReminderDate: item.ReminderDate,
  5679. SingleDose: item.SingleDose,
  5680. SingleDoseUnit: item.SingleDoseUnit,
  5681. DrugSpec: item.DrugSpec,
  5682. DrugSpecUnit: item.DrugSpecUnit,
  5683. PrescribingNumber: item.PrescribingNumber,
  5684. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5685. DeliveryWay: item.DeliveryWay,
  5686. ExecutionFrequency: item.ExecutionFrequency,
  5687. AdviceDoctor: item.AdviceDoctor,
  5688. Status: 1,
  5689. CreatedTime: item.CreatedTime,
  5690. UpdatedTime: item.UpdatedTime,
  5691. AdviceAffirm: item.AdviceAffirm,
  5692. Remark: item.Remark,
  5693. StopTime: item.StopTime,
  5694. StopReason: item.StopReason,
  5695. StopDoctor: item.StopDoctor,
  5696. StopState: item.StopState,
  5697. ParentId: item.ParentId,
  5698. ExecutionTime: item.ExecutionTime,
  5699. ExecutionStaff: creater,
  5700. ExecutionState: item.ExecutionState,
  5701. Checker: item.Checker,
  5702. RecordDate: item.RecordDate,
  5703. DialysisOrderId: item.DialysisOrderId,
  5704. CheckTime: item.CheckTime,
  5705. CheckState: item.CheckState,
  5706. RemindType: item.RemindType,
  5707. FrequencyType: item.FrequencyType,
  5708. DayCount: item.DayCount,
  5709. WeekDay: item.WeekDay,
  5710. TemplateId: item.TemplateId,
  5711. Modifier: item.Modifier,
  5712. Way: item.Way,
  5713. DrugId: item.DrugId,
  5714. ExecutionFrequencyId: item.ExecutionFrequencyId,
  5715. }
  5716. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5717. if medical.IsUse == 2 {
  5718. if config.IsOpen != 1 {
  5719. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5720. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5721. }
  5722. //不通过药房发药
  5723. if pharmacyConfig.IsOpen != 1 {
  5724. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5725. }
  5726. //查询默认仓库
  5727. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5728. //查询默认仓库剩余多少库存
  5729. var sum_count int64
  5730. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5731. for _, its := range stockInfo {
  5732. if its.MaxUnit == medical.MaxUnit {
  5733. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5734. }
  5735. sum_count += its.StockMaxNumber + its.StockMinNumber
  5736. }
  5737. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5738. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5739. }
  5740. }
  5741. info := models.HisDoctorAdviceInfo{
  5742. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5743. ExecutionTime: exec_time,
  5744. ExecutionState: 1,
  5745. UpdatedTime: time.Now().Unix(),
  5746. }
  5747. //执行医嘱
  5748. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  5749. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5750. redis := service.RedisClient()
  5751. //清空key 值
  5752. redis.Set(key, "", time.Second)
  5753. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5754. redis.Set(keyTwo, "", time.Second)
  5755. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5756. redis.Set(keyThree, "", time.Second)
  5757. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5758. theTime := toTime.Format("2006-01-02")
  5759. fmt.Println("theTIME", theTime)
  5760. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5761. redis.Set(keyFour, "", time.Second)
  5762. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5763. redis.Set(keyFive, "", time.Second)
  5764. }
  5765. } else {
  5766. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  5767. //查找未执行医嘱
  5768. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5769. for _, item := range groupList {
  5770. for _, it := range list {
  5771. if item.DrugId == it.DrugId {
  5772. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5773. }
  5774. }
  5775. }
  5776. for _, item := range groupList {
  5777. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5778. var sum_out_count int64
  5779. for _, it := range item.ChildDoctorAdvice {
  5780. var prescribing_number int64
  5781. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5782. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5783. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5784. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5785. }
  5786. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5787. prescribing_number = parseIntPrescribingNumber
  5788. }
  5789. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5790. prescribing_number = parseIntPrescribingNumber
  5791. }
  5792. sum_out_count += prescribing_number
  5793. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5794. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5795. //库存不足
  5796. if sum_out_count > drugStockOut.FlushCount {
  5797. this.ServeSuccessJSON(map[string]interface{}{
  5798. "msg": "2",
  5799. "drug": medical,
  5800. })
  5801. return
  5802. }
  5803. }
  5804. }
  5805. for _, item := range list {
  5806. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5807. dadvice := &models.DoctorAdvice{
  5808. ID: item.ID,
  5809. UserOrgId: item.UserOrgId,
  5810. PatientId: item.PatientId,
  5811. AdviceType: item.AdviceType,
  5812. AdviceDate: item.AdviceDate,
  5813. StartTime: item.StartTime,
  5814. AdviceName: item.AdviceName,
  5815. AdviceDesc: item.AdviceDesc,
  5816. ReminderDate: item.ReminderDate,
  5817. SingleDose: item.SingleDose,
  5818. SingleDoseUnit: item.SingleDoseUnit,
  5819. DrugSpec: item.DrugSpec,
  5820. DrugSpecUnit: item.DrugSpecUnit,
  5821. PrescribingNumber: item.PrescribingNumber,
  5822. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5823. DeliveryWay: item.DeliveryWay,
  5824. ExecutionFrequency: item.ExecutionFrequency,
  5825. AdviceDoctor: item.AdviceDoctor,
  5826. Status: 1,
  5827. CreatedTime: item.CreatedTime,
  5828. UpdatedTime: item.UpdatedTime,
  5829. AdviceAffirm: item.AdviceAffirm,
  5830. Remark: item.Remark,
  5831. StopTime: item.StopTime,
  5832. StopReason: item.StopReason,
  5833. StopDoctor: item.StopDoctor,
  5834. StopState: item.StopState,
  5835. ParentId: item.ParentId,
  5836. ExecutionTime: item.ExecutionTime,
  5837. ExecutionStaff: item.ExecutionStaff,
  5838. ExecutionState: item.ExecutionState,
  5839. Checker: item.Checker,
  5840. RecordDate: item.ReminderDate,
  5841. DialysisOrderId: item.DialysisOrderId,
  5842. CheckTime: item.CheckTime,
  5843. CheckState: item.CheckState,
  5844. RemindType: item.RemindType,
  5845. FrequencyType: item.FrequencyType,
  5846. DayCount: item.DayCount,
  5847. WeekDay: item.WeekDay,
  5848. TemplateId: item.TemplateId,
  5849. Modifier: item.Modifier,
  5850. Way: item.Way,
  5851. DrugId: item.DrugId,
  5852. }
  5853. if medical.IsUse == 2 {
  5854. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5856. }
  5857. if pharmacyConfig.IsOpen != 1 {
  5858. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5859. }
  5860. //更新字典里面的库存
  5861. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5862. var sum_count int64
  5863. for _, its := range stockInfo {
  5864. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5865. if its.MaxUnit == baseDrug.MaxUnit {
  5866. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5867. }
  5868. sum_count += its.StockMaxNumber + its.StockMinNumber
  5869. }
  5870. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5871. //剩余库存
  5872. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5873. }
  5874. info := models.DoctorAdvice{
  5875. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5876. ExecutionTime: exec_time,
  5877. ExecutionState: 1,
  5878. UpdatedTime: time.Now().Unix(),
  5879. }
  5880. //执行医嘱
  5881. service.UpdateDoctorAdviceExecution(info, item.ID)
  5882. }
  5883. }
  5884. this.ServeSuccessJSON(map[string]interface{}{
  5885. "msg": "1",
  5886. })
  5887. return
  5888. }
  5889. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  5890. orgId := this.GetAdminUserInfo().CurrentOrgId
  5891. idsStr := this.GetString("str")
  5892. recordIDStrs := strings.Split(idsStr, ",")
  5893. start_time := this.GetString("advice_date")
  5894. timeLayout := "2006-01-02"
  5895. loc, _ := time.LoadLocation("Local")
  5896. var startTime int64
  5897. if len(start_time) > 0 {
  5898. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5899. if err != nil {
  5900. //fmt.Println(err)
  5901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5902. return
  5903. }
  5904. startTime = theTime.Unix()
  5905. }
  5906. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5907. if config.IsOpen == 1 {
  5908. creater := this.GetAdminUserInfo().AdminUser.Id
  5909. //查询未核对的医嘱
  5910. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5911. for _, item := range advicelist {
  5912. if item.ExecutionStaff == creater {
  5913. this.ServeSuccessJSON(map[string]interface{}{
  5914. "msg": "2",
  5915. "advice": item,
  5916. })
  5917. return
  5918. }
  5919. service.CheckHisDoctorAdvice(item.ID, creater)
  5920. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5921. redis := service.RedisClient()
  5922. //清空key 值
  5923. redis.Set(key, "", time.Second)
  5924. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5925. redis.Set(keyTwo, "", time.Second)
  5926. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5927. redis.Set(keyThree, "", time.Second)
  5928. theTime := time.Now()
  5929. recordDate := theTime.Format("2006-01-02")
  5930. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5931. redis.Set(keyFour, "", time.Second)
  5932. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5933. redis.Set(keyFive, "", time.Second)
  5934. }
  5935. } else {
  5936. //查询未核对的医嘱
  5937. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5938. creater := this.GetAdminUserInfo().AdminUser.Id
  5939. for _, item := range advicelist {
  5940. if item.ExecutionStaff == creater {
  5941. this.ServeSuccessJSON(map[string]interface{}{
  5942. "msg": "2",
  5943. "advice": item,
  5944. })
  5945. return
  5946. }
  5947. service.CheckDoctorAdvice(item.ID, creater)
  5948. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5949. redis := service.RedisClient()
  5950. //清空key 值
  5951. redis.Set(key, "", time.Second)
  5952. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5953. redis.Set(keyTwo, "", time.Second)
  5954. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5955. redis.Set(keyThree, "", time.Second)
  5956. theTime := time.Now()
  5957. recordDate := theTime.Format("2006-01-02")
  5958. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5959. redis.Set(keyFour, "", time.Second)
  5960. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5961. redis.Set(keyFive, "", time.Second)
  5962. }
  5963. }
  5964. this.ServeSuccessJSON(map[string]interface{}{
  5965. "msg": "1",
  5966. })
  5967. return
  5968. }
  5969. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5970. orgId := this.GetAdminUserInfo().CurrentOrgId
  5971. is_open, _ := this.GetInt64("is_open")
  5972. idsStr := this.GetString("str")
  5973. recordIDStrs := strings.Split(idsStr, ",")
  5974. start_time := this.GetString("advice_date")
  5975. timeLayout := "2006-01-02"
  5976. loc, _ := time.LoadLocation("Local")
  5977. var startTime int64
  5978. if len(start_time) > 0 {
  5979. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5980. if err != nil {
  5981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5982. return
  5983. }
  5984. startTime = theTime.Unix()
  5985. }
  5986. if is_open == 1 {
  5987. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5988. } else {
  5989. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5990. }
  5991. this.ServeSuccessJSON(map[string]interface{}{
  5992. "msg": "1",
  5993. })
  5994. return
  5995. }
  5996. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5997. advice_id, _ := this.GetInt64("advice_id")
  5998. start_time := this.GetString("advice_date")
  5999. orgId := this.GetAdminUserInfo().CurrentOrgId
  6000. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6001. exec_time, _ := this.GetInt64("exec_time")
  6002. //his医嘱
  6003. if config.IsOpen == 1 {
  6004. //查询医嘱
  6005. advice, _ := service.GetHisDocById(advice_id, orgId)
  6006. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  6007. this.ServeSuccessJSON(map[string]interface{}{
  6008. "msg": "3",
  6009. })
  6010. return
  6011. }
  6012. medical, _ := service.GetBaseDrugMedical(orgId)
  6013. var prescribing_number int64
  6014. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6015. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6016. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6017. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6018. }
  6019. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6020. prescribing_number = parseIntPrescribingNumber
  6021. }
  6022. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6023. prescribing_number = parseIntPrescribingNumber
  6024. }
  6025. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6026. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6027. //库存不足
  6028. if prescribing_number > drugStockOut.FlushCount {
  6029. this.ServeSuccessJSON(map[string]interface{}{
  6030. "msg": "2",
  6031. "drug": medical,
  6032. })
  6033. return
  6034. }
  6035. info := models.HisDoctorAdviceInfo{
  6036. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6037. ExecutionTime: exec_time,
  6038. ExecutionState: 1,
  6039. UpdatedTime: time.Now().Unix(),
  6040. }
  6041. //执行医嘱
  6042. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  6043. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  6044. redis := service.RedisClient()
  6045. //清空key 值
  6046. redis.Set(key, "", time.Second)
  6047. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  6048. redis.Set(keyTwo, "", time.Second)
  6049. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6050. redis.Set(keyThree, "", time.Second)
  6051. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6052. theTime := toTime.Format("2006-01-02")
  6053. fmt.Println("theTIME", theTime)
  6054. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6055. redis.Set(keyFour, "", time.Second)
  6056. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6057. redis.Set(keyFive, "", time.Second)
  6058. //出库
  6059. if prescribing_number <= drugStockOut.FlushCount {
  6060. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6061. //执行出库逻辑
  6062. hisadvice := &models.HisDoctorAdviceInfo{
  6063. ID: advice.ID,
  6064. UserOrgId: advice.UserOrgId,
  6065. PatientId: advice.PatientId,
  6066. AdviceType: advice.AdviceType,
  6067. AdviceDate: advice.AdviceDate,
  6068. StartTime: advice.StartTime,
  6069. AdviceName: advice.AdviceName,
  6070. AdviceDesc: advice.AdviceDesc,
  6071. ReminderDate: advice.ReminderDate,
  6072. SingleDose: advice.SingleDose,
  6073. SingleDoseUnit: advice.SingleDoseUnit,
  6074. DrugSpec: advice.DrugSpec,
  6075. DrugSpecUnit: advice.DrugSpecUnit,
  6076. PrescribingNumber: advice.PrescribingNumber,
  6077. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6078. DeliveryWay: advice.DeliveryWay,
  6079. ExecutionFrequency: advice.ExecutionFrequency,
  6080. AdviceDoctor: advice.AdviceDoctor,
  6081. Status: 1,
  6082. CreatedTime: advice.CreatedTime,
  6083. UpdatedTime: advice.UpdatedTime,
  6084. AdviceAffirm: advice.AdviceAffirm,
  6085. Remark: advice.Remark,
  6086. StopTime: advice.StopTime,
  6087. StopReason: advice.StopReason,
  6088. StopDoctor: advice.StopDoctor,
  6089. StopState: advice.StopState,
  6090. ParentId: advice.ParentId,
  6091. ExecutionTime: advice.ExecutionTime,
  6092. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6093. ExecutionState: advice.ExecutionState,
  6094. Checker: advice.Checker,
  6095. RecordDate: advice.RecordDate,
  6096. DialysisOrderId: advice.DialysisOrderId,
  6097. CheckTime: advice.CheckTime,
  6098. CheckState: advice.CheckState,
  6099. RemindType: advice.RemindType,
  6100. FrequencyType: advice.FrequencyType,
  6101. DayCount: advice.DayCount,
  6102. WeekDay: advice.WeekDay,
  6103. TemplateId: advice.TemplateId,
  6104. Modifier: advice.Modifier,
  6105. Way: advice.Way,
  6106. DrugId: advice.DrugId,
  6107. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  6108. }
  6109. if medical.IsUse == 2 {
  6110. if config.IsOpen != 1 {
  6111. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6112. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6113. }
  6114. //不通过药房发药
  6115. if pharmacyConfig.IsOpen != 1 {
  6116. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6117. }
  6118. //查询默认仓库
  6119. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  6120. //查询默认仓库剩余多少库存
  6121. var sum_count int64
  6122. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6123. for _, its := range stockInfo {
  6124. if its.MaxUnit == medical.MaxUnit {
  6125. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6126. }
  6127. sum_count += its.StockMaxNumber + its.StockMinNumber
  6128. }
  6129. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6130. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6131. }
  6132. }
  6133. }
  6134. this.ServeSuccessJSON(map[string]interface{}{
  6135. "msg": "1",
  6136. })
  6137. return
  6138. }
  6139. if config.IsOpen == 2 || config.IsOpen == 0 {
  6140. advice, _ := service.GetBloodDocById(advice_id, orgId)
  6141. medical, _ := service.GetBaseDrugMedical(orgId)
  6142. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6143. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6144. var prescribing_number int64
  6145. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6146. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6147. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6148. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6149. }
  6150. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6151. prescribing_number = parseIntPrescribingNumber
  6152. }
  6153. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6154. prescribing_number = parseIntPrescribingNumber
  6155. }
  6156. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6157. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6158. //库存不足
  6159. if prescribing_number > drugStockOut.FlushCount {
  6160. this.ServeSuccessJSON(map[string]interface{}{
  6161. "msg": "2",
  6162. "drug": medical,
  6163. })
  6164. return
  6165. }
  6166. info := models.DoctorAdvice{
  6167. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6168. ExecutionTime: exec_time,
  6169. ExecutionState: 1,
  6170. UpdatedTime: time.Now().Unix(),
  6171. }
  6172. //执行医嘱
  6173. service.UpdateDoctorAdviceExecution(info, advice.ID)
  6174. dadvice := &models.DoctorAdvice{
  6175. ID: advice.ID,
  6176. UserOrgId: advice.UserOrgId,
  6177. PatientId: advice.PatientId,
  6178. AdviceType: advice.AdviceType,
  6179. AdviceDate: advice.AdviceDate,
  6180. StartTime: advice.StartTime,
  6181. AdviceName: advice.AdviceName,
  6182. AdviceDesc: advice.AdviceDesc,
  6183. ReminderDate: advice.ReminderDate,
  6184. SingleDose: advice.SingleDose,
  6185. SingleDoseUnit: advice.SingleDoseUnit,
  6186. DrugSpec: advice.DrugSpec,
  6187. DrugSpecUnit: advice.DrugSpecUnit,
  6188. PrescribingNumber: advice.PrescribingNumber,
  6189. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6190. DeliveryWay: advice.DeliveryWay,
  6191. ExecutionFrequency: advice.ExecutionFrequency,
  6192. AdviceDoctor: advice.AdviceDoctor,
  6193. Status: 1,
  6194. CreatedTime: advice.CreatedTime,
  6195. UpdatedTime: advice.UpdatedTime,
  6196. AdviceAffirm: advice.AdviceAffirm,
  6197. Remark: advice.Remark,
  6198. StopTime: advice.StopTime,
  6199. StopReason: advice.StopReason,
  6200. StopDoctor: advice.StopDoctor,
  6201. StopState: advice.StopState,
  6202. ParentId: advice.ParentId,
  6203. ExecutionTime: advice.ExecutionTime,
  6204. ExecutionStaff: advice.ExecutionStaff,
  6205. ExecutionState: advice.ExecutionState,
  6206. Checker: advice.Checker,
  6207. RecordDate: advice.ReminderDate,
  6208. DialysisOrderId: advice.DialysisOrderId,
  6209. CheckTime: advice.CheckTime,
  6210. CheckState: advice.CheckState,
  6211. RemindType: advice.RemindType,
  6212. FrequencyType: advice.FrequencyType,
  6213. DayCount: advice.DayCount,
  6214. WeekDay: advice.WeekDay,
  6215. TemplateId: advice.TemplateId,
  6216. Modifier: advice.Modifier,
  6217. Way: advice.Way,
  6218. DrugId: advice.DrugId,
  6219. }
  6220. if medical.IsUse == 2 {
  6221. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6222. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6223. }
  6224. if pharmacyConfig.IsOpen != 1 {
  6225. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6226. }
  6227. //更新字典里面的库存
  6228. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6229. var sum_count int64
  6230. for _, its := range stockInfo {
  6231. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6232. if its.MaxUnit == baseDrug.MaxUnit {
  6233. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6234. }
  6235. sum_count += its.StockMaxNumber + its.StockMinNumber
  6236. }
  6237. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6238. //剩余库存
  6239. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6240. }
  6241. }
  6242. this.ServeSuccessJSON(map[string]interface{}{
  6243. "msg": "1",
  6244. })
  6245. return
  6246. }
  6247. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6248. orgId := this.GetAdminUserInfo().CurrentOrgId
  6249. schedule_type, _ := this.GetInt64("schedule_type")
  6250. //partion_type, _ := this.GetInt64("partion_type")
  6251. partion_type := this.GetString("partion_type")
  6252. var ids []string
  6253. ids = strings.Split(partion_type, ",")
  6254. start_time := this.GetString("selected_date")
  6255. timeLayout := "2006-01-02"
  6256. loc, _ := time.LoadLocation("Local")
  6257. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6258. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6259. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6260. _, config := service.FindXTHisRecordByOrgId(orgId)
  6261. appId := this.GetAdminUserInfo().CurrentAppId
  6262. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6263. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6264. if err == nil {
  6265. this.ServeSuccessJSON(map[string]interface{}{
  6266. "list": list,
  6267. "drug": drug,
  6268. "config": config,
  6269. "doctorList": doctorList,
  6270. "manufacturerList": manufacturerList,
  6271. })
  6272. return
  6273. } else {
  6274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6275. return
  6276. }
  6277. }
  6278. func (this *DialysisApiController) GetDialysisProject() {
  6279. orgId := this.GetAdminUserInfo().CurrentOrgId
  6280. schedule_type, _ := this.GetInt64("schedule_type")
  6281. partion_type := this.GetString("partion_type")
  6282. var ids []string
  6283. ids = strings.Split(partion_type, ",")
  6284. start_time := this.GetString("selected_date")
  6285. timeLayout := "2006-01-02"
  6286. loc, _ := time.LoadLocation("Local")
  6287. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6288. list, err := service.GetDialysisProjectSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6289. if err == nil {
  6290. this.ServeSuccessJSON(map[string]interface{}{
  6291. "list": list,
  6292. })
  6293. return
  6294. } else {
  6295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6296. return
  6297. }
  6298. }
  6299. func (this *DialysisApiController) GetMobileScheduleList() {
  6300. orgId := this.GetAdminUserInfo().CurrentOrgId
  6301. schedule, _ := service.GetMobileScheduleList(orgId)
  6302. if len(schedule) > 0 {
  6303. for _, its := range schedule {
  6304. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6305. //its.DialysisPrescription = prescription
  6306. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6307. //its.MonitoringRecord = monitor
  6308. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6309. //its.XtAssessmentAfterDislysis = after
  6310. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6311. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6312. }
  6313. }
  6314. this.ServeSuccessJSON(map[string]interface{}{
  6315. "schedule": schedule,
  6316. })
  6317. return
  6318. }
  6319. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6320. week_day, _ := this.GetInt64("week_day")
  6321. orgId := this.GetAdminUserInfo().CurrentOrgId
  6322. informaitonSetting := models.XtDialysisInformaitonSetting{
  6323. WeekDay: week_day,
  6324. UserOrgId: orgId,
  6325. Status: 1,
  6326. Ctime: time.Now().Unix(),
  6327. Mtime: 0,
  6328. }
  6329. information, _ := service.GetInformationSettingByOrgId(orgId)
  6330. if information.ID == 0 {
  6331. service.CreateInformationSetting(informaitonSetting)
  6332. }
  6333. if information.ID > 0 {
  6334. service.UpdateInformationSettingById(orgId, week_day)
  6335. }
  6336. this.ServeSuccessJSON(map[string]interface{}{
  6337. "informaitonSetting": informaitonSetting,
  6338. })
  6339. return
  6340. }
  6341. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6342. orgId := this.GetAdminUserInfo().CurrentOrgId
  6343. limit, _ := this.GetInt64("limit")
  6344. page, _ := this.GetInt64("page")
  6345. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6346. //未审核
  6347. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6348. //全部
  6349. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6350. patients, _ := service.GetAllpatientThirty(orgId)
  6351. appId := this.GetAdminUserInfo().CurrentAppId
  6352. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6353. this.ServeSuccessJSON(map[string]interface{}{
  6354. "informaitonSetting": informationSetting,
  6355. "infor": infor,
  6356. "total": total,
  6357. "totalOne": totalOne,
  6358. "inforList": inforList,
  6359. "patients": patients,
  6360. "adminList": role,
  6361. })
  6362. return
  6363. }
  6364. func (this *DialysisApiController) CheckDialysisInformation() {
  6365. id, _ := this.GetInt64("id")
  6366. application_status, _ := this.GetInt64("application_status")
  6367. timeNow := time.Now().Unix()
  6368. checker := this.GetAdminUserInfo().AdminUser.Id
  6369. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6370. this.ServeSuccessJSON(map[string]interface{}{
  6371. "information": information,
  6372. })
  6373. return
  6374. }
  6375. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6376. page, _ := this.GetInt64("page", 1)
  6377. limit, _ := this.GetInt64("limit", 10)
  6378. schedulType, _ := this.GetInt64("schedul_type", 0)
  6379. startTime, _ := this.GetInt64("schedul_time", 0)
  6380. partitionType, _ := this.GetInt64("partition_type", 0)
  6381. keywords := this.GetString("keywords")
  6382. start_time, _ := this.GetInt64("start_time")
  6383. end_time, _ := this.GetInt64("end_time")
  6384. adminUserInfo := this.GetAdminUserInfo()
  6385. if len(keywords) > 0 {
  6386. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6387. if err == nil {
  6388. this.ServeSuccessJSON(map[string]interface{}{
  6389. "schedule": dialysisSchedule,
  6390. "total": total,
  6391. })
  6392. } else {
  6393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6394. }
  6395. } else {
  6396. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6397. if err == nil {
  6398. this.ServeSuccessJSON(map[string]interface{}{
  6399. "schedule": dialysisSchedule,
  6400. "total": total,
  6401. })
  6402. } else {
  6403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6404. }
  6405. }
  6406. }
  6407. func (this *DialysisApiController) SaveInformation() {
  6408. patient_id, _ := this.GetInt64("patient_id")
  6409. record_date, _ := this.GetInt64("record_date")
  6410. startTime := this.GetString("selected_date")
  6411. timeLayout := "2006-01-02 15:04"
  6412. loc, _ := time.LoadLocation("Local")
  6413. if len(startTime) == 0 {
  6414. utils.ErrorLog("len(start_time) == 0")
  6415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6416. return
  6417. }
  6418. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6419. if err != nil {
  6420. utils.ErrorLog(err.Error())
  6421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6422. return
  6423. }
  6424. StartTime := theTime.Unix()
  6425. fmt.Println("startime-------------", StartTime)
  6426. module, _ := this.GetInt64("module")
  6427. remark := this.GetString("remark")
  6428. orgId := this.GetAdminUserInfo().CurrentOrgId
  6429. creater := this.GetAdminUserInfo().AdminUser.Id
  6430. information := models.XtDialysisInformation{
  6431. Module: module,
  6432. PatientId: patient_id,
  6433. RecordDate: record_date,
  6434. ApplicationDate: StartTime,
  6435. Creater: creater,
  6436. ApplicationStatus: 2,
  6437. Checker: 0,
  6438. CheckTime: 0,
  6439. Remark: remark,
  6440. UserOrgId: orgId,
  6441. Ctime: time.Now().Unix(),
  6442. Status: 1,
  6443. Mtime: 0,
  6444. }
  6445. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6446. if infor.ID == 0 {
  6447. err := service.CreatedDialysisInformation(information)
  6448. if err == nil {
  6449. this.ServeSuccessJSON(map[string]interface{}{
  6450. "information": information,
  6451. })
  6452. return
  6453. }
  6454. }
  6455. if infor.ID > 0 {
  6456. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6457. if err == nil {
  6458. this.ServeSuccessJSON(map[string]interface{}{
  6459. "information": information,
  6460. })
  6461. return
  6462. }
  6463. }
  6464. }
  6465. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6466. orgId := this.GetAdminUserInfo().CurrentOrgId
  6467. schedule_type, _ := this.GetInt64("schedule_type")
  6468. partion_type := this.GetString("partion_type")
  6469. var ids []string
  6470. ids = strings.Split(partion_type, ",")
  6471. start_time := this.GetString("selected_date")
  6472. timeLayout := "2006-01-02"
  6473. loc, _ := time.LoadLocation("Local")
  6474. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6475. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6476. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6477. _, config := service.FindXTHisRecordByOrgId(orgId)
  6478. appId := this.GetAdminUserInfo().CurrentAppId
  6479. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6480. if err == nil {
  6481. this.ServeSuccessJSON(map[string]interface{}{
  6482. "list": list,
  6483. "drug": drug,
  6484. "config": config,
  6485. "doctorList": doctorList,
  6486. })
  6487. return
  6488. } else {
  6489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6490. return
  6491. }
  6492. }
  6493. func (this *DialysisApiController) GetPatientList() {
  6494. orgId := this.GetAdminUserInfo().CurrentOrgId
  6495. keyWord := this.GetString("keyword")
  6496. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  6497. if err == nil {
  6498. this.ServeSuccessJSON(map[string]interface{}{
  6499. "patientList": patientList,
  6500. })
  6501. return
  6502. } else {
  6503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6504. return
  6505. }
  6506. }
  6507. func (this *DialysisApiController) GetPrescriptionLogList() {
  6508. patient_id, _ := this.GetInt64("patient_id")
  6509. record_date := this.GetString("record_date")
  6510. page, _ := this.GetInt64("page")
  6511. limit, _ := this.GetInt64("limit")
  6512. orgId := this.GetAdminUserInfo().CurrentOrgId
  6513. timeLayout := "2006-01-02"
  6514. loc, _ := time.LoadLocation("Local")
  6515. var recordDateTime int64
  6516. if len(record_date) > 0 {
  6517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6518. if err != nil {
  6519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6520. return
  6521. }
  6522. recordDateTime = theTime.Unix()
  6523. }
  6524. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  6525. patients, _ := service.GetAllPatientLog(orgId)
  6526. role, _ := service.GetAllDoctorLog(orgId)
  6527. if err == nil {
  6528. this.ServeSuccessJSON(map[string]interface{}{
  6529. "prescriptionlogList": prescriptionlogList,
  6530. "total": total,
  6531. "patients": patients,
  6532. "role": role,
  6533. })
  6534. return
  6535. } else {
  6536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6537. return
  6538. }
  6539. }
  6540. func (this *DialysisApiController) GetBeforLogList() {
  6541. patient_id, _ := this.GetInt64("patient_id")
  6542. record_date := this.GetString("record_date")
  6543. page, _ := this.GetInt64("page")
  6544. limit, _ := this.GetInt64("limit")
  6545. orgId := this.GetAdminUserInfo().CurrentOrgId
  6546. timeLayout := "2006-01-02"
  6547. loc, _ := time.LoadLocation("Local")
  6548. var recordDateTime int64
  6549. if len(record_date) > 0 {
  6550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6551. if err != nil {
  6552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6553. return
  6554. }
  6555. recordDateTime = theTime.Unix()
  6556. }
  6557. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  6558. patients, _ := service.GetAllPatientLog(orgId)
  6559. role, _ := service.GetAllDoctorLog(orgId)
  6560. if err == nil {
  6561. this.ServeSuccessJSON(map[string]interface{}{
  6562. "beforLogList": beforLogList,
  6563. "total": total,
  6564. "patients": patients,
  6565. "role": role,
  6566. })
  6567. return
  6568. } else {
  6569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6570. return
  6571. }
  6572. }
  6573. func (this *DialysisApiController) GetDocLogList() {
  6574. patient_id, _ := this.GetInt64("patient_id")
  6575. record_date := this.GetString("record_date")
  6576. page, _ := this.GetInt64("page")
  6577. limit, _ := this.GetInt64("limit")
  6578. orgId := this.GetAdminUserInfo().CurrentOrgId
  6579. timeLayout := "2006-01-02"
  6580. loc, _ := time.LoadLocation("Local")
  6581. var recordDateTime int64
  6582. if len(record_date) > 0 {
  6583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6584. if err != nil {
  6585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6586. return
  6587. }
  6588. recordDateTime = theTime.Unix()
  6589. }
  6590. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  6591. patients, _ := service.GetAllPatientLog(orgId)
  6592. role, _ := service.GetAllDoctorLog(orgId)
  6593. if err == nil {
  6594. this.ServeSuccessJSON(map[string]interface{}{
  6595. "adviceLogList": adviceLogList,
  6596. "total": total,
  6597. "patients": patients,
  6598. "role": role,
  6599. })
  6600. return
  6601. } else {
  6602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6603. return
  6604. }
  6605. }
  6606. func (this *DialysisApiController) GetMonitorLogList() {
  6607. patient_id, _ := this.GetInt64("patient_id")
  6608. record_date := this.GetString("record_date")
  6609. page, _ := this.GetInt64("page")
  6610. limit, _ := this.GetInt64("limit")
  6611. orgId := this.GetAdminUserInfo().CurrentOrgId
  6612. timeLayout := "2006-01-02"
  6613. loc, _ := time.LoadLocation("Local")
  6614. var recordDateTime int64
  6615. if len(record_date) > 0 {
  6616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6617. if err != nil {
  6618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6619. return
  6620. }
  6621. recordDateTime = theTime.Unix()
  6622. }
  6623. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  6624. patients, _ := service.GetAllPatientLog(orgId)
  6625. role, _ := service.GetAllDoctorLog(orgId)
  6626. if err == nil {
  6627. this.ServeSuccessJSON(map[string]interface{}{
  6628. "monitorLogList": monitorLogList,
  6629. "total": total,
  6630. "patients": patients,
  6631. "role": role,
  6632. })
  6633. return
  6634. } else {
  6635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6636. return
  6637. }
  6638. }
  6639. func (this *DialysisApiController) GetAfterLogList() {
  6640. patient_id, _ := this.GetInt64("patient_id")
  6641. record_date := this.GetString("record_date")
  6642. page, _ := this.GetInt64("page")
  6643. limit, _ := this.GetInt64("limit")
  6644. orgId := this.GetAdminUserInfo().CurrentOrgId
  6645. timeLayout := "2006-01-02"
  6646. loc, _ := time.LoadLocation("Local")
  6647. var recordDateTime int64
  6648. if len(record_date) > 0 {
  6649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6650. if err != nil {
  6651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6652. return
  6653. }
  6654. recordDateTime = theTime.Unix()
  6655. }
  6656. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  6657. patients, _ := service.GetAllPatientLog(orgId)
  6658. role, _ := service.GetAllDoctorLog(orgId)
  6659. if err == nil {
  6660. this.ServeSuccessJSON(map[string]interface{}{
  6661. "afterLogList": afterLogList,
  6662. "total": total,
  6663. "patients": patients,
  6664. "role": role,
  6665. })
  6666. return
  6667. } else {
  6668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6669. return
  6670. }
  6671. }
  6672. func (this *DialysisApiController) SaveGatherSetting() {
  6673. orgId := this.GetAdminUserInfo().CurrentOrgId
  6674. is_index_number, _ := this.GetInt64("is_index_number")
  6675. fmt.Println("this,23o2332232323232332", is_index_number)
  6676. is_zone, _ := this.GetInt64("is_zone")
  6677. is_number, _ := this.GetInt64("is_number")
  6678. is_birth, _ := this.GetInt64("is_birth")
  6679. is_age, _ := this.GetInt64("is_age")
  6680. is_name, _ := this.GetInt64("is_name")
  6681. is_mode_type, _ := this.GetInt64("is_mode_type")
  6682. is_prescription_status, _ := this.GetInt64("is_prescription_status")
  6683. is_admission_number, _ := this.GetInt64("is_admission_number")
  6684. is_dialysis_no, _ := this.GetInt64("is_dialysis_no")
  6685. is_dry_weight, _ := this.GetInt64("is_dry_weight")
  6686. is_dialysis_dialyszers, _ := this.GetInt64("is_dialysis_dialyszers")
  6687. is_dialysis_strainer, _ := this.GetInt64("is_dialysis_strainer")
  6688. is_dialysis_irrigation, _ := this.GetInt64("is_dialysis_irrigation")
  6689. is_calcium, _ := this.GetInt64("is_calcium")
  6690. is_kalium, _ := this.GetInt64("is_kalium")
  6691. is_change_nurse, _ := this.GetInt64("is_change_nurse")
  6692. is_puncture_needle, _ := this.GetInt64("is_puncture_needle")
  6693. is_anticoagulant, _ := this.GetInt64("is_anticoagulant")
  6694. is_tube, _ := this.GetInt64("is_tube")
  6695. is_cuhong, _ := this.GetInt64("is_cuhong")
  6696. is_zuoka, _ := this.GetInt64("is_zuoka")
  6697. is_zhetangtie, _ := this.GetInt64("is_zhetangtie")
  6698. is_paligu, _ := this.GetInt64("is_paligu")
  6699. is_guhuachun, _ := this.GetInt64("is_guhuachun")
  6700. is_niaojimei, _ := this.GetInt64("is_niaojimei")
  6701. is_putaosuangai, _ := this.GetInt64("is_putaosuangai")
  6702. is_jiaguan, _ := this.GetInt64("is_jiaguan")
  6703. is_xiongxiewutai, _ := this.GetInt64("is_xiongxiewutai")
  6704. gatherSetting := models.XtDialysisGatherSetting{
  6705. UserOrgId: orgId,
  6706. IndexNumber: is_index_number,
  6707. Zone: is_zone,
  6708. Number: is_number,
  6709. Birth: is_birth,
  6710. Name: is_name,
  6711. Age: is_age,
  6712. ModeType: is_mode_type,
  6713. PrescriptionStatus: is_prescription_status,
  6714. AdmissionNumber: is_admission_number,
  6715. DialysisNo: is_dialysis_no,
  6716. DryWeight: is_dry_weight,
  6717. DialysisDialyszers: is_dialysis_dialyszers,
  6718. DialysisStrainer: is_dialysis_strainer,
  6719. DialysisIrrigation: is_dialysis_irrigation,
  6720. Calcium: is_calcium,
  6721. Kalium: is_kalium,
  6722. ChangeNurse: is_change_nurse,
  6723. PunctureNeedle: is_puncture_needle,
  6724. Anticoagulant: is_anticoagulant,
  6725. Tube: is_tube,
  6726. Cuhong: is_cuhong,
  6727. Zuoka: is_zuoka,
  6728. Zhetangtie: is_zhetangtie,
  6729. Paligu: is_paligu,
  6730. Guhuachun: is_guhuachun,
  6731. Niaojimei: is_niaojimei,
  6732. Putaosuangai: is_putaosuangai,
  6733. Jiaguan: is_jiaguan,
  6734. Xiongxiewutai: is_xiongxiewutai,
  6735. Ctime: time.Now().Unix(),
  6736. Mtime: time.Now().Unix(),
  6737. Status: 1,
  6738. }
  6739. //查询该机构有没有设置
  6740. gatherSettingOne, _ := service.GetGatherSettingByOrgId(orgId)
  6741. if gatherSettingOne.ID == 0 {
  6742. service.CreateGather(gatherSetting)
  6743. } else {
  6744. gatherSetting.ID = gatherSettingOne.ID
  6745. service.SaveGather(gatherSetting)
  6746. }
  6747. this.ServeSuccessJSON(map[string]interface{}{
  6748. "gatherSetting": gatherSetting,
  6749. })
  6750. return
  6751. }
  6752. func (this *DialysisApiController) GetGatherSetting() {
  6753. orgId := this.GetAdminUserInfo().CurrentOrgId
  6754. gatherSetting, _ := service.GetGatherSetting(orgId)
  6755. this.ServeSuccessJSON(map[string]interface{}{
  6756. "gatherSetting": gatherSetting,
  6757. })
  6758. return
  6759. }
  6760. func (this *DialysisApiController) GetDialysisGatherList() {
  6761. keyword := this.GetString("keywords")
  6762. limit, _ := this.GetInt64("limit")
  6763. page, _ := this.GetInt64("page")
  6764. partion_type := this.GetString("partition_id")
  6765. idSplit := strings.Split(partion_type, ",")
  6766. schedule_type, _ := this.GetInt64("schedule_type")
  6767. start_time := this.GetString("schedule_date")
  6768. timeLayout := "2006-01-02"
  6769. loc, _ := time.LoadLocation("Local")
  6770. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6771. orgId := this.GetAdminUserInfo().CurrentOrgId
  6772. scheduids := this.GetString("ids")
  6773. var ids []string
  6774. if scheduids != "" {
  6775. ids = strings.Split(scheduids, ",")
  6776. }
  6777. list, total, _ := service.GetDialysisGatherList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  6778. gatherSetting, _ := service.GetGatherSetting(orgId)
  6779. this.ServeSuccessJSON(map[string]interface{}{
  6780. "list": list,
  6781. "total": total,
  6782. "gatherSetting": gatherSetting,
  6783. })
  6784. return
  6785. }
  6786. func (this *DialysisApiController) GetPatientDialysisRecordList() {
  6787. patient_id, _ := this.GetInt64("patient_id")
  6788. timeLayout := "2006-01-02"
  6789. loc, _ := time.LoadLocation("Local")
  6790. start_time := this.GetString("start_time")
  6791. end_time := this.GetString("end_time")
  6792. var startdateunix int64
  6793. if len(start_time) > 0 {
  6794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6795. if err != nil {
  6796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6797. return
  6798. }
  6799. startdateunix = theTime.Unix()
  6800. }
  6801. var enddateunix int64
  6802. if len(end_time) > 0 {
  6803. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6804. if err != nil {
  6805. utils.ErrorLog(err.Error())
  6806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6807. return
  6808. }
  6809. enddateunix = theTime.Unix()
  6810. }
  6811. org_id := this.GetAdminUserInfo().CurrentOrgId
  6812. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  6813. list, _ := service.GetPatientDialysisRecordList(patient_id, startdateunix, enddateunix)
  6814. this.ServeSuccessJSON(map[string]interface{}{
  6815. "list": list,
  6816. })
  6817. return
  6818. } else {
  6819. list, _ := service.GetPatientDialysisRecordListOne(patient_id, startdateunix, enddateunix)
  6820. this.ServeSuccessJSON(map[string]interface{}{
  6821. "list": list,
  6822. })
  6823. }
  6824. return
  6825. }
  6826. func (this *DialysisApiController) GetPatientRecordList() {
  6827. patient_id, _ := this.GetInt64("patient_id")
  6828. orgId := this.GetAdminUserInfo().CurrentOrgId
  6829. beforList, _ := service.GetPatientBeforRecordList(patient_id, orgId)
  6830. afterList, _ := service.GetPatientAfterRecordList(patient_id, orgId)
  6831. monitorList, _ := service.GetMonitorRecordByGroup(patient_id, orgId)
  6832. this.ServeSuccessJSON(map[string]interface{}{
  6833. "beforList": beforList,
  6834. "afterList": afterList,
  6835. "monitorList": monitorList,
  6836. })
  6837. }
  6838. func (this *DialysisApiController) GetDialysisTotalCount() {
  6839. timeLayout := "2006-01-02"
  6840. loc, _ := time.LoadLocation("Local")
  6841. start_time := this.GetString("start_time")
  6842. end_time := this.GetString("end_time")
  6843. patient_id, _ := this.GetInt64("patient_id")
  6844. var startdateunix int64
  6845. if len(start_time) > 0 {
  6846. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6847. if err != nil {
  6848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6849. return
  6850. }
  6851. startdateunix = theTime.Unix()
  6852. }
  6853. var enddateunix int64
  6854. if len(end_time) > 0 {
  6855. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6856. if err != nil {
  6857. utils.ErrorLog(err.Error())
  6858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6859. return
  6860. }
  6861. enddateunix = theTime.Unix()
  6862. }
  6863. orgId := this.GetAdminUserInfo().CurrentOrgId
  6864. order, _ := service.GetDialysisTotalCountByTime(orgId, startdateunix, enddateunix, patient_id)
  6865. this.ServeSuccessJSON(map[string]interface{}{
  6866. "order": order,
  6867. })
  6868. }