dialysis_api_controller.go 441KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. if id <= 0 {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. adminUserInfo := c.GetMobileAdminUserInfo()
  1327. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1328. if patient.ID == 0 {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1330. return
  1331. }
  1332. if len(recordDateStr) == 0 {
  1333. recordDateStr = time.Now().Format("2006-01-02")
  1334. }
  1335. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1336. fmt.Println("parseDateErr", parseDateErr)
  1337. if parseDateErr != nil {
  1338. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. //now := time.Now()
  1343. //year, month, day := now.Date()
  1344. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1345. //todayTimeStamp := today_time.Unix()
  1346. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1347. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1348. UserOrgId: adminUserInfo.Org.Id,
  1349. PatientId: id,
  1350. AssessmentDate: recordDate.Unix(),
  1351. Temperature: temperature,
  1352. PulseFrequency: pulse_frequency,
  1353. BreathingRate: breathing_rate,
  1354. SystolicBloodPressure: systolic_blood_pressure,
  1355. DiastolicBloodPressure: diastolic_blood_pressure,
  1356. ActualUltrafiltration: actual_ultrafiltration,
  1357. ActualDisplacement: actual_displacement,
  1358. ActualTreatmentHour: actualtreatHour,
  1359. ActualTreatmentMinute: actualtreatmin,
  1360. WeightAfter: weightAfter,
  1361. AdditionalWeight: additionalWeight,
  1362. WeightLoss: weightReduce,
  1363. Cruor: cruor,
  1364. SymptomAfterDialysis: symptomsAfterDialysi,
  1365. InternalFistula: internalFistula,
  1366. Catheter: catheter,
  1367. Complication: complications,
  1368. DialysisIntakes: dialysateVolume,
  1369. CreatedTime: time.Now().Unix(),
  1370. UpdatedTime: time.Now().Unix(),
  1371. Status: 1,
  1372. Remark: remark,
  1373. BloodAccessPartId: blood_access_part_id,
  1374. BloodAccessPartOperaId: blood_access_part_opera_id,
  1375. DialysisIntakesUnit: dialysis_intakes_unit,
  1376. PuncturePointOozingBlood: puncturePointOozingBlood,
  1377. PuncturePointHaematoma: puncturePointHaematoma,
  1378. InternalFistulaTremorAc: internalFistulaTremorAc,
  1379. PatientGose: patientGose,
  1380. InpatientDepartment: inpatientDepartment,
  1381. ObservationContent: observationContent,
  1382. ObservationContentOther: observationContentOther,
  1383. DialysisProcess: dialysis_process,
  1384. InAdvanceMinute: in_advance_minute,
  1385. InAdvanceReason: in_advance_reason,
  1386. HemostasisMinute: hemostasis_minute,
  1387. HemostasisOpera: hemostasis_opera,
  1388. TremorNoise: tremor_noise,
  1389. DisequilibriumSyndrome: disequilibrium_syndrome,
  1390. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1391. ArterialTube: arterial_tube,
  1392. IntravenousTube: intravenous_tube,
  1393. Dialyzer: dialyzer,
  1394. InAdvanceReasonOther: in_advance_reason_other,
  1395. IsEat: is_eat,
  1396. CvcA: cvc_a,
  1397. CvcV: cvc_v,
  1398. Channel: channels,
  1399. ReturnBlood: return_blood,
  1400. RehydrationVolume: rehydration_volume,
  1401. DialysisDuring: dialysis_during,
  1402. StrokeVolume: stroke_volume,
  1403. BloodFlow: blood_flow,
  1404. SealingFluidDispose: sealing_fluid_dispose,
  1405. SealingFluidSpecial: sealing_fluid_special,
  1406. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1407. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1408. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1409. SettingPressure: setting_pressure,
  1410. DiastolicPressure: diastolic_pressure,
  1411. OtherComplication: other_complication,
  1412. Ktv: ktv,
  1413. Urr: urr,
  1414. Hypopiesia: hypopiesia,
  1415. Hypertenison: hypertenison,
  1416. Lapse: lapse,
  1417. LeaveOfficeMethod: leave_office_method,
  1418. Consciousness: consciousness,
  1419. Fallrisk: fallrisk,
  1420. MachineRun: machine_run,
  1421. AfterUrea: after_urea,
  1422. PipCoagulation: pip_coagulation,
  1423. AccumulatedBloodVolume: accumulated_blood_volume,
  1424. TransfusionVolume: transfusion_volume,
  1425. LastAfterWeight: last_after_weight,
  1426. DisplaceLiquiValue: displace_liqui_value,
  1427. }
  1428. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1429. // 查询信息规挡的设置天数
  1430. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1431. if infor.ID > 0 && infor.WeekDay > 0 {
  1432. var cha_time int64
  1433. timeNowStr := time.Now().Format("2006-01-02")
  1434. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1435. //今日的日期减去设置的日期
  1436. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1437. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1438. if cha_time >= recordDate.Unix() {
  1439. //查询审核是否允许
  1440. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1441. //申请状态不允许的情况 拒绝修改
  1442. if infor.ApplicationStatus != 1 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1449. if assessmentAfter.ID == 0 { //新增
  1450. if appRole.UserType == 2 || appRole.UserType == 1 {
  1451. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1452. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1453. } else {
  1454. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1455. }
  1456. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1457. if assessmentAfterDislysis.UserOrgId != 10340 {
  1458. if assessmentAfterDislysis.WeightAfter == 0 {
  1459. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1460. }
  1461. }
  1462. if adminUserInfo.Org.Id == 10693 {
  1463. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1464. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1465. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1466. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1467. }
  1468. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1471. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1472. }
  1473. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.PulseFrequency == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1481. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1482. }
  1483. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1486. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1487. }
  1488. }
  1489. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1490. //记录日志
  1491. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1492. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1493. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1494. PatientId: assessmentAfterDislysis.PatientId,
  1495. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1496. Status: 1,
  1497. ErrLog: string(byterequest),
  1498. AdminUserId: adminUserInfo.AdminUser.Id,
  1499. Ctime: 0,
  1500. Mtime: 0,
  1501. Source: "手机端保存透后评估",
  1502. }
  1503. service.CreateAfterDialysisLog(afterDialysisLog)
  1504. finish := models.XtDialysisFinish{
  1505. IsFinish: 1,
  1506. UserOrgId: adminUserInfo.Org.Id,
  1507. Status: 1,
  1508. Ctime: time.Now().Unix(),
  1509. Mtime: 0,
  1510. Module: 9,
  1511. RecordDate: recordDate.Unix(),
  1512. Sourse: 1,
  1513. PatientId: id,
  1514. }
  1515. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1516. if dialysisFinish.ID == 0 {
  1517. service.CreateDialysisFinish(finish)
  1518. }
  1519. redis := service.RedisClient()
  1520. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1521. redis.Set(keyTwo, "", time.Second)
  1522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1523. //清空key 值
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1526. redis.Set(keyOne, "", time.Second)
  1527. defer redis.Close()
  1528. if err == nil {
  1529. c.ServeSuccessJSON(map[string]interface{}{
  1530. "assessmentAfterDislysis": assessmentAfterDislysis,
  1531. })
  1532. }
  1533. return
  1534. } else { //修改
  1535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1536. if infor.ID > 0 && infor.WeekDay > 0 {
  1537. var cha_time int64
  1538. timeNowStr := time.Now().Format("2006-01-02")
  1539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1540. //今日的日期减去设置的日期
  1541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1542. if cha_time >= recordDate.Unix() {
  1543. //查询审核是否允许
  1544. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1545. //申请状态不允许的情况 拒绝修改
  1546. if infor.ApplicationStatus != 1 {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. if appRole.UserType == 2 || appRole.UserType == 1 {
  1553. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1554. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1555. } else {
  1556. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1557. if assessmentAfterDislysis.Creater == 0 {
  1558. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1559. }
  1560. }
  1561. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1562. assessmentAfterDislysis.ID = assessmentAfter.ID
  1563. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1564. if assessmentAfterDislysis.UserOrgId != 10340 {
  1565. if assessmentAfterDislysis.WeightAfter == 0 {
  1566. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1567. }
  1568. }
  1569. if adminUserInfo.Org.Id == 10693 {
  1570. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1571. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1572. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1573. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1574. }
  1575. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1578. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1579. }
  1580. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.PulseFrequency == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1588. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1589. }
  1590. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1593. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1594. }
  1595. }
  1596. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1597. //记录日志
  1598. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1599. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1600. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1601. PatientId: assessmentAfterDislysis.PatientId,
  1602. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1603. Status: 1,
  1604. ErrLog: string(byterequest),
  1605. AdminUserId: adminUserInfo.AdminUser.Id,
  1606. Ctime: time.Now().Unix(),
  1607. Mtime: 0,
  1608. Source: "手机端修改保存透后评估",
  1609. }
  1610. service.CreateAfterDialysisLog(afterDialysisLog)
  1611. redis := service.RedisClient()
  1612. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1613. redis.Set(keyTwo, "", time.Second)
  1614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1615. //清空key 值
  1616. redis.Set(key, "", time.Second)
  1617. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1618. redis.Set(keyOne, "", time.Second)
  1619. if err == nil {
  1620. c.ServeSuccessJSON(map[string]interface{}{
  1621. "assessmentAfterDislysis": assessmentAfterDislysis,
  1622. })
  1623. return
  1624. }
  1625. }
  1626. return
  1627. }
  1628. func (c *DialysisAPIController) PostDialysisPrescription() {
  1629. id, _ := c.GetInt64("patient", 0)
  1630. recordDateStr := c.GetString("record_date")
  1631. if id <= 0 {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. adminUserInfo := c.GetMobileAdminUserInfo()
  1636. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, 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. mode_id, _ := c.GetInt64("mode_id", 0)
  1651. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1652. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1653. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1654. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1655. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1656. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1657. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1658. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1659. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1660. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1661. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1662. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1663. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1664. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1665. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1666. kalium, _ := c.GetFloat("kalium", 0)
  1667. sodium, _ := c.GetFloat("sodium", 0)
  1668. calcium, _ := c.GetFloat("calcium", 0)
  1669. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1670. glucose, _ := c.GetFloat("glucose", 0)
  1671. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1672. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1673. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1674. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1675. conductivity, _ := c.GetFloat("conductivity", 0)
  1676. remark := c.GetString("remark")
  1677. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1678. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1679. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1680. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1681. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1682. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1683. special_medicine_other := c.GetString("special_medicine_other")
  1684. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1685. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1686. blood_access, _ := c.GetInt64("blood_access", 0)
  1687. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1688. body_fluid_other := c.GetString("body_fluid_other")
  1689. niprocart, _ := c.GetInt64("niprocart", 0)
  1690. jms, _ := c.GetInt64("jms", 0)
  1691. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1692. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1693. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1694. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1695. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1696. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1697. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1698. injector, _ := c.GetInt64("injector", 0)
  1699. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1700. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1701. safe_package, _ := c.GetInt64("package", 0)
  1702. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1703. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1704. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1705. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1706. blood := c.GetString("blood")
  1707. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1708. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1709. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1710. displace_speed := c.GetString("displace_speed")
  1711. illness, _ := c.GetInt64("illness")
  1712. amylaceum := c.GetString("amylaceum")
  1713. single_time := c.GetString("single_time")
  1714. single_water := c.GetString("single_water")
  1715. replacement_flow := c.GetString("replacement_flow")
  1716. plasma_separator := c.GetString("plasma_separator")
  1717. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1718. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1719. oxygen_flow := c.GetString("oxygen_flow")
  1720. oxygen_time := c.GetString("oxygen_time")
  1721. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1722. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1723. puncture_needle := c.GetString("puncture_needle")
  1724. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1725. epo := c.GetString("epo")
  1726. epo_count, _ := c.GetFloat("epo_count", 0)
  1727. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1728. admin_user_id, _ := c.GetInt64("admin_user_id")
  1729. is_water := c.GetString("is_water")
  1730. var is_war int64
  1731. if is_water == "是" {
  1732. is_war = 1
  1733. }
  1734. if is_water == "否" {
  1735. is_war = 2
  1736. }
  1737. if is_water == "请选择" {
  1738. is_war = 0
  1739. }
  1740. drhy_water := c.GetString("drhy_water")
  1741. dry_water_hour := c.GetString("dry_water_hour")
  1742. water_machine := c.GetString("water_machine")
  1743. add_amount, _ := c.GetFloat("add_amount")
  1744. reduce_amount, _ := c.GetFloat("reduce_amount")
  1745. dialysis_remark := c.GetString("dialysis_remark")
  1746. prescribing_number, _ := c.GetFloat("prescribing_number")
  1747. prescription_sodium := c.GetString("prescription_sodium")
  1748. start_sodium := c.GetString("start_sodium")
  1749. sodium_curve := c.GetString("sodium_curve")
  1750. treatment_remark := c.GetString("treatment_remark")
  1751. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1752. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1753. prescription_water, _ := c.GetFloat("prescription_water")
  1754. dialysis_strainer := c.GetString("dialysis_strainer")
  1755. chaptalization := c.GetString("chaptalization")
  1756. washing_time := c.GetString("washing_time")
  1757. warsh_count := c.GetString("warsh_count")
  1758. blood_access_part_id := c.GetString("blood_access_part_id")
  1759. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1760. dialyzate := c.GetString("dialyzate")
  1761. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1762. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1763. //
  1764. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1765. // if appRole.UserType == 3 {
  1766. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1767. // if getPermissionErr != nil {
  1768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1769. // return
  1770. // } else if headNursePermission == nil {
  1771. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1772. // return
  1773. // }
  1774. // }
  1775. //}
  1776. // 查询信息规挡的设置天数
  1777. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1778. if infor.ID > 0 && infor.WeekDay > 0 {
  1779. var cha_time int64
  1780. timeNowStr := time.Now().Format("2006-01-02")
  1781. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1782. //今日的日期减去设置的日期
  1783. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1784. if cha_time >= recordDate.Unix() {
  1785. //查询审核是否允许
  1786. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1787. //申请状态不允许的情况 拒绝修改
  1788. if infor.ApplicationStatus != 1 {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1790. return
  1791. }
  1792. }
  1793. }
  1794. if mode_id > 0 {
  1795. var str string
  1796. //查找该机构用的是什么透析器
  1797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1798. if filedConfig.ID > 0 {
  1799. str = dialyzerPerfusionApparatus
  1800. } else {
  1801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1802. }
  1803. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1804. }
  1805. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1806. var dialysis_dialyszers_id int64
  1807. var dialysis_strainer_id int64
  1808. var dialysis_irrigation_id int64
  1809. if len(goodList) > 0 {
  1810. for _, item := range goodList {
  1811. if item.SpecificationName == dialysis_dialyszers {
  1812. dialysis_dialyszers_id = item.ID
  1813. }
  1814. if item.SpecificationName == dialysis_irrigation {
  1815. dialysis_irrigation_id = item.ID
  1816. }
  1817. if item.SpecificationName == dialysis_strainer {
  1818. dialysis_strainer_id = item.ID
  1819. }
  1820. }
  1821. }
  1822. //TODO 需要根据角色去判断
  1823. prescription := models.DialysisPrescription{
  1824. UserOrgId: adminUserInfo.Org.Id,
  1825. PatientId: id,
  1826. RecordDate: recordDate.Unix(),
  1827. ModeId: mode_id,
  1828. DialysisDuration: dialysis_duration,
  1829. Dialyzer: dialyzer,
  1830. PerfusionApparatus: perfusion_apparatus,
  1831. BloodFlowVolume: blood_flow_volume,
  1832. DewaterAmount: dewater_amount,
  1833. DisplaceLiqui: displace_liqui,
  1834. ReplacementWay: replacement_way,
  1835. Anticoagulant: anticoagulant,
  1836. AnticoagulantShouji: anticoagulant_shouji,
  1837. AnticoagulantWeichi: anticoagulant_weichi,
  1838. AnticoagulantZongliang: anticoagulant_zongliang,
  1839. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1840. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1841. Kalium: kalium,
  1842. Sodium: sodium,
  1843. Calcium: calcium,
  1844. Bicarbonate: bicarbonate,
  1845. Glucose: glucose,
  1846. // DryWeight: dry_weight,
  1847. DialysateFlow: dialysate_flow,
  1848. DialysateTemperature: dialysate_temperature,
  1849. // PrescriptionDoctor: prescription_doctor,
  1850. ReplacementTotal: replacement_total,
  1851. Conductivity: conductivity,
  1852. Remark: remark,
  1853. Status: 1,
  1854. CreatedTime: time.Now().Unix(),
  1855. UpdatedTime: time.Now().Unix(),
  1856. DialysisDurationMinute: dialysisDurationMinute,
  1857. DialysisDurationHour: dialysisDurationHour,
  1858. TargetUltrafiltration: targetUltrafiltration,
  1859. DialysateFormulation: dialysateFormulation,
  1860. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1861. BodyFluid: body_fluid,
  1862. SpecialMedicine: special_medicine,
  1863. SpecialMedicineOther: special_medicine_other,
  1864. DisplaceLiquiPart: displace_liqui_part,
  1865. DisplaceLiquiValue: displace_liqui_value,
  1866. BloodAccess: blood_access,
  1867. Ultrafiltration: ultrafiltration,
  1868. BodyFluidOther: body_fluid_other,
  1869. Niprocart: niprocart,
  1870. Jms: jms,
  1871. FistulaNeedleSet: fistula_needle_set,
  1872. FistulaNeedleSet16: fistula_needle_set_16,
  1873. Hemoperfusion: hemoperfusion,
  1874. DialyserSterilised: dialyser_sterilised,
  1875. Filtryzer: filtryzer,
  1876. Dialyzers: dialyzers,
  1877. Injector: injector,
  1878. Bloodlines: bloodlines,
  1879. TubingHemodialysis: tubing_hemodialysis,
  1880. Package: safe_package,
  1881. ALiquid: a_liquid,
  1882. TargetKtv: target_ktv,
  1883. PreImpulse: pre_impulse,
  1884. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1885. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1886. Blood: blood,
  1887. DialysisDialyszers: dialysis_dialyszers,
  1888. DialysisIrrigation: dialysis_irrigation,
  1889. AntioxidantCommodityName: antioxidant_commodity_name,
  1890. DisplaceSpeed: displace_speed,
  1891. Illness: illness,
  1892. Amylaceum: amylaceum,
  1893. SingleTime: single_time,
  1894. SingleWater: single_water,
  1895. ReplacementFlow: replacement_flow,
  1896. PlasmaSeparator: plasma_separator,
  1897. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1898. OxygenUptake: oxygen_uptake,
  1899. OxygenFlow: oxygen_flow,
  1900. OxygenTime: oxygen_time,
  1901. HemodialysisPipelines: hemodialysis_pipelines,
  1902. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1903. PunctureNeedle: puncture_needle,
  1904. PunctureNeedleCount: puncture_needle_count,
  1905. Epo: epo,
  1906. EpoCount: epo_count,
  1907. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1908. AdminUserId: admin_user_id,
  1909. IsWater: is_war,
  1910. DrhyWater: drhy_water,
  1911. DryWaterHour: dry_water_hour,
  1912. WaterMachine: water_machine,
  1913. AddAmount: add_amount,
  1914. ReduceAmount: reduce_amount,
  1915. DialysisRemark: dialysis_remark,
  1916. PrescribingNumber: prescribing_number,
  1917. StartSodium: start_sodium,
  1918. SodiumCurve: sodium_curve,
  1919. TreatmentRemark: treatment_remark,
  1920. PrescriptionSodium: prescription_sodium,
  1921. DialysisFluidFlow: dialysis_fluid_flow,
  1922. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1923. PrescriptionWater: prescription_water,
  1924. DialysisStrainer: dialysis_strainer,
  1925. Chaptalization: chaptalization,
  1926. WashingTime: washing_time,
  1927. WarshCount: warsh_count,
  1928. BloodAccessPartId: blood_access_part_id,
  1929. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1930. Dialyzate: dialyzate,
  1931. DialysisDialyszersId: dialysis_dialyszers_id,
  1932. DialysisIrrigationId: dialysis_irrigation_id,
  1933. DialysisStrainerId: dialysis_strainer_id,
  1934. }
  1935. if adminUserInfo.Org.Id == 10721 {
  1936. if prescription.ModeId == 2 {
  1937. if prescription.ReplacementTotal == 0 {
  1938. prescription.ReplacementTotal = 15
  1939. }
  1940. }
  1941. }
  1942. //查询最近透析准备表里是否存在 透析器 灌流器
  1943. //
  1944. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1945. //
  1946. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1947. //
  1948. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1949. //if len(mation)>0{
  1950. // for _, item := range splitStr {
  1951. // for _,it := range mation{
  1952. // if(item == it.SpecificationName){
  1953. //
  1954. // //查询最近一次的透析器
  1955. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1956. //
  1957. // if errcode == gorm.ErrRecordNotFound{
  1958. // //插入数据
  1959. // prepare := models.DialysisBeforePrepare{
  1960. // UserOrgId: adminUserInfo.Org.Id,
  1961. // PatientId: id,
  1962. // RecordDate: recordDate.Unix(),
  1963. // GoodTypeId: it.GoodTypeId,
  1964. // GoodId: it.ID,
  1965. // Count: 1,
  1966. // Ctime: time.Now().Unix(),
  1967. // Creater: adminUserInfo.AdminUser.Id,
  1968. // Status:1,
  1969. //
  1970. // }
  1971. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1972. // fmt.Println("",errcode)
  1973. // }
  1974. // }
  1975. // }
  1976. //
  1977. // }
  1978. //
  1979. // for _, item := range splitIrrigation {
  1980. // for _,it := range mation{
  1981. // if(item == it.SpecificationName){
  1982. // //查询最近一次的透析器
  1983. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1984. // if errcode == gorm.ErrRecordNotFound{
  1985. // //插入数据
  1986. // prepare := models.DialysisBeforePrepare{
  1987. // UserOrgId: adminUserInfo.Org.Id,
  1988. // PatientId: id,
  1989. // RecordDate: recordDate.Unix(),
  1990. // GoodTypeId: it.GoodTypeId,
  1991. // GoodId: it.ID,
  1992. // Count: 1,
  1993. // Ctime: time.Now().Unix(),
  1994. // Creater: adminUserInfo.AdminUser.Id,
  1995. // Status:1,
  1996. //
  1997. // }
  1998. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1999. // fmt.Println(errcode)
  2000. // }
  2001. // }
  2002. // }
  2003. // }
  2004. //}
  2005. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2006. if dialysisPrescription.ID == 0 { //新增
  2007. if appRole.UserType == 2 || appRole.UserType == 1 {
  2008. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2009. }
  2010. prescription.Creater = adminUserInfo.AdminUser.Id
  2011. //针对河间咸得
  2012. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2013. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2014. prescription.DisplaceLiquiPart = 0
  2015. prescription.DisplaceLiquiValue = 0
  2016. }
  2017. }
  2018. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2019. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2020. }
  2021. err := service.AddSigleRecord(&prescription)
  2022. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2023. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2024. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2025. if len(monitorList) > 0 {
  2026. var ultrafiltration_rate float64
  2027. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2028. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2029. var replacement_rate float64
  2030. //乘10 除10是为了保留一位小数
  2031. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2032. var firstOpeateTime = monitorList[0].OperateTime
  2033. for _, item := range monitorList {
  2034. //超滤率
  2035. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2036. //置换率
  2037. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2038. //超滤量
  2039. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2040. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2041. //置换量
  2042. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2043. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2044. }
  2045. }
  2046. }
  2047. //记录日志
  2048. byterequest, _ := json.Marshal(prescription)
  2049. prescriptionLog := models.XtDialysisPrescriptionLog{
  2050. UserOrgId: prescription.UserOrgId,
  2051. Ctime: time.Now().Unix(),
  2052. Mtime: 0,
  2053. ErrLog: string(byterequest),
  2054. AdminUserId: adminUserInfo.AdminUser.Id,
  2055. RecordDate: prescription.RecordDate,
  2056. PatientId: prescription.PatientId,
  2057. Source: "手机端新增保存处方",
  2058. Status: 1,
  2059. }
  2060. service.CreatePrescriptionLog(prescriptionLog)
  2061. finish := models.XtDialysisFinish{
  2062. IsFinish: 1,
  2063. UserOrgId: adminUserInfo.Org.Id,
  2064. Status: 1,
  2065. Ctime: time.Now().Unix(),
  2066. Mtime: 0,
  2067. Module: 1,
  2068. RecordDate: recordDate.Unix(),
  2069. Sourse: 1,
  2070. PatientId: id,
  2071. }
  2072. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2073. if dialysisFinish.ID == 0 {
  2074. service.CreateDialysisFinish(finish)
  2075. }
  2076. //长沙南雅医院,自动生成抗凝剂的临时处方
  2077. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2078. if prescribing_number == 0 {
  2079. prescribing_number = 1
  2080. }
  2081. if prescribing_number == 0 && id == 14682 {
  2082. prescribing_number = 2
  2083. }
  2084. if prescribing_number == 0 && id == 18560 {
  2085. prescribing_number = 2
  2086. }
  2087. advice := models.DoctorAdvice{
  2088. UserOrgId: adminUserInfo.Org.Id,
  2089. PatientId: id,
  2090. GroupNo: 0,
  2091. AdviceType: 2,
  2092. RecordDate: recordDate.Unix(),
  2093. AdviceDate: recordDate.Unix(),
  2094. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2095. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2096. AdviceDesc: "",
  2097. ReminderDate: 0,
  2098. SingleDose: anticoagulant_zongliang,
  2099. SingleDoseUnit: "iu",
  2100. DrugSpec: 0,
  2101. DrugSpecUnit: "",
  2102. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2103. PrescribingNumberUnit: "支",
  2104. DeliveryWay: "静脉注射",
  2105. ExecutionFrequency: "上机前",
  2106. AdviceDoctor: 0,
  2107. Status: 1,
  2108. CreatedTime: time.Now().Unix(),
  2109. UpdatedTime: time.Now().Unix(),
  2110. IsPrescription: 1,
  2111. ExecutionState: 2,
  2112. StopState: 2,
  2113. IsSettle: 2,
  2114. }
  2115. // 查询排班信息
  2116. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2117. if schedulePatient.ID > 0 {
  2118. if schedulePatient.ScheduleType == 1 {
  2119. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2120. }
  2121. if schedulePatient.ScheduleType == 2 {
  2122. advice.StartTime = recordDate.Unix() + 9*60*60
  2123. }
  2124. }
  2125. // 抗凝剂名称
  2126. switch anticoagulant {
  2127. case 1:
  2128. advice.AdviceName = "无肝素"
  2129. break
  2130. case 2:
  2131. advice.AdviceName = "普通肝素"
  2132. break
  2133. case 3:
  2134. advice.AdviceName = "低分子肝素"
  2135. break
  2136. case 4:
  2137. advice.AdviceName = "阿加曲班"
  2138. break
  2139. case 5:
  2140. advice.AdviceName = "枸橼酸钠"
  2141. break
  2142. case 6:
  2143. advice.AdviceName = "低分子肝素钙"
  2144. break
  2145. case 7:
  2146. advice.AdviceName = "低分子肝素钠"
  2147. break
  2148. case 8:
  2149. advice.AdviceName = "依诺肝素"
  2150. break
  2151. case 9:
  2152. advice.AdviceName = "达肝素"
  2153. break
  2154. case 10:
  2155. advice.AdviceName = "体外抗凝"
  2156. break
  2157. case 11:
  2158. advice.AdviceName = "那曲肝素"
  2159. break
  2160. case 12:
  2161. advice.AdviceName = "无抗凝剂"
  2162. break
  2163. }
  2164. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2165. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2166. advice.AdviceDoctor = appRole.AdminUserId
  2167. }
  2168. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2169. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2171. advice.AdviceName = "低分子肝素钠注射液"
  2172. // 修改患者临时医嘱里的抗凝剂医嘱
  2173. advice.ID = advicePrescription.ID
  2174. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2175. } else {
  2176. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2177. advice.AdviceName = "低分子肝素钠注射液"
  2178. // 新增患者临时医嘱里的抗凝剂医嘱
  2179. service.CreateDoctorAdvice(&advice)
  2180. }
  2181. }
  2182. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2183. redis := service.RedisClient()
  2184. defer redis.Close()
  2185. //清空key 值
  2186. redis.Set(key, "", time.Second)
  2187. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2188. redis.Set(keyOne, "", time.Second)
  2189. }
  2190. //获取key,清空redis
  2191. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2192. redis := service.RedisClient()
  2193. //清空key 值
  2194. redis.Set(key, "", time.Second)
  2195. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2196. //清空key 值
  2197. redis.Set(keyOne, "", time.Second)
  2198. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2199. //清空key 值
  2200. redis.Set(keyTwo, "", time.Second)
  2201. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2202. redis.Set(keySix, "", time.Second)
  2203. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2204. redis.Set(keySeven, "", time.Second)
  2205. if err == nil {
  2206. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2207. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2208. //清空key 值
  2209. redis.Set(keyThree, "", time.Second)
  2210. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2211. //清空key 值
  2212. redis.Set(keyFour, "", time.Second)
  2213. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2214. redis.Set(keyFive, "", time.Second)
  2215. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2216. redis.Set(keySix, "", time.Second)
  2217. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2218. redis.Set(keySeven, "", time.Second)
  2219. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2220. //清空key 值
  2221. redis.Set(keyOne, "", time.Second)
  2222. if updateErr != nil {
  2223. utils.ErrorLog("%v", updateErr)
  2224. }
  2225. defer redis.Close()
  2226. c.ServeSuccessJSON(map[string]interface{}{
  2227. "prescription": prescription,
  2228. })
  2229. }
  2230. } else { //修改
  2231. //if mode_id > 0 {
  2232. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2233. //}
  2234. //if template.TemplateId == 1 {
  2235. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2236. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2237. // if getPermissionErr != nil {
  2238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2239. // return
  2240. // } else if headNursePermission == nil {
  2241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2242. // return
  2243. // }
  2244. // }
  2245. //}
  2246. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2247. prescription.Modifier = adminUserInfo.AdminUser.Id
  2248. if appRole.UserType == 2 || appRole.UserType == 1 {
  2249. prescription_doctor := adminUserInfo.AdminUser.Id
  2250. prescription.PrescriptionDoctor = prescription_doctor
  2251. } else {
  2252. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2253. }
  2254. if dialysisPrescription.Creater == 0 { //体重称
  2255. prescription.Creater = adminUserInfo.AdminUser.Id
  2256. } else {
  2257. prescription.Creater = dialysisPrescription.Creater
  2258. if adminUserInfo.Org.Id == 9882 {
  2259. if appRole.UserType == 2 || appRole.UserType == 1 {
  2260. prescription_doctor := adminUserInfo.AdminUser.Id
  2261. prescription.PrescriptionDoctor = prescription_doctor
  2262. prescription.Creater = prescription_doctor
  2263. }
  2264. }
  2265. }
  2266. prescription.ID = dialysisPrescription.ID
  2267. if adminUserInfo.Org.Id == 10721 {
  2268. if prescription.ModeId == 2 {
  2269. if prescription.ReplacementTotal == 0 {
  2270. prescription.ReplacementTotal = 15
  2271. }
  2272. }
  2273. }
  2274. service.UpDateDialysisPrescription(&prescription)
  2275. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2276. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2277. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2278. if len(monitorList) > 0 {
  2279. var ultrafiltration_rate float64
  2280. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2281. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2282. var replacement_rate float64
  2283. //乘10 除10是为了保留一位小数
  2284. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2285. var firstOpeateTime = monitorList[0].OperateTime
  2286. for _, item := range monitorList {
  2287. //超滤率
  2288. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2289. //置换率
  2290. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2291. //超滤量
  2292. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2293. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2294. //置换量
  2295. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2296. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2297. }
  2298. }
  2299. }
  2300. //记录日志
  2301. byterequest, _ := json.Marshal(prescription)
  2302. prescriptionLog := models.XtDialysisPrescriptionLog{
  2303. UserOrgId: prescription.UserOrgId,
  2304. Ctime: time.Now().Unix(),
  2305. Mtime: 0,
  2306. ErrLog: string(byterequest),
  2307. AdminUserId: adminUserInfo.AdminUser.Id,
  2308. RecordDate: prescription.RecordDate,
  2309. PatientId: prescription.PatientId,
  2310. Source: "手机端修改处方",
  2311. Status: 1,
  2312. }
  2313. service.CreatePrescriptionLog(prescriptionLog)
  2314. finish := models.XtDialysisFinish{
  2315. IsFinish: 1,
  2316. UserOrgId: adminUserInfo.Org.Id,
  2317. Status: 1,
  2318. Ctime: time.Now().Unix(),
  2319. Mtime: 0,
  2320. Module: 1,
  2321. RecordDate: recordDate.Unix(),
  2322. Sourse: 1,
  2323. PatientId: id,
  2324. }
  2325. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2326. if dialysisFinish.ID == 0 {
  2327. service.CreateDialysisFinish(finish)
  2328. }
  2329. //修改处方
  2330. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2331. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2332. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2333. if advicePrescription.ID > 0 {
  2334. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2336. redis := service.RedisClient()
  2337. defer redis.Close()
  2338. //清空key 值
  2339. redis.Set(key, "", time.Second)
  2340. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2341. redis.Set(keyOne, "", time.Second)
  2342. }
  2343. }
  2344. //获取key,清空redis
  2345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2346. redis := service.RedisClient()
  2347. //清空key 值
  2348. redis.Set(key, "", time.Second)
  2349. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2350. //清空key 值
  2351. redis.Set(keyOne, "", time.Second)
  2352. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2353. redis.Set(keySix, "", time.Second)
  2354. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2355. redis.Set(keySeven, "", time.Second)
  2356. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2357. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2358. //清空key 值
  2359. redis.Set(keyTwoOne, "", time.Second)
  2360. defer redis.Close()
  2361. if updateErr != nil {
  2362. utils.ErrorLog("%v", updateErr)
  2363. }
  2364. c.ServeSuccessJSON(map[string]interface{}{
  2365. "prescription": prescription,
  2366. })
  2367. }
  2368. }
  2369. func (c *DialysisAPIController) Finish() {
  2370. id, _ := c.GetInt64("patient", 0)
  2371. recordDateStr := c.GetString("record_date")
  2372. nurseID, _ := c.GetInt64("nurse")
  2373. end_time := c.GetString("end_time")
  2374. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2375. internal_fistula := c.GetString("blood_access_internal_fistula")
  2376. catheter := c.GetString("catheter")
  2377. cruor := c.GetString("cruor")
  2378. mission := c.GetString("mission")
  2379. condenser := c.GetString("condenser")
  2380. if id <= 0 || nurseID <= 0 {
  2381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2382. return
  2383. }
  2384. adminUserInfo := c.GetMobileAdminUserInfo()
  2385. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2386. if patient.ID == 0 {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2388. return
  2389. }
  2390. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2391. if getNurseErr != nil {
  2392. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2394. return
  2395. } else if nurse == nil {
  2396. c.ErrorLog("护士不存在")
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2398. return
  2399. }
  2400. if len(recordDateStr) == 0 {
  2401. recordDateStr = time.Now().Format("2006-01-02")
  2402. }
  2403. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2404. if parseDateErr != nil {
  2405. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2410. if parseEndDateErr != nil {
  2411. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. // 查询信息规挡的设置天数
  2416. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2417. if infor.ID > 0 && infor.WeekDay > 0 {
  2418. var cha_time int64
  2419. timeNowStr := time.Now().Format("2006-01-02")
  2420. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2421. //今日的日期减去设置的日期
  2422. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2423. if cha_time >= recordDate.Unix() {
  2424. //查询审核是否允许
  2425. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2426. //申请状态不允许的情况 拒绝修改
  2427. if infor.ApplicationStatus != 1 {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2429. return
  2430. }
  2431. }
  2432. }
  2433. //now := time.Now()
  2434. //year, month, day := now.Date()
  2435. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2436. //todayTimeStamp := today_time.Unix()
  2437. // 获取当天的第一条透析纪录
  2438. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2439. if getMonitorRecordsErr != nil {
  2440. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2442. return
  2443. }
  2444. // 获取当前的最后一条透析纪录
  2445. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2446. if getMonitorRecordsErr != nil {
  2447. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2449. return
  2450. }
  2451. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2452. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2453. if getAADErr != nil {
  2454. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2459. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2460. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2461. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2462. if assessmentAfterDislysis != nil {
  2463. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2464. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2465. } else {
  2466. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2467. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2468. tempassessmentAfterDislysis.Status = 1
  2469. tempassessmentAfterDislysis.PatientId = id
  2470. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2471. }
  2472. //长沙南雅
  2473. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2474. //获取最后一条透析处方数据
  2475. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2476. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2478. }
  2479. if dialysisOrder.Stage == 1 {
  2480. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2481. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2482. fmt.Println(value)
  2483. a, b := math.Modf(value)
  2484. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2485. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2486. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2487. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2488. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2489. }
  2490. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2491. //var num1 int64
  2492. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2493. //fmt.Println(num1)
  2494. //sub := float64(num1 / 3600)
  2495. //fmt.Println(sub)
  2496. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2497. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2498. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2499. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2500. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2501. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2502. if adminUserInfo.Org.Id != 10375 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2505. }
  2506. if adminUserInfo.Org.Id != 10445 {
  2507. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2508. }
  2509. //北方营口医院
  2510. if adminUserInfo.Org.Id == 10445 {
  2511. //获取最后一条透析处方数据
  2512. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2513. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2514. } else {
  2515. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2516. }
  2517. //新化博翔
  2518. if adminUserInfo.Org.Id == 10447 {
  2519. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2520. }
  2521. //阳春
  2522. if adminUserInfo.Org.Id == 10485 {
  2523. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2524. }
  2525. if adminUserInfo.Org.Id == 10551 {
  2526. //获取最后一条透析处方数据
  2527. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2528. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2529. }
  2530. if adminUserInfo.Org.Id == 10580 {
  2531. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2532. }
  2533. if adminUserInfo.Org.Id == 10612 {
  2534. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2535. }
  2536. //孝康
  2537. if adminUserInfo.Org.Id == 10693 {
  2538. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2539. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2540. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2541. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2542. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2543. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2544. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2545. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2546. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2547. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2548. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2549. }
  2550. if adminUserInfo.Org.Id == 10721 {
  2551. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2552. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2553. }
  2554. if adminUserInfo.Org.Id == 10697 {
  2555. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2556. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2557. lastWeightAfter.LastAfterWeight = floatAfeter
  2558. }
  2559. }
  2560. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 {
  2561. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. if evaluation.SystolicBloodPressure == 0 {
  2563. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2564. if adminUserInfo.Org.Id == 10693 {
  2565. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2566. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2567. }
  2568. pre := models.PredialysisEvaluation{
  2569. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2570. }
  2571. fmt.Println("prew", pre)
  2572. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2573. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2574. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2575. redis := service.RedisClient()
  2576. redis.Set(key, "", time.Second)
  2577. redis.Set(keyOne, "", time.Second)
  2578. defer redis.Close()
  2579. fmt.Println(getNurseErr)
  2580. }
  2581. if evaluation.DiastolicBloodPressure == 0 {
  2582. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2583. if adminUserInfo.Org.Id == 10693 {
  2584. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2585. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2586. }
  2587. pres := models.PredialysisEvaluation{
  2588. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2589. }
  2590. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2592. redis := service.RedisClient()
  2593. redis.Set(key, "", time.Second)
  2594. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2595. redis.Set(keyOne, "", time.Second)
  2596. defer redis.Close()
  2597. fmt.Println(getNurseErr)
  2598. }
  2599. if evaluation.PulseFrequency == 0 {
  2600. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2601. if adminUserInfo.Org.Id == 10693 {
  2602. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2603. evaluation.PulseFrequency = pulseFrequency
  2604. }
  2605. press := models.PredialysisEvaluation{
  2606. PulseFrequency: evaluation.PulseFrequency,
  2607. }
  2608. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2609. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2610. redis := service.RedisClient()
  2611. redis.Set(key, "", time.Second)
  2612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2613. redis.Set(keyOne, "", time.Second)
  2614. defer redis.Close()
  2615. fmt.Println(getNurseErr)
  2616. }
  2617. if evaluation.Temperature == 0 {
  2618. evaluation.Temperature = fmonitorRecords.Temperature
  2619. press := models.PredialysisEvaluation{
  2620. Temperature: evaluation.Temperature,
  2621. }
  2622. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2624. redis := service.RedisClient()
  2625. redis.Set(key, "", time.Second)
  2626. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2627. redis.Set(keyOne, "", time.Second)
  2628. defer redis.Close()
  2629. fmt.Println(getNurseErr)
  2630. }
  2631. }
  2632. if adminUserInfo.Org.Id == 9583 {
  2633. //获取透析处方的最后一条数据
  2634. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2635. if diaerr != nil {
  2636. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2638. return
  2639. }
  2640. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2641. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2642. }
  2643. }
  2644. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2645. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2646. }
  2647. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2648. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2649. }
  2650. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2651. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2652. }
  2653. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2654. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2655. }
  2656. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2657. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2658. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2659. }
  2660. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2661. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2662. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2663. }
  2664. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2665. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2666. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2667. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2668. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2669. }
  2670. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2671. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2672. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2673. }
  2674. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2675. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2676. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2677. }
  2678. if lastAssessmentAfterDislysis != nil {
  2679. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2680. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2681. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2682. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2683. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2684. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2685. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2686. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2687. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2688. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2689. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2690. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2691. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2692. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2693. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2694. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2695. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2696. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2697. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2698. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2699. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2700. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2701. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2702. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2703. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2704. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2705. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2706. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2707. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2708. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2709. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2710. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2711. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2712. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2713. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2714. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2715. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2716. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2717. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2718. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2719. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2720. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2721. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2722. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2723. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2724. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2725. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2726. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2727. if tempassessmentAfterDislysis.PatientId == 18695 {
  2728. tempassessmentAfterDislysis.ActualDisplacement = 0
  2729. }
  2730. if adminUserInfo.Org.Id != 10375 {
  2731. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2732. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2733. }
  2734. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2735. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2736. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2737. }
  2738. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2739. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2740. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2741. }
  2742. }
  2743. finish := models.XtDialysisFinish{
  2744. IsFinish: 1,
  2745. UserOrgId: adminUserInfo.Org.Id,
  2746. Status: 1,
  2747. Ctime: time.Now().Unix(),
  2748. Mtime: 0,
  2749. Module: 9,
  2750. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2751. Sourse: 1,
  2752. PatientId: tempassessmentAfterDislysis.PatientId,
  2753. }
  2754. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2755. if dialysisFinish.ID == 0 {
  2756. service.CreateDialysisFinish(finish)
  2757. }
  2758. //孝康
  2759. if adminUserInfo.Org.Id == 10693 {
  2760. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2761. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2762. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2763. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2764. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2765. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2766. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2767. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2768. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2769. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2770. }
  2771. if adminUserInfo.Org.Id == 10697 {
  2772. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2773. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2774. lastWeightAfter.LastAfterWeight = floatAfeter
  2775. }
  2776. if adminUserInfo.Org.Id == 10721 {
  2777. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. }
  2780. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2781. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2782. redis := service.RedisClient()
  2783. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2784. redis.Set(keyOne, "", time.Second)
  2785. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2786. redis.Set(keyTwo, "", time.Second)
  2787. defer redis.Close()
  2788. //清空key 值
  2789. redis.Set(key, "", time.Second)
  2790. if err != nil {
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2792. return
  2793. }
  2794. if dialysisOrder == nil {
  2795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2796. return
  2797. }
  2798. if dialysisOrder.Stage == 2 {
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2800. return
  2801. }
  2802. if dialysisOrder.Stage == 1 {
  2803. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2804. finish := models.XtDialysisFinish{
  2805. IsFinish: 1,
  2806. UserOrgId: adminUserInfo.Org.Id,
  2807. Status: 1,
  2808. Ctime: time.Now().Unix(),
  2809. Mtime: 0,
  2810. Module: 8,
  2811. RecordDate: recordDate.Unix(),
  2812. Sourse: 1,
  2813. PatientId: id,
  2814. }
  2815. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2816. if dialysisFinish.ID == 0 {
  2817. service.CreateDialysisFinish(finish)
  2818. }
  2819. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2820. redis := service.RedisClient()
  2821. defer redis.Close()
  2822. //清空key 值
  2823. redis.Set(key, "", time.Second)
  2824. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2825. redis.Set(keyOne, "", time.Second)
  2826. //结束时候透析次数加1
  2827. service.UpdateSolutionByPatientId(id)
  2828. //下机完自动消毒,针对长沙南雅
  2829. if dialysisOrder.Stage == 1 {
  2830. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2831. //根据床位号获取设备型号
  2832. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2833. //查询使用消毒最后一条消毒记录
  2834. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2835. fmt.Println("err", err)
  2836. if err == gorm.ErrRecordNotFound {
  2837. //查找排班
  2838. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2839. //查询改设备是否有消毒计划
  2840. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2841. //根据床位号获取设备id
  2842. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2843. //查询病人信息
  2844. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2845. var con = ""
  2846. if patients.IsInfectious == 0 {
  2847. con = ""
  2848. }
  2849. if patients.IsInfectious == 1 {
  2850. con = "无"
  2851. }
  2852. if patients.IsInfectious == 2 {
  2853. con = "有"
  2854. }
  2855. if errcode == nil {
  2856. var end_time int64
  2857. end_time = endDate.Unix() + plan.DisinfecTime*60
  2858. //新增消毒
  2859. information := models.DeviceInformation{
  2860. Date: dialysisOrder.DialysisDate,
  2861. Zone: dialysisOrder.ZoneId,
  2862. Class: dialysisOrder.SchedualType,
  2863. BedNumber: dialysisOrder.BedID,
  2864. PatientId: dialysisOrder.PatientId,
  2865. DialysisMode: scheduleByPatient.ModeId,
  2866. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2867. Disinfection: 1,
  2868. DialysisConcentration: 1,
  2869. DisinfectionStatus: 1,
  2870. Move: 1,
  2871. UserOrgId: dialysisOrder.UserOrgId,
  2872. DisinfectType: plan.Way,
  2873. DisinfectantType: plan.MachineDisinfectant,
  2874. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2875. Disinfectant: plan.Disinfectant,
  2876. Ctime: time.Now().Unix(),
  2877. Status: 1,
  2878. SignName: nurseID,
  2879. EquimentId: addmacher.ID,
  2880. DisinfectionResidue: 2,
  2881. Bed: addmacher.BedNumber,
  2882. StartTime: dialysisOrder.StartTime,
  2883. EndTime: dialysisOrder.EndTime,
  2884. Contagion: con,
  2885. WeightLoss: 0,
  2886. Hyperfiltratio: 0,
  2887. DialysisHour: "",
  2888. MachineRun: 1,
  2889. DisinfecStartime: endDate.Unix(),
  2890. DisinfecEndtime: end_time,
  2891. }
  2892. err := service.CreateInformationTwo(&information)
  2893. fmt.Println("报错", err)
  2894. }
  2895. }
  2896. }
  2897. }
  2898. dialysisOrder.Stage = 2
  2899. dialysisOrder.FinishNurse = nurseID
  2900. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2901. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2902. dialysisOrder.EndTime = endDate.Unix()
  2903. // 长沙南雅需求
  2904. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2905. //获取最后1条监测的数据
  2906. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2907. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2908. var accumulatedBloodVolume float64
  2909. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2910. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2911. fmt.Println(err)
  2912. // 查询未执行的医嘱
  2913. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2914. for _, item := range doctorAdvice {
  2915. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2917. redis := service.RedisClient()
  2918. //清空key 值
  2919. redis.Set(key, "", time.Second)
  2920. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2921. redis.Set(keyTwo, "", time.Second)
  2922. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2923. redis.Set(keyThree, "", time.Second)
  2924. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2925. theTime := toTime.Format("2006-01-02")
  2926. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2927. redis.Set(keyFour, "", time.Second)
  2928. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2929. redis.Set(keyFive, "", time.Second)
  2930. defer redis.Close()
  2931. }
  2932. }
  2933. go func() {
  2934. ssoDomain := beego.AppConfig.String("call_domain")
  2935. api := ssoDomain + "/index/downpatient"
  2936. values := make(url.Values)
  2937. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2938. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2939. values.Set("patient_id", strconv.FormatInt(id, 10))
  2940. http.PostForm(api, values)
  2941. }()
  2942. if err == nil {
  2943. c.ServeSuccessJSON(map[string]interface{}{
  2944. "dialysisOrder": dialysisOrder,
  2945. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2946. })
  2947. } else {
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2949. }
  2950. }
  2951. }
  2952. func (c *DialysisAPIController) GetAllZone() {
  2953. adminUserInfo := c.GetMobileAdminUserInfo()
  2954. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2955. if err == nil {
  2956. c.ServeSuccessJSON(map[string]interface{}{
  2957. "zone": zone,
  2958. })
  2959. }
  2960. }
  2961. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2962. adminUserInfo := c.GetMobileAdminUserInfo()
  2963. page, _ := c.GetInt64("page", 1)
  2964. limit, _ := c.GetInt64("limit", 10)
  2965. schedulType, _ := c.GetInt64("schedul_type", 0)
  2966. startTime, _ := c.GetInt64("schedul_time", 0)
  2967. partitionType, _ := c.GetInt64("partition_type", 0)
  2968. keywords := c.GetString("keywords")
  2969. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2970. if err == nil {
  2971. c.ServeSuccessJSON(map[string]interface{}{
  2972. "schedule": dialysisSchedule,
  2973. })
  2974. }
  2975. return
  2976. }
  2977. // /m/api/dialysis/start [post]
  2978. // @param patient_id:int
  2979. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2980. // @param nurse:int 上机护士
  2981. // @param bed:int 床位号
  2982. func (this *DialysisAPIController) StartDialysis() {
  2983. patientID, _ := this.GetInt64("patient_id")
  2984. recordDateStr := this.GetString("record_date")
  2985. nurseID, _ := this.GetInt64("start_nurse")
  2986. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2987. blood_drawing, _ := this.GetInt64("blood_drawing")
  2988. schedual_type, _ := this.GetInt64("schedual_type")
  2989. bedID, _ := this.GetInt64("bed")
  2990. start_time := this.GetString("start_time")
  2991. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2992. change_nurse, _ := this.GetInt64("change_nurse")
  2993. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2994. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2995. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2996. puncture_needle := this.GetString("puncture_needle")
  2997. puncture_way := this.GetString("puncture_way")
  2998. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2999. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3000. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3001. zone_id, _ := this.GetInt64("zone_id")
  3002. elecsign := this.GetString("url")
  3003. nuclein_date_str := this.GetString("nuclein_date_str")
  3004. schedule_remark := this.GetString("schedule_remark")
  3005. order_remark := this.GetString("order_remark")
  3006. catheter_operation := this.GetString("catheter_operation")
  3007. blood_flow_volume := this.GetString("blood_flow_volume")
  3008. dialysis_strainer := this.GetString("dialysis_strainer")
  3009. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3011. return
  3012. }
  3013. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3014. if parseStartDateErr != nil {
  3015. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3017. return
  3018. }
  3019. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3020. if parseErr != nil {
  3021. this.ErrorLog("时间解析失败:%v", parseErr)
  3022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3023. return
  3024. }
  3025. adminUserInfo := this.GetMobileAdminUserInfo()
  3026. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3027. if getPatientErr != nil {
  3028. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3030. return
  3031. } else if patient == nil {
  3032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3033. return
  3034. }
  3035. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3036. if getNurseErr != nil {
  3037. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3039. return
  3040. } else if nurse == nil {
  3041. this.ErrorLog("护士不存在")
  3042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3046. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3047. if getDeviceNumberErr != nil {
  3048. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3050. return
  3051. } else if deviceNumber == nil {
  3052. this.ErrorLog("床位号不存在")
  3053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3054. return
  3055. }
  3056. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3057. if getRecordErr != nil {
  3058. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3060. return
  3061. } else if dialysisRecord != nil {
  3062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3063. return
  3064. }
  3065. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3066. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3067. timeLayout := "2006-01-02 15:04:05"
  3068. loc, _ := time.LoadLocation("Local")
  3069. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3070. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3071. schedulestartTime := theStartTime.Unix()
  3072. scheduleendTime := theEndTime.Unix()
  3073. var theNucleinDate int64
  3074. timeLayoutOne := "2006-01-02"
  3075. if len(nuclein_date_str) > 0 {
  3076. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3077. if err != nil {
  3078. utils.ErrorLog(err.Error())
  3079. }
  3080. theNucleinDate = theTime.Unix()
  3081. }
  3082. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3083. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3084. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3085. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3086. //查询该床位是否有人用了
  3087. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3088. if err == gorm.ErrRecordNotFound { //空床位
  3089. // 修改了床位逻辑
  3090. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3091. if daySchedule.ID > 0 {
  3092. daySchedule.PartitionId = deviceNumber.ZoneID
  3093. daySchedule.BedId = bedID
  3094. daySchedule.ScheduleType = schedual_type
  3095. daySchedule.UpdatedTime = time.Now().Unix()
  3096. xtSchedule := models.Schedule{
  3097. PartitionId: deviceNumber.ZoneID,
  3098. BedId: bedID,
  3099. ScheduleType: schedual_type,
  3100. UpdatedTime: time.Now().Unix(),
  3101. }
  3102. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3103. if err != nil {
  3104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3105. return
  3106. }
  3107. }
  3108. } else if err == nil {
  3109. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3110. if order.ID > 0 { //该机位被其他人占用了
  3111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3112. return
  3113. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3114. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3115. if daySchedule.ID > 0 {
  3116. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3117. if err != nil {
  3118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3119. return
  3120. }
  3121. }
  3122. }
  3123. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3125. return
  3126. }
  3127. //else if order.ID == 0 { //该床位没被占用
  3128. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3129. // if daySchedule.ID > 0 {
  3130. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3131. // //daySchedule.BedId = bedID
  3132. // //daySchedule.ScheduleType = schedual_type
  3133. // //daySchedule.UpdatedTime = time.Now().Unix()
  3134. // //err := service.UpdateSchedule(&daySchedule)
  3135. // xtSchedule := models.Schedule{
  3136. // PartitionId: deviceNumber.ZoneID,
  3137. // BedId: bedID,
  3138. // ScheduleType: schedual_type,
  3139. // UpdatedTime: time.Now().Unix(),
  3140. // }
  3141. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3142. // if err != nil {
  3143. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3144. // return
  3145. // }
  3146. // }
  3147. //}
  3148. //}
  3149. } else if err != nil {
  3150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3151. return
  3152. }
  3153. // 查询信息规挡的设置天数
  3154. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3155. if infor.ID > 0 && infor.WeekDay > 0 {
  3156. var cha_time int64
  3157. timeNowStr := time.Now().Format("2006-01-02")
  3158. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3159. //今日的日期减去设置的日期
  3160. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3161. if cha_time >= recordDate.Unix() {
  3162. //查询审核是否允许
  3163. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3164. //申请状态不允许的情况 拒绝修改
  3165. if infor.ApplicationStatus != 1 {
  3166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3167. return
  3168. }
  3169. }
  3170. }
  3171. dialysisRecord = &models.DialysisOrder{
  3172. DialysisDate: recordDate.Unix(),
  3173. UserOrgId: adminUserInfo.Org.Id,
  3174. PatientId: patientID,
  3175. Stage: 1,
  3176. BedID: bedID,
  3177. StartNurse: nurseID,
  3178. Status: 1,
  3179. StartTime: startDate.Unix(),
  3180. CreatedTime: time.Now().Unix(),
  3181. UpdatedTime: time.Now().Unix(),
  3182. PunctureNurse: puncture_nurse,
  3183. Creator: adminUserInfo.AdminUser.Id,
  3184. Modifier: adminUserInfo.AdminUser.Id,
  3185. SchedualType: schedual_type,
  3186. WashpipeNurse: washpipe_nurse,
  3187. ChangeNurse: change_nurse,
  3188. DifficultPunctureNurse: difficult_puncture_nurse,
  3189. NewFistulaNurse: new_fistula_nurse,
  3190. ZoneId: zone_id,
  3191. QualityNurseId: quality_nurse_id,
  3192. PunctureNeedle: puncture_needle,
  3193. PunctureWay: puncture_way,
  3194. DialysisIrrigation: dialysis_irrigation,
  3195. DialysisDialyszers: dialysis_dialyszers,
  3196. BloodAccessId: blood_access_id,
  3197. Url: elecsign,
  3198. NucleinDate: theNucleinDate,
  3199. ScheduleRemark: schedule_remark,
  3200. OrderRemark: order_remark,
  3201. CatheterOperation: catheter_operation,
  3202. BloodFlowVolume: blood_flow_volume,
  3203. BloodDrawing: blood_drawing,
  3204. DialysisStrainer: dialysis_strainer,
  3205. }
  3206. //查询该床位是否有人用了
  3207. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3208. if errorscode == gorm.ErrRecordNotFound {
  3209. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3210. finish := models.XtDialysisFinish{
  3211. IsFinish: 1,
  3212. UserOrgId: adminUserInfo.Org.Id,
  3213. Status: 1,
  3214. Ctime: time.Now().Unix(),
  3215. Mtime: 0,
  3216. Module: 6,
  3217. RecordDate: schedulestartTime,
  3218. Sourse: 1,
  3219. PatientId: patientID,
  3220. }
  3221. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3222. if dialysisFinish.ID == 0 {
  3223. service.CreateDialysisFinish(finish)
  3224. }
  3225. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3226. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3227. //统计该患者总次数
  3228. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3229. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3230. }
  3231. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3232. //统计该患者总次数
  3233. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3234. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3235. }
  3236. redis := service.RedisClient()
  3237. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3238. redis.Set(key, "", time.Second)
  3239. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3240. //清空key 值
  3241. redis.Set(keyOne, "", time.Second)
  3242. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3243. //清空key 值
  3244. redis.Set(keyTwo, "", time.Second)
  3245. if createErr != nil {
  3246. this.ErrorLog("上机失败:%v", createErr)
  3247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3248. return
  3249. }
  3250. }
  3251. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3252. var tempdispose string
  3253. // 只针对中能建
  3254. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3255. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3256. }
  3257. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3258. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3259. }
  3260. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3261. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3262. //}
  3263. var ultrafiltration_rate float64
  3264. var ultrafiltration_rate_one string
  3265. var replacement_rate float64
  3266. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3267. //后期预增脱水量
  3268. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3269. if prescription.ID > 0 {
  3270. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3271. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3272. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3273. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3274. }
  3275. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3276. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3277. }
  3278. //针对医师汇
  3279. if adminUserInfo.Org.Id == 10121 {
  3280. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3281. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3282. }
  3283. //针对通道
  3284. if adminUserInfo.Org.Id == 10234 {
  3285. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3286. }
  3287. //针对监利大垸医院
  3288. if template.TemplateId == 41 {
  3289. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3290. }
  3291. //针对肇庆三鹤血液透析中心
  3292. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3293. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3294. }
  3295. if adminUserInfo.Org.Id == 10469 {
  3296. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3297. }
  3298. if adminUserInfo.Org.Id == 10667 {
  3299. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3300. }
  3301. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3302. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3303. }
  3304. // 只针对方济医院
  3305. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3306. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3307. ultrafiltration_rate = value
  3308. }
  3309. //针对
  3310. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3311. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3312. ultrafiltration_rate = ultrafiltration_rate / 1000
  3313. }
  3314. if adminUserInfo.Org.Id == 10551 {
  3315. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3316. ultrafiltration_rate = ultrafiltration_rate / 1000
  3317. }
  3318. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3319. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3320. ultrafiltration_rate = ultrafiltration_rate / 1000
  3321. }
  3322. if adminUserInfo.Org.Id == 10580 {
  3323. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3324. ultrafiltration_rate = ultrafiltration_rate / 1000
  3325. }
  3326. if adminUserInfo.Org.Id == 10629 {
  3327. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3328. ultrafiltration_rate = ultrafiltration_rate / 1000
  3329. }
  3330. if adminUserInfo.Org.Id == 10644 {
  3331. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3332. ultrafiltration_rate = ultrafiltration_rate / 1000
  3333. }
  3334. if adminUserInfo.Org.Id == 10667 {
  3335. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3336. ultrafiltration_rate = ultrafiltration_rate / 1000
  3337. }
  3338. if adminUserInfo.Org.Id == 10693 {
  3339. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3340. ultrafiltration_rate = ultrafiltration_rate
  3341. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3342. }
  3343. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3344. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3345. ultrafiltration_rate = ultrafiltration_rate
  3346. }
  3347. if adminUserInfo.Org.Id == 10702 {
  3348. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3349. ultrafiltration_rate = ultrafiltration_rate / 1000
  3350. }
  3351. if adminUserInfo.Org.Id == 10723 {
  3352. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3353. ultrafiltration_rate = ultrafiltration_rate / 1000
  3354. }
  3355. if adminUserInfo.Org.Id == 10721 {
  3356. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3357. ultrafiltration_rate = ultrafiltration_rate / 1000
  3358. }
  3359. }
  3360. }
  3361. record := models.MonitoringRecord{
  3362. UserOrgId: adminUserInfo.Org.Id,
  3363. PatientId: patientID,
  3364. DialysisOrderId: dialysisRecord.ID,
  3365. MonitoringDate: schedulestartTime,
  3366. OperateTime: startDate.Unix(),
  3367. // MonitoringTime: recordTime,
  3368. MonitoringNurse: nurseID,
  3369. Dispose: tempdispose,
  3370. UltrafiltrationRate: ultrafiltration_rate,
  3371. UltrafiltrationVolume: 0,
  3372. Status: 1,
  3373. CreatedTime: time.Now().Unix(),
  3374. UpdatedTime: time.Now().Unix(),
  3375. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3376. ReplacementRate: replacement_rate,
  3377. }
  3378. //只针对广慈医院
  3379. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3380. // 查询病人是否有透前评估数据
  3381. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3382. //如果有数据就插入
  3383. if errcode == nil {
  3384. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3385. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3386. record.BreathingRate = befor.BreathingRate
  3387. record.PulseFrequency = befor.PulseFrequency
  3388. record.Temperature = befor.Temperature
  3389. }
  3390. }
  3391. //孝昌
  3392. if adminUserInfo.Org.Id == 10693 {
  3393. // 查询病人是否有透前评估数据
  3394. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3395. //如果有数据就插入
  3396. if errcode == nil {
  3397. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3398. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3399. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3400. record.BreathingRate = befor.BreathingRate
  3401. }
  3402. }
  3403. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3404. if newdialysisRecord.ID > 0 {
  3405. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3406. record.Temperature = 36.5
  3407. record.ArterialPressure = -100
  3408. record.DialysateTemperature = 36.5
  3409. record.Conductivity = 14
  3410. record.BreathingRate = "20"
  3411. record.VenousPressure = 80
  3412. record.TransmembranePressure = 60
  3413. record.Dispose = catheter_operation
  3414. }
  3415. //针对新化博翔
  3416. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3417. record.BloodOxygenSaturation = "99"
  3418. record.Conductivity = 14
  3419. record.DialysateTemperature = 36.5
  3420. record.BreathingRate = "20"
  3421. }
  3422. //针对兰溪人民医院的需求
  3423. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3424. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3425. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3426. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3427. record.Temperature = befor.Temperature
  3428. record.PulseFrequency = befor.PulseFrequency
  3429. record.BreathingRate = befor.BreathingRate
  3430. }
  3431. //针对乐山友谊医院的需求
  3432. if adminUserInfo.Org.Id == 10677 {
  3433. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3434. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3435. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3436. record.Temperature = befor.Temperature
  3437. record.PulseFrequency = befor.PulseFrequency
  3438. record.BreathingRate = befor.BreathingRate
  3439. }
  3440. //新化博翔
  3441. if adminUserInfo.Org.Id == 10447 {
  3442. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3443. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3444. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3445. record.BreathingRate = befor.BreathingRate
  3446. }
  3447. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3448. record.PulseFrequency = 80
  3449. record.Temperature = 36.5
  3450. }
  3451. //诊断灵山圣康
  3452. if adminUserInfo.Org.Id == 10375 {
  3453. record.Conductivity = 13.8
  3454. record.DialysateTemperature = 37
  3455. record.DialysateFlow = 500
  3456. record.BloodFlowVolume = 200
  3457. record.BreathingRate = "18"
  3458. record.SodiumConcentration = 140
  3459. }
  3460. //江成肾病医院
  3461. if adminUserInfo.Org.Id == 10517 {
  3462. record.SodiumConcentration = 138
  3463. record.DialysateTemperature = 36.5
  3464. }
  3465. //濉溪杏康血液透析中心
  3466. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3467. record.BloodFlowVolume = prescription.BloodFlowVolume
  3468. }
  3469. if adminUserInfo.Org.Id != 10683 {
  3470. err = service.CreateMonitor(&record)
  3471. }
  3472. //记录日志
  3473. byterequest, _ := json.Marshal(record)
  3474. monitorRecordLog := models.XtMonitorRecordLog{
  3475. RecordDate: record.MonitoringDate,
  3476. PatientId: record.PatientId,
  3477. Module: 1,
  3478. AdminUserId: adminUserInfo.AdminUser.Id,
  3479. Ctime: time.Now().Unix(),
  3480. Mtime: 0,
  3481. Status: 1,
  3482. UserOrgId: record.UserOrgId,
  3483. ErrLog: string(byterequest),
  3484. Source: "执行上机时新增监测",
  3485. }
  3486. service.CreateMonitorRecordLog(monitorRecordLog)
  3487. finish := models.XtDialysisFinish{
  3488. IsFinish: 1,
  3489. UserOrgId: adminUserInfo.Org.Id,
  3490. Status: 1,
  3491. Ctime: time.Now().Unix(),
  3492. Mtime: 0,
  3493. Module: 7,
  3494. RecordDate: schedulestartTime,
  3495. Sourse: 1,
  3496. PatientId: patientID,
  3497. }
  3498. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3499. if dialysisFinish.ID == 0 {
  3500. service.CreateDialysisFinish(finish)
  3501. }
  3502. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3503. redis := service.RedisClient()
  3504. //清空key 值
  3505. redis.Set(key, "", time.Second)
  3506. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3507. redis.Set(keyOne, "", time.Second)
  3508. defer redis.Close()
  3509. if err != nil {
  3510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3511. return
  3512. }
  3513. }
  3514. go func() {
  3515. ssoDomain := beego.AppConfig.String("call_domain")
  3516. api := ssoDomain + "/index/uppatient"
  3517. values := make(url.Values)
  3518. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3519. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3520. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3521. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3522. http.PostForm(api, values)
  3523. }()
  3524. this.ServeSuccessJSON(map[string]interface{}{
  3525. "dialysis_order": newdialysisRecord,
  3526. "monitor": record,
  3527. })
  3528. return
  3529. }
  3530. func (c *DialysisAPIController) PostSolution() {
  3531. id, _ := c.GetInt64("patient", 0)
  3532. recordDateStr := c.GetString("record_date")
  3533. if id <= 0 {
  3534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3535. return
  3536. }
  3537. adminUserInfo := c.GetMobileAdminUserInfo()
  3538. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3539. if patient.ID == 0 {
  3540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3541. return
  3542. }
  3543. if len(recordDateStr) == 0 {
  3544. recordDateStr = time.Now().Format("2006-01-02")
  3545. }
  3546. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3547. if parseDateErr != nil {
  3548. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. mode_id, _ := c.GetInt64("mode_id", 0)
  3553. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3554. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3555. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3556. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3557. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3558. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3559. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3560. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3561. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3562. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3563. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3564. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3565. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3566. kalium, _ := c.GetFloat("kalium", 0)
  3567. sodium, _ := c.GetFloat("sodium", 0)
  3568. calcium, _ := c.GetFloat("calcium", 0)
  3569. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3570. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3571. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3572. glucose, _ := c.GetFloat("glucose", 0)
  3573. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3574. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3575. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3576. conductivity, _ := c.GetFloat("conductivity", 0)
  3577. remark := c.GetString("remark")
  3578. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3579. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3580. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3581. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3582. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3583. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3584. special_medicine_other := c.GetString("special_medicine_other")
  3585. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3586. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3587. blood_access, _ := c.GetInt64("blood_access", 0)
  3588. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3589. body_fluid_other := c.GetString("body_fluid_other")
  3590. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3591. niprocart, _ := c.GetInt64("niprocart", 0)
  3592. jms, _ := c.GetInt64("jms", 0)
  3593. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3594. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3595. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3596. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3597. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3598. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3599. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3600. injector, _ := c.GetInt64("injector", 0)
  3601. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3602. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3603. safe_package, _ := c.GetInt64("package", 0)
  3604. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3605. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3606. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3607. blood := c.GetString("blood")
  3608. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3609. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3610. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3611. displace_speed := c.GetString("displace_speed")
  3612. illness, _ := c.GetInt64("illness")
  3613. amylaceum := c.GetString("amylaceum")
  3614. single_time := c.GetString("single_time")
  3615. single_water := c.GetString("single_water")
  3616. replacement_flow := c.GetString("replacement_flow")
  3617. plasma_separator := c.GetString("plasma_separator")
  3618. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3619. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3620. oxygen_flow := c.GetString("oxygen_flow")
  3621. oxygen_time := c.GetString("oxygen_time")
  3622. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3623. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3624. puncture_needle := c.GetString("puncture_needle")
  3625. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3626. epo := c.GetString("epo")
  3627. epo_count, _ := c.GetFloat("epo_count", 0)
  3628. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3629. pre_impulse := c.GetString("pre_impulse")
  3630. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3631. admin_user_id, _ := c.GetInt64("admin_user_id")
  3632. is_water := c.GetString("is_water")
  3633. add_amount, _ := c.GetFloat("add_amount")
  3634. reduce_amount, _ := c.GetFloat("reduce_amount")
  3635. prescribing_number, _ := c.GetFloat("prescribing_number")
  3636. treatment_remark := c.GetString("treatment_remark")
  3637. prescription_sodium := c.GetString("prescription_sodium")
  3638. start_sodium := c.GetString("start_sodium")
  3639. sodium_curve := c.GetString("sodium_curve")
  3640. var is_war int64
  3641. if is_water == "是" {
  3642. is_war = 1
  3643. }
  3644. if is_water == "否" {
  3645. is_war = 2
  3646. }
  3647. if is_water == "请选择" {
  3648. is_war = 0
  3649. }
  3650. drhy_water := c.GetString("drhy_water")
  3651. dry_water_hour := c.GetString("dry_water_hour")
  3652. water_machine := c.GetString("water_machine")
  3653. dialysis_remark := c.GetString("dialysis_remark")
  3654. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3655. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3656. prescription_water, _ := c.GetFloat("prescription_water")
  3657. dialysis_strainer := c.GetString("dialysis_strainer")
  3658. chaptalization := c.GetString("chaptalization")
  3659. washing_time := c.GetString("washing_time")
  3660. warsh_count := c.GetString("warsh_count")
  3661. blood_access_part_id := c.GetString("blood_access_part_id")
  3662. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3663. dialyzate := c.GetString("dialyzate")
  3664. if mode_id > 0 {
  3665. var str string
  3666. //查找该机构用的是什么透析器
  3667. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3668. if filedConfig.ID > 0 {
  3669. str = dialyzerPerfusionApparatus
  3670. } else {
  3671. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3672. }
  3673. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3674. }
  3675. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3676. //
  3677. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3678. // if appRole.UserType == 3 {
  3679. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3680. // if getPermissionErr != nil {
  3681. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3682. // return
  3683. // } else if headNursePermission == nil {
  3684. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3685. // return
  3686. // }
  3687. // }
  3688. //}
  3689. // 查询信息规挡的设置天数
  3690. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3691. if infor.ID > 0 && infor.WeekDay > 0 {
  3692. var cha_time int64
  3693. timeNowStr := time.Now().Format("2006-01-02")
  3694. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3695. //今日的日期减去设置的日期
  3696. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3697. if cha_time >= recordDate.Unix() {
  3698. //查询审核是否允许
  3699. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3700. //申请状态不允许的情况 拒绝修改
  3701. if infor.ApplicationStatus != 1 {
  3702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3703. return
  3704. }
  3705. }
  3706. }
  3707. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3708. var dialysis_dialyszers_id int64
  3709. var dialysis_strainer_id int64
  3710. var dialysis_irrigation_id int64
  3711. if len(goodList) > 0 {
  3712. for _, item := range goodList {
  3713. if item.SpecificationName == dialysis_dialyszers {
  3714. dialysis_dialyszers_id = item.ID
  3715. }
  3716. if item.SpecificationName == dialysis_irrigation {
  3717. dialysis_irrigation_id = item.ID
  3718. }
  3719. if item.SpecificationName == dialysis_strainer {
  3720. dialysis_strainer_id = item.ID
  3721. }
  3722. }
  3723. }
  3724. prescription := models.DialysisPrescription{
  3725. UserOrgId: adminUserInfo.Org.Id,
  3726. PatientId: id,
  3727. RecordDate: recordDate.Unix(),
  3728. ModeId: mode_id,
  3729. DialysisDuration: dialysis_duration,
  3730. Dialyzer: dialyzer,
  3731. PerfusionApparatus: perfusion_apparatus,
  3732. BloodFlowVolume: blood_flow_volume,
  3733. DewaterAmount: dewater_amount,
  3734. DisplaceLiqui: displace_liqui,
  3735. ReplacementWay: replacement_way,
  3736. Anticoagulant: anticoagulant,
  3737. AnticoagulantShouji: anticoagulant_shouji,
  3738. AnticoagulantWeichi: anticoagulant_weichi,
  3739. AnticoagulantZongliang: anticoagulant_zongliang,
  3740. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3741. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3742. Kalium: kalium,
  3743. Sodium: sodium,
  3744. Calcium: calcium,
  3745. Bicarbonate: bicarbonate,
  3746. Glucose: glucose,
  3747. // DryWeight: dry_weight,
  3748. DialysateFlow: dialysate_flow,
  3749. DialysateTemperature: dialysate_temperature,
  3750. Conductivity: conductivity,
  3751. Remark: remark,
  3752. Status: 1,
  3753. CreatedTime: time.Now().Unix(),
  3754. UpdatedTime: time.Now().Unix(),
  3755. DialysisDurationMinute: dialysisDurationMinute,
  3756. DialysisDurationHour: dialysisDurationHour,
  3757. TargetUltrafiltration: targetUltrafiltration,
  3758. DialysateFormulation: dialysateFormulation,
  3759. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3760. BodyFluid: body_fluid,
  3761. SpecialMedicine: special_medicine,
  3762. SpecialMedicineOther: special_medicine_other,
  3763. DisplaceLiquiPart: displace_liqui_part,
  3764. DisplaceLiquiValue: displace_liqui_value,
  3765. BloodAccess: blood_access,
  3766. Ultrafiltration: ultrafiltration,
  3767. BodyFluidOther: body_fluid_other,
  3768. ReplacementTotal: replacement_total,
  3769. Niprocart: niprocart,
  3770. Jms: jms,
  3771. FistulaNeedleSet: fistula_needle_set,
  3772. FistulaNeedleSet16: fistula_needle_set_16,
  3773. Hemoperfusion: hemoperfusion,
  3774. DialyserSterilised: dialyser_sterilised,
  3775. Filtryzer: filtryzer,
  3776. TargetKtv: target_ktv,
  3777. Dialyzers: dialyzers,
  3778. Injector: injector,
  3779. Bloodlines: bloodlines,
  3780. TubingHemodialysis: tubing_hemodialysis,
  3781. Package: safe_package,
  3782. ALiquid: a_liquid,
  3783. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3784. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3785. Blood: blood,
  3786. DialysisDialyszers: dialysis_dialyszers,
  3787. DialysisIrrigation: dialysis_irrigation,
  3788. AntioxidantCommodityName: antioxidant_commodity_name,
  3789. DisplaceSpeed: displace_speed,
  3790. Illness: illness,
  3791. Amylaceum: amylaceum,
  3792. SingleWater: single_water,
  3793. SingleTime: single_time,
  3794. ReplacementFlow: replacement_flow,
  3795. PlasmaSeparator: plasma_separator,
  3796. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3797. OxygenUptake: oxygen_uptake,
  3798. OxygenTime: oxygen_time,
  3799. OxygenFlow: oxygen_flow,
  3800. HemodialysisPipelines: hemodialysis_pipelines,
  3801. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3802. PunctureNeedle: puncture_needle,
  3803. PunctureNeedleCount: puncture_needle_count,
  3804. Epo: epo,
  3805. EpoCount: epo_count,
  3806. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3807. PreImpulse: impulse,
  3808. AdminUserId: admin_user_id,
  3809. IsWater: is_war,
  3810. DrhyWater: drhy_water,
  3811. DryWaterHour: dry_water_hour,
  3812. WaterMachine: water_machine,
  3813. AddAmount: add_amount,
  3814. ReduceAmount: reduce_amount,
  3815. DialysisRemark: dialysis_remark,
  3816. PrescribingNumber: prescribing_number,
  3817. PrescriptionSodium: prescription_sodium,
  3818. StartSodium: start_sodium,
  3819. SodiumCurve: sodium_curve,
  3820. TreatmentRemark: treatment_remark,
  3821. DialysisFluidFlow: dialysis_fluid_flow,
  3822. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3823. PrescriptionWater: prescription_water,
  3824. DialysisStrainer: dialysis_strainer,
  3825. Chaptalization: chaptalization,
  3826. WashingTime: washing_time,
  3827. WarshCount: warsh_count,
  3828. BloodAccessPartId: blood_access_part_id,
  3829. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3830. Dialyzate: dialyzate,
  3831. DialysisDialyszersId: dialysis_dialyszers_id,
  3832. DialysisIrrigationId: dialysis_irrigation_id,
  3833. DialysisStrainerId: dialysis_strainer_id,
  3834. }
  3835. if adminUserInfo.Org.Id == 10721 {
  3836. if prescription.ModeId == 2 {
  3837. if prescription.ReplacementTotal == 0 {
  3838. prescription.ReplacementTotal = 15
  3839. }
  3840. }
  3841. }
  3842. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3843. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3844. //
  3845. if appRole.UserType == 2 || appRole.UserType == 1 {
  3846. prescription_doctor = adminUserInfo.AdminUser.Id
  3847. prescription.PrescriptionDoctor = prescription_doctor
  3848. }
  3849. if dialysisPrescription.ID == 0 { //新增
  3850. prescription.Creater = adminUserInfo.AdminUser.Id
  3851. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3852. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3853. }
  3854. } else { //修改
  3855. if dialysisPrescription.Creater == 0 {
  3856. prescription.Creater = adminUserInfo.AdminUser.Id
  3857. } else {
  3858. prescription.Creater = dialysisPrescription.Creater
  3859. if adminUserInfo.Org.Id == 9882 {
  3860. if appRole.UserType == 2 || appRole.UserType == 1 {
  3861. prescription.Creater = adminUserInfo.AdminUser.Id
  3862. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3863. }
  3864. }
  3865. }
  3866. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3867. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3868. }
  3869. //if/**/
  3870. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3871. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3872. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3873. // if getPermissionErr != nil {
  3874. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3875. // return
  3876. // } else if headNursePermission == nil {
  3877. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3878. // return
  3879. // }
  3880. //}
  3881. //prescription.Creater = dialysisPrescription.Creater
  3882. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3883. prescription.Modifier = adminUserInfo.AdminUser.Id
  3884. prescription.ID = dialysisPrescription.ID
  3885. }
  3886. solution := models.DialysisSolution{
  3887. RegistrarsId: adminUserInfo.AdminUser.Id,
  3888. UserOrgId: adminUserInfo.Org.Id,
  3889. Doctor: prescription_doctor,
  3890. PatientId: id,
  3891. ModeId: mode_id,
  3892. DialysisDuration: dialysis_duration,
  3893. PerfusionApparatus: perfusion_apparatus,
  3894. BloodFlowVolume: blood_flow_volume,
  3895. Dewater: dewater_amount,
  3896. DisplaceLiqui: displace_liqui,
  3897. ReplacementWay: replacement_way,
  3898. Anticoagulant: anticoagulant,
  3899. AnticoagulantShouji: anticoagulant_shouji,
  3900. AnticoagulantWeichi: anticoagulant_weichi,
  3901. AnticoagulantZongliang: anticoagulant_zongliang,
  3902. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3903. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3904. Kalium: kalium,
  3905. Sodium: sodium,
  3906. Calcium: calcium,
  3907. Bicarbonate: bicarbonate,
  3908. Glucose: glucose,
  3909. // DryWeight: dry_weight,
  3910. DialysateFlow: dialysate_flow,
  3911. DialysateTemperature: dialysate_temperature,
  3912. Conductivity: conductivity,
  3913. Remark: remark,
  3914. Status: 1,
  3915. CreatedTime: time.Now().Unix(),
  3916. UpdatedTime: time.Now().Unix(),
  3917. DialysisDurationMinute: dialysisDurationMinute,
  3918. DialysisDurationHour: dialysisDurationHour,
  3919. TargetUltrafiltration: targetUltrafiltration,
  3920. DialysateFormulation: dialysateFormulation,
  3921. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3922. BodyFluid: body_fluid,
  3923. SpecialMedicine: special_medicine,
  3924. SpecialMedicineOther: special_medicine_other,
  3925. DisplaceLiquiPart: displace_liqui_part,
  3926. DisplaceLiquiValue: displace_liqui_value,
  3927. BloodAccess: blood_access,
  3928. Ultrafiltration: ultrafiltration,
  3929. BodyFluidOther: body_fluid_other,
  3930. ReplacementTotal: replacement_total,
  3931. TargetKtv: target_ktv,
  3932. DialysisDialyszers: dialysis_dialyszers,
  3933. DialysisIrrigation: dialysis_irrigation,
  3934. HemodialysisPipelines: hemodialysis_pipelines,
  3935. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3936. PunctureNeedle: puncture_needle,
  3937. PunctureNeedleCount: puncture_needle_count,
  3938. Epo: epo,
  3939. EpoCount: epo_count,
  3940. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3941. PreImpulse: impulse,
  3942. SolutionStatus: 1,
  3943. DialysisRemark: dialysis_remark,
  3944. PrescribingNumber: prescribing_number,
  3945. PrescriptionSodium: prescription_sodium,
  3946. StartSodium: start_sodium,
  3947. SodiumCurve: sodium_curve,
  3948. TreatmentRemark: treatment_remark,
  3949. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3950. DialysisFluidFlow: dialysis_fluid_flow,
  3951. PrescriptionWater: prescription_water,
  3952. DialysisStrainer: dialysis_strainer,
  3953. Chaptalization: chaptalization,
  3954. WashingTime: washing_time,
  3955. WarshCount: warsh_count,
  3956. BloodAccessPartId: blood_access_part_id,
  3957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3958. Dialyzate: dialyzate,
  3959. DialysisDialyszersId: dialysis_dialyszers_id,
  3960. DialysisIrrigationId: dialysis_irrigation_id,
  3961. DialysisStrainerId: dialysis_strainer_id,
  3962. }
  3963. //针对河间咸的
  3964. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3965. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3966. solution.DisplaceLiquiPart = 0
  3967. solution.DisplaceLiquiValue = 0
  3968. }
  3969. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3970. prescription.DisplaceLiquiPart = 0
  3971. prescription.DisplaceLiquiValue = 0
  3972. }
  3973. }
  3974. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3975. if solution.PrescribingNumber == 0 {
  3976. solution.PrescribingNumber = 1
  3977. }
  3978. if prescription.PrescribingNumber == 0 {
  3979. prescription.PrescribingNumber = 1
  3980. }
  3981. if solution.PrescribingNumber == 0 && id == 14682 {
  3982. solution.PrescribingNumber = 2
  3983. }
  3984. if solution.PrescribingNumber == 0 && id == 18560 {
  3985. solution.PrescribingNumber = 2
  3986. }
  3987. if prescription.PrescribingNumber == 0 && id == 14682 {
  3988. prescription.PrescribingNumber = 2
  3989. }
  3990. if prescription.PrescribingNumber == 0 && id == 18560 {
  3991. prescription.PrescribingNumber = 2
  3992. }
  3993. }
  3994. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3995. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3996. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3997. if len(monitorList) > 0 {
  3998. var ultrafiltration_rate float64
  3999. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4000. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4001. var replacement_rate float64
  4002. //乘10 除10是为了保留一位小数
  4003. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4004. var firstOpeateTime = monitorList[0].OperateTime
  4005. for _, item := range monitorList {
  4006. //超滤率
  4007. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4008. //置换率
  4009. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4010. //超滤量
  4011. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4012. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4013. //置换量
  4014. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4015. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4016. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4017. }
  4018. }
  4019. }
  4020. //记录日志
  4021. byterequest, _ := json.Marshal(prescription)
  4022. prescriptionLog := models.XtDialysisPrescriptionLog{
  4023. UserOrgId: prescription.UserOrgId,
  4024. Ctime: time.Now().Unix(),
  4025. Mtime: 0,
  4026. ErrLog: string(byterequest),
  4027. AdminUserId: adminUserInfo.AdminUser.Id,
  4028. RecordDate: prescription.RecordDate,
  4029. PatientId: prescription.PatientId,
  4030. Source: "手机端新增长期处方",
  4031. Status: 1,
  4032. }
  4033. service.CreatePrescriptionLog(prescriptionLog)
  4034. finish := models.XtDialysisFinish{
  4035. IsFinish: 1,
  4036. UserOrgId: adminUserInfo.Org.Id,
  4037. Status: 1,
  4038. Ctime: time.Now().Unix(),
  4039. Mtime: 0,
  4040. Module: 1,
  4041. RecordDate: recordDate.Unix(),
  4042. Sourse: 1,
  4043. PatientId: id,
  4044. }
  4045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4046. if dialysisFinish.ID == 0 {
  4047. service.CreateDialysisFinish(finish)
  4048. }
  4049. //获取最新1条
  4050. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4051. //更新状态
  4052. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4053. //长沙南雅医院,自动生成抗凝剂的临时处方
  4054. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4055. if prescribing_number == 0 {
  4056. prescribing_number = 1
  4057. }
  4058. advice := models.DoctorAdvice{
  4059. UserOrgId: adminUserInfo.Org.Id,
  4060. PatientId: id,
  4061. GroupNo: 0,
  4062. AdviceType: 2,
  4063. RecordDate: recordDate.Unix(),
  4064. AdviceDate: recordDate.Unix(),
  4065. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4066. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4067. AdviceDesc: "",
  4068. ReminderDate: 0,
  4069. SingleDose: prescription.AnticoagulantZongliang,
  4070. SingleDoseUnit: "iu",
  4071. DrugSpec: 0,
  4072. DrugSpecUnit: "",
  4073. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4074. PrescribingNumberUnit: "支",
  4075. DeliveryWay: "静脉注射",
  4076. ExecutionFrequency: "上机前",
  4077. AdviceDoctor: 0,
  4078. Status: 1,
  4079. CreatedTime: time.Now().Unix(),
  4080. UpdatedTime: time.Now().Unix(),
  4081. IsPrescription: 1,
  4082. ExecutionState: 2,
  4083. StopState: 2,
  4084. IsSettle: 2,
  4085. }
  4086. // 查询排班信息
  4087. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4088. if schedulePatient.ID > 0 {
  4089. if schedulePatient.ScheduleType == 1 {
  4090. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4091. }
  4092. if schedulePatient.ScheduleType == 2 {
  4093. advice.StartTime = recordDate.Unix() + 9*60*60
  4094. }
  4095. }
  4096. // 抗凝剂名称
  4097. switch anticoagulant {
  4098. case 1:
  4099. advice.AdviceName = "无肝素"
  4100. break
  4101. case 2:
  4102. advice.AdviceName = "普通肝素"
  4103. break
  4104. case 3:
  4105. advice.AdviceName = "低分子肝素"
  4106. break
  4107. case 4:
  4108. advice.AdviceName = "阿加曲班"
  4109. break
  4110. case 5:
  4111. advice.AdviceName = "枸橼酸钠"
  4112. break
  4113. case 6:
  4114. advice.AdviceName = "低分子肝素钙"
  4115. break
  4116. case 7:
  4117. advice.AdviceName = "低分子肝素钠"
  4118. break
  4119. case 8:
  4120. advice.AdviceName = "依诺肝素"
  4121. break
  4122. case 9:
  4123. advice.AdviceName = "达肝素"
  4124. break
  4125. case 10:
  4126. advice.AdviceName = "体外抗凝"
  4127. break
  4128. case 11:
  4129. advice.AdviceName = "那曲肝素"
  4130. break
  4131. case 12:
  4132. advice.AdviceName = "无抗凝剂"
  4133. break
  4134. }
  4135. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4136. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4137. advice.AdviceDoctor = appRole.AdminUserId
  4138. }
  4139. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4140. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4141. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4142. advice.AdviceName = "低分子肝素钠注射液"
  4143. // 修改患者临时医嘱里的抗凝剂医嘱
  4144. advice.ID = advicePrescription.ID
  4145. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4146. } else {
  4147. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4148. advice.AdviceName = "低分子肝素钠注射液"
  4149. service.CreateDoctorAdvice(&advice)
  4150. }
  4151. }
  4152. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4153. redis := service.RedisClient()
  4154. defer redis.Close()
  4155. //清空key 值
  4156. redis.Set(key, "", time.Second)
  4157. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4158. redis.Set(keyOne, "", time.Second)
  4159. }
  4160. //获取key,清空redis
  4161. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4162. redis := service.RedisClient()
  4163. defer redis.Close()
  4164. //清空key 值
  4165. redis.Set(key, "", time.Second)
  4166. //清空长期医嘱的key
  4167. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4168. redis.Set(soulution_key, "", time.Second)
  4169. //查询最近透析准备表里是否存在 透析器 灌流器
  4170. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4171. redis.Set(keyOne, "", time.Second)
  4172. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4173. redis.Set(keyTwo, "", time.Second)
  4174. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4175. redis.Set(keyThree, "", time.Second)
  4176. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4177. redis.Set(keyFour, "", time.Second)
  4178. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4179. //
  4180. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4181. //
  4182. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4183. //if len(mation)>0{
  4184. // for _, item := range splitStr {
  4185. // for _,it := range mation{
  4186. // if(item == it.SpecificationName){
  4187. //
  4188. // //查询最近一次的透析器
  4189. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4190. //
  4191. // if errcode == gorm.ErrRecordNotFound{
  4192. // //插入数据
  4193. // prepare := models.DialysisBeforePrepare{
  4194. // UserOrgId: adminUserInfo.Org.Id,
  4195. // PatientId: id,
  4196. // RecordDate: recordDate.Unix(),
  4197. // GoodTypeId: it.GoodTypeId,
  4198. // GoodId: it.ID,
  4199. // Count: 1,
  4200. // Ctime: time.Now().Unix(),
  4201. // Creater: adminUserInfo.AdminUser.Id,
  4202. // Status:1,
  4203. //
  4204. // }
  4205. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4206. // fmt.Println("",errcode)
  4207. // }
  4208. // }
  4209. // }
  4210. //
  4211. // }
  4212. //
  4213. // for _, item := range splitIrrigation {
  4214. // for _,it := range mation{
  4215. // if(item == it.SpecificationName){
  4216. // //查询最近一次的透析器
  4217. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4218. // if errcode == gorm.ErrRecordNotFound{
  4219. // //插入数据
  4220. // prepare := models.DialysisBeforePrepare{
  4221. // UserOrgId: adminUserInfo.Org.Id,
  4222. // PatientId: id,
  4223. // RecordDate: recordDate.Unix(),
  4224. // GoodTypeId: it.GoodTypeId,
  4225. // GoodId: it.ID,
  4226. // Count: 1,
  4227. // Ctime: time.Now().Unix(),
  4228. // Creater: adminUserInfo.AdminUser.Id,
  4229. // Status:1,
  4230. //
  4231. // }
  4232. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4233. // fmt.Println(errcode)
  4234. // }
  4235. // }
  4236. // }
  4237. // }
  4238. //}
  4239. c.ServeSuccessJSON(map[string]interface{}{
  4240. "solution": &solution,
  4241. "prescription": &prescription,
  4242. })
  4243. }
  4244. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4245. patient, _ := c.GetInt64("patient", 0)
  4246. adminUserInfo := c.GetMobileAdminUserInfo()
  4247. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4248. c.ServeSuccessJSON(map[string]interface{}{
  4249. "receiveTreatmentAsses": receiveTreatmentAsses,
  4250. })
  4251. }
  4252. func (this *DialysisAPIController) PostSignInfo() {
  4253. patientID, _ := this.GetInt64("patient_id")
  4254. recordDateStr := this.GetString("date")
  4255. if patientID <= 0 {
  4256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4257. return
  4258. }
  4259. if len(recordDateStr) == 0 {
  4260. recordDateStr = time.Now().Format("2006-01-02")
  4261. }
  4262. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4263. if parseDateErr != nil {
  4264. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4266. return
  4267. }
  4268. adminInfo := this.GetMobileAdminUserInfo()
  4269. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4270. if err != nil {
  4271. this.ErrorLog("签名失败:%v", err)
  4272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4273. return
  4274. }
  4275. this.ServeSuccessJSON(map[string]interface{}{
  4276. "doctor_id": adminInfo.AdminUser.Id,
  4277. })
  4278. }
  4279. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4280. patientID, _ := this.GetInt64("patient_id")
  4281. adminInfo := this.GetMobileAdminUserInfo()
  4282. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4283. this.ServeSuccessJSON(map[string]interface{}{
  4284. "monitor": record,
  4285. })
  4286. }
  4287. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4288. thisTime := time.Now()
  4289. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4290. timeLayout := "2006-01-02 15:04:05"
  4291. loc, _ := time.LoadLocation("Local")
  4292. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4293. theAssessmentDateTime := theStartTime.Unix()
  4294. patientID, _ := this.GetInt64("patient_id")
  4295. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4296. adminInfo := this.GetMobileAdminUserInfo()
  4297. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4298. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4299. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4300. var ultrafiltration_rate float64
  4301. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4302. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4303. fmt.Println(evaluation)
  4304. fmt.Println("prescription.ID", prescription.ID)
  4305. if prescription.ID > 0 {
  4306. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4307. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4308. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4309. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4310. record.UltrafiltrationRate = ultrafiltration_rate
  4311. }
  4312. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4313. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4314. record.UltrafiltrationRate = ultrafiltration_rate
  4315. }
  4316. if adminInfo.Org.Id == 10510 {
  4317. record.UltrafiltrationRate = 0
  4318. }
  4319. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4320. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4321. record.UltrafiltrationRate = ultrafiltration_rate
  4322. }
  4323. if template.TemplateId == 20 || template.TemplateId == 22 {
  4324. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4325. record.UltrafiltrationRate = ultrafiltration_rate
  4326. }
  4327. // 只针对方济医院
  4328. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4329. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4330. ultrafiltration_rate = value
  4331. record.UltrafiltrationRate = ultrafiltration_rate
  4332. }
  4333. if template.TemplateId == 41 || template.TemplateId == 47 {
  4334. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4335. record.UltrafiltrationRate = ultrafiltration_rate
  4336. }
  4337. if template.TemplateId == 43 {
  4338. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4339. record.UltrafiltrationRate = ultrafiltration_rate
  4340. }
  4341. if template.TemplateId == 46 || template.TemplateId == 54 {
  4342. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4343. record.UltrafiltrationRate = ultrafiltration_rate
  4344. }
  4345. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4346. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4347. record.UltrafiltrationRate = ultrafiltration_rate
  4348. }
  4349. if adminInfo.Org.Id == 10469 {
  4350. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4351. record.UltrafiltrationRate = ultrafiltration_rate
  4352. }
  4353. if adminInfo.Org.Id == 10667 {
  4354. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4355. record.UltrafiltrationRate = ultrafiltration_rate
  4356. }
  4357. if adminInfo.Org.Id == 10471 {
  4358. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4359. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4360. }
  4361. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4362. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4363. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4364. }
  4365. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4366. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4367. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4368. }
  4369. if adminInfo.Org.Id == 10721 {
  4370. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4371. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4372. }
  4373. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4374. record.UltrafiltrationRate = 0
  4375. }
  4376. //if template.TemplateId == 47 {
  4377. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4378. // record.UltrafiltrationRate = ultrafiltration_rate
  4379. //}
  4380. }
  4381. }
  4382. // record.UltrafiltrationRate = ultrafiltration_rate
  4383. record.UltrafiltrationVolume = 0
  4384. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  4385. if ultrafiltration_rate > 0 {
  4386. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4387. record.UltrafiltrationVolume = value
  4388. }
  4389. }
  4390. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4391. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4392. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4393. record.UltrafiltrationVolume = ultrafiltration_volume
  4394. }
  4395. }
  4396. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4397. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4398. record.UltrafiltrationVolume = ultrafiltration_volume
  4399. }
  4400. //长沙南雅
  4401. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4402. if ultrafiltration_rate > 0 {
  4403. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4404. record.UltrafiltrationVolume = ultrafiltration_volume
  4405. }
  4406. }
  4407. if adminInfo.Org.Id == 10471 {
  4408. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4409. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4410. }
  4411. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4412. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4413. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4414. }
  4415. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4416. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4417. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4418. }
  4419. //长沙南雅累计血容量自动计算
  4420. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4421. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4422. //}
  4423. if template.TemplateId == 47 || template.TemplateId == 54 {
  4424. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4425. }
  4426. if adminInfo.Org.Id == 10510 {
  4427. record.UltrafiltrationVolume = 0
  4428. }
  4429. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 {
  4430. if ultrafiltration_rate > 0 {
  4431. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4432. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4433. }
  4434. }
  4435. if adminInfo.Org.Id == 10721 {
  4436. var replacement_rate float64
  4437. var displacement_quantity float64
  4438. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4439. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4440. fmt.Println("replacement_rate--------------------------", replacement_rate)
  4441. record.ReplacementRate = replacement_rate
  4442. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4443. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4444. record.DisplacementQuantity = displacement_quantity
  4445. }
  4446. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4447. this.ServeSuccessJSON(map[string]interface{}{
  4448. "monitor": record,
  4449. "lastMonitorRecordList": lastMonitorRecordList,
  4450. })
  4451. }
  4452. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4453. record_id, _ := this.GetInt64("id")
  4454. nurseID, _ := this.GetInt64("start_nurse")
  4455. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4456. bedID, _ := this.GetInt64("bed")
  4457. start_time := this.GetString("start_time")
  4458. schedual_type, _ := this.GetInt64("schedual_type")
  4459. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4460. change_nurse, _ := this.GetInt64("change_nurse")
  4461. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4462. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4463. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4464. patient_id, _ := this.GetInt64("patient_id")
  4465. record_date, _ := this.GetInt64("record_date")
  4466. puncture_needle := this.GetString("puncture_needle")
  4467. puncture_way := this.GetString("puncture_way")
  4468. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4469. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4470. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4471. nuclein_date_str := this.GetString("nuclein_date_str")
  4472. order_remark := this.GetString("order_remark")
  4473. schedule_remark := this.GetString("schedule_remark")
  4474. catheter_operation := this.GetString("catheter_operation")
  4475. blood_flow_volume := this.GetString("blood_flow_volume")
  4476. blood_drawing, _ := this.GetInt64("blood_drawing")
  4477. dialysis_strainer := this.GetString("dialysis_strainer")
  4478. if record_id == 0 {
  4479. this.ErrorLog("id:%v", record_id)
  4480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4481. return
  4482. }
  4483. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4484. if parseStartDateErr != nil {
  4485. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4487. return
  4488. }
  4489. adminUserInfo := this.GetMobileAdminUserInfo()
  4490. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4491. if getNurseErr != nil {
  4492. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4494. return
  4495. } else if nurse == nil {
  4496. this.ErrorLog("护士不存在")
  4497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4501. //if getNurseErr != nil {
  4502. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4503. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4504. // return
  4505. //} else if nurse == nil {
  4506. // this.ErrorLog("护士不存在")
  4507. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4508. // return
  4509. //}
  4510. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4511. if getDeviceNumberErr != nil {
  4512. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4514. return
  4515. } else if deviceNumber == nil {
  4516. this.ErrorLog("床位号不存在")
  4517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4518. return
  4519. }
  4520. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4521. //
  4522. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4523. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4524. // if getPermissionErr != nil {
  4525. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4526. // return
  4527. // } else if headNursePermission == nil {
  4528. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4529. // return
  4530. // }
  4531. //}
  4532. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4533. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4534. timeLayout := "2006-01-02 15:04:05"
  4535. loc, _ := time.LoadLocation("Local")
  4536. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4537. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4538. schedulestartTime := theStartTime.Unix()
  4539. scheduleendTime := theEndTime.Unix()
  4540. var theNucleinDate int64
  4541. timeLayoutOne := "2006-01-02"
  4542. if len(nuclein_date_str) > 0 {
  4543. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4544. if err != nil {
  4545. utils.ErrorLog(err.Error())
  4546. }
  4547. theNucleinDate = theTime.Unix()
  4548. }
  4549. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4550. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4551. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4552. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4553. if err == gorm.ErrRecordNotFound { //空床位
  4554. // 修改了床位逻辑
  4555. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4556. if daySchedule.ID > 0 {
  4557. //daySchedule.BedId = bedID
  4558. //daySchedule.PartitionId = deviceNumber.ZoneID
  4559. //daySchedule.ScheduleType = schedual_type
  4560. //daySchedule.UpdatedTime = time.Now().Unix()
  4561. //err := service.UpdateSchedule(&daySchedule)
  4562. xtSchedule := models.Schedule{
  4563. PartitionId: deviceNumber.ZoneID,
  4564. BedId: bedID,
  4565. ScheduleType: schedual_type,
  4566. UpdatedTime: time.Now().Unix(),
  4567. }
  4568. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4569. if err != nil {
  4570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4571. return
  4572. }
  4573. }
  4574. } else if err == nil {
  4575. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4576. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4577. if daySchedule.ID > 0 {
  4578. //daySchedule.BedId = bedID
  4579. //daySchedule.PartitionId = deviceNumber.ZoneID
  4580. //
  4581. //daySchedule.ScheduleType = schedual_type
  4582. //daySchedule.UpdatedTime = time.Now().Unix()
  4583. //err := service.UpdateSchedule(&daySchedule)
  4584. xtSchedule := models.Schedule{
  4585. PartitionId: deviceNumber.ZoneID,
  4586. BedId: bedID,
  4587. ScheduleType: schedual_type,
  4588. UpdatedTime: time.Now().Unix(),
  4589. }
  4590. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4591. if err != nil {
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4593. return
  4594. }
  4595. }
  4596. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4598. return
  4599. }
  4600. } else if err != nil {
  4601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4602. return
  4603. }
  4604. }
  4605. dialysisRecord := &models.DialysisOrder{
  4606. ID: record_id,
  4607. UserOrgId: adminUserInfo.Org.Id,
  4608. BedID: bedID,
  4609. StartNurse: nurseID,
  4610. StartTime: startDate.Unix(),
  4611. PunctureNurse: puncture_nurse,
  4612. Creator: adminUserInfo.AdminUser.Id,
  4613. Modifier: adminUserInfo.AdminUser.Id,
  4614. WashpipeNurse: washpipe_nurse,
  4615. SchedualType: schedual_type,
  4616. ChangeNurse: change_nurse,
  4617. DifficultPunctureNurse: difficult_puncture_nurse,
  4618. NewFistulaNurse: new_fistula_nurse,
  4619. QualityNurseId: quality_nurse_id,
  4620. PunctureNeedle: puncture_needle,
  4621. PunctureWay: puncture_way,
  4622. DialysisDialyszers: dialysis_dialyszers,
  4623. DialysisIrrigation: dialysis_irrigation,
  4624. BloodAccessId: blood_access_id,
  4625. NucleinDate: theNucleinDate,
  4626. OrderRemark: order_remark,
  4627. ScheduleRemark: schedule_remark,
  4628. CatheterOperation: catheter_operation,
  4629. BloodFlowVolume: blood_flow_volume,
  4630. BloodDrawing: blood_drawing,
  4631. DialysisStrainer: dialysis_strainer,
  4632. }
  4633. //修改床位号需要重新消毒
  4634. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4635. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4636. //查询第一条监测
  4637. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4638. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4639. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4640. redis := service.RedisClient()
  4641. //清空key 值
  4642. redis.Set(key, "", time.Second)
  4643. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4644. redis.Set(keyOne, "", time.Second)
  4645. defer redis.Close()
  4646. }
  4647. // 查询信息规挡的设置天数
  4648. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4649. if infor.ID > 0 && infor.WeekDay > 0 {
  4650. var cha_time int64
  4651. timeNowStr := time.Now().Format("2006-01-02")
  4652. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4653. //今日的日期减去设置的日期
  4654. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4655. if cha_time >= record_date {
  4656. //查询审核是否允许
  4657. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4658. //申请状态不允许的情况 拒绝修改
  4659. if infor.ApplicationStatus != 1 {
  4660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4661. return
  4662. }
  4663. }
  4664. }
  4665. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4666. //修改床位后重新生成消毒计划
  4667. if adminUserInfo.Org.Id == 10340 {
  4668. //根据床位号获取设备型号
  4669. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4670. //查询使用消毒最后一条消毒记录
  4671. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4672. fmt.Println("err", err)
  4673. if err == gorm.ErrRecordNotFound {
  4674. //查找排班
  4675. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4676. //查询改设备是否有消毒计划
  4677. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4678. //根据床位号获取设备id
  4679. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4680. //查询病人信息
  4681. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4682. var con = ""
  4683. if patients.IsInfectious == 0 {
  4684. con = ""
  4685. }
  4686. if patients.IsInfectious == 1 {
  4687. con = "无"
  4688. }
  4689. if patients.IsInfectious == 2 {
  4690. con = "有"
  4691. }
  4692. if errcode == nil {
  4693. var end_time int64
  4694. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4695. //新增消毒
  4696. information := models.DeviceInformation{
  4697. Date: dialysisRecord.DialysisDate,
  4698. Zone: dialysisRecord.ZoneId,
  4699. Class: dialysisRecord.SchedualType,
  4700. BedNumber: dialysisRecord.BedID,
  4701. PatientId: dialysisRecord.PatientId,
  4702. DialysisMode: scheduleByPatient.ModeId,
  4703. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4704. Disinfection: 1,
  4705. DialysisConcentration: 1,
  4706. DisinfectionStatus: 1,
  4707. Move: 1,
  4708. UserOrgId: dialysisRecord.UserOrgId,
  4709. DisinfectType: plan.Way,
  4710. DisinfectantType: plan.MachineDisinfectant,
  4711. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4712. Disinfectant: plan.Disinfectant,
  4713. Ctime: time.Now().Unix(),
  4714. Status: 1,
  4715. SignName: nurseID,
  4716. EquimentId: addmacher.ID,
  4717. DisinfectionResidue: 2,
  4718. Bed: addmacher.BedNumber,
  4719. StartTime: dialysisRecord.StartTime,
  4720. EndTime: dialysisRecord.EndTime,
  4721. Contagion: con,
  4722. WeightLoss: 0,
  4723. Hyperfiltratio: 0,
  4724. DialysisHour: "",
  4725. MachineRun: 1,
  4726. DisinfecStartime: dialysisRecord.EndTime,
  4727. DisinfecEndtime: end_time,
  4728. }
  4729. err := service.CreateInformationTwo(&information)
  4730. fmt.Println("报错", err)
  4731. }
  4732. }
  4733. }
  4734. order, _ := service.GetLastPatientOrder(record_id)
  4735. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4736. redis := service.RedisClient()
  4737. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4738. redis.Set(key, "", time.Second)
  4739. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4740. //清空key 值
  4741. redis.Set(keyOne, "", time.Second)
  4742. scheduleDateStartOne := startDate.Format("2006-01-02")
  4743. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4744. redis.Set(keyTwo, "", time.Second)
  4745. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4746. redis.Set(keyThree, "", time.Second)
  4747. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4748. redis.Set(keyFour, "", time.Second)
  4749. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4750. redis.Set(keyFive, "", time.Second)
  4751. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4752. redis.Set(keySix, "", time.Second)
  4753. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4754. redis.Set(keySeven, "", time.Second)
  4755. if updateErr != nil {
  4756. this.ErrorLog("修改上机失败:%v", updateErr)
  4757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4758. return
  4759. }
  4760. if updateErr == nil {
  4761. if tempDialysisRecord.Stage == 2 {
  4762. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4763. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4764. fmt.Println(value)
  4765. a, b := math.Modf(value)
  4766. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4767. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4768. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4769. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4770. redis := service.RedisClient()
  4771. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4772. redis.Set(key, "", time.Second)
  4773. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4774. redis.Set(keyOne, "", time.Second)
  4775. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4776. //清空key 值
  4777. redis.Set(keySix, "", time.Second)
  4778. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4779. redis.Set(keySeven, "", time.Second)
  4780. redis.Close()
  4781. if updateAssessmentErr != nil {
  4782. utils.ErrorLog("%v", updateAssessmentErr)
  4783. }
  4784. }
  4785. }
  4786. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4787. this.ServeSuccessJSON(map[string]interface{}{
  4788. "dialysis_order": dialysisRecords,
  4789. })
  4790. }
  4791. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4792. record_id, _ := c.GetInt64("id")
  4793. nurseID, _ := c.GetInt64("nurse")
  4794. end_time := c.GetString("end_time")
  4795. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4796. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4797. catheter := c.GetString("catheter")
  4798. cruor := c.GetString("cruor")
  4799. mission := c.GetString("mission")
  4800. condenser := c.GetString("condenser")
  4801. if record_id <= 0 || nurseID <= 0 {
  4802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4803. return
  4804. }
  4805. adminUserInfo := c.GetMobileAdminUserInfo()
  4806. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4807. if getNurseErr != nil {
  4808. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4810. return
  4811. } else if nurse == nil {
  4812. c.ErrorLog("护士不存在")
  4813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4814. return
  4815. }
  4816. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4817. if parseEndDateErr != nil {
  4818. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4820. return
  4821. }
  4822. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4823. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4824. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4825. // if getPermissionErr != nil {
  4826. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4827. // return
  4828. // } else if headNursePermission == nil {
  4829. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4830. // return
  4831. // }
  4832. //}
  4833. // 查询信息规挡的设置天数
  4834. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4835. if infor.ID > 0 {
  4836. var cha_time int64
  4837. timeNowStr := time.Now().Format("2006-01-02")
  4838. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4839. //今日的日期减去设置的日期
  4840. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4841. if cha_time >= tempDialysisRecords.DialysisDate {
  4842. //查询审核是否允许
  4843. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4844. //申请状态不允许的情况 拒绝修改
  4845. if infor.ApplicationStatus != 1 {
  4846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4847. return
  4848. }
  4849. }
  4850. }
  4851. dialysisRecord := &models.DialysisOrder{
  4852. ID: record_id,
  4853. UserOrgId: adminUserInfo.Org.Id,
  4854. EndTime: endDate.Unix(),
  4855. FinishNurse: nurseID,
  4856. FinishModifier: adminUserInfo.AdminUser.Id,
  4857. PuncturePointHaematoma: puncture_point_haematoma,
  4858. BloodAccessInternalFistula: blood_access_internal_fistula,
  4859. Catheter: catheter,
  4860. Cruor: cruor,
  4861. Mission: mission,
  4862. Condenser: condenser,
  4863. }
  4864. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4865. redis := service.RedisClient()
  4866. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4867. //清空key 值
  4868. redis.Set(key, "", time.Second)
  4869. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4870. //清空key 值
  4871. redis.Set(keyOne, "", time.Second)
  4872. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4873. redis.Set(keySeven, "", time.Second)
  4874. redis.Close()
  4875. if updateErr != nil {
  4876. c.ErrorLog("修改下机失败:%v", updateErr)
  4877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4878. return
  4879. }
  4880. if updateErr == nil {
  4881. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4882. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4883. a, b := math.Modf(value)
  4884. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4885. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4886. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4887. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4888. redis := service.RedisClient()
  4889. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4890. redis.Set(keyTen, "", time.Second)
  4891. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4892. redis.Set(keyTwo, "", time.Second)
  4893. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4894. redis.Set(key, "", time.Second)
  4895. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4896. redis.Set(keyThree, "", time.Second)
  4897. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4898. redis.Set(keySeven, "", time.Second)
  4899. defer redis.Close()
  4900. if updateAssessmentErr != nil {
  4901. utils.ErrorLog("%v", updateAssessmentErr)
  4902. }
  4903. }
  4904. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4905. c.ServeSuccessJSON(map[string]interface{}{
  4906. "dialysis_order": dialysisRecords,
  4907. })
  4908. }
  4909. func (c *DialysisAPIController) GetLongAdvice() {
  4910. patient_id, _ := c.GetInt64("id")
  4911. adminUserInfo := c.GetMobileAdminUserInfo()
  4912. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4913. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4914. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4915. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4916. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4917. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4918. c.ServeSuccessJSON(map[string]interface{}{
  4919. "status": "1",
  4920. })
  4921. return
  4922. } else { //开启推送提醒
  4923. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4924. var advice_three []*models.DoctorAdvice
  4925. recordDateStr := time.Now().Format("2006-01-02")
  4926. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4927. nowtime := recordDate.Unix()
  4928. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4929. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4930. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4931. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4932. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4933. for _, advice := range advices {
  4934. if advice.FrequencyType == 3 {
  4935. t := time.Now()
  4936. week := int(t.Weekday())
  4937. fmt.Println(t.Weekday())
  4938. fmt.Println(week)
  4939. switch week {
  4940. case 1:
  4941. if strings.Index(advice.WeekDay, "周一") == -1 {
  4942. advice_three = append(advice_three, advice)
  4943. }
  4944. break
  4945. case 2:
  4946. if strings.Index(advice.WeekDay, "周二") == -1 {
  4947. advice_three = append(advice_three, advice)
  4948. }
  4949. break
  4950. case 3:
  4951. if strings.Index(advice.WeekDay, "周三") == -1 {
  4952. advice_three = append(advice_three, advice)
  4953. }
  4954. break
  4955. case 4:
  4956. if strings.Index(advice.WeekDay, "周四") == -1 {
  4957. advice_three = append(advice_three, advice)
  4958. }
  4959. break
  4960. case 5:
  4961. if strings.Index(advice.WeekDay, "周五") == -1 {
  4962. advice_three = append(advice_three, advice)
  4963. }
  4964. break
  4965. case 6:
  4966. if strings.Index(advice.WeekDay, "周六") == -1 {
  4967. advice_three = append(advice_three, advice)
  4968. }
  4969. break
  4970. case 0:
  4971. if strings.Index(advice.WeekDay, "周日") == -1 {
  4972. advice_three = append(advice_three, advice)
  4973. }
  4974. break
  4975. }
  4976. }
  4977. }
  4978. for _, advice := range advices_two {
  4979. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4980. now := p.Unix()
  4981. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4982. dayStr2 := "-" + dayStr
  4983. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4984. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4985. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4986. for _, ad := range advices {
  4987. advice_three = append(advice_three, ad)
  4988. }
  4989. }
  4990. if err == nil {
  4991. c.ServeSuccessJSON(map[string]interface{}{
  4992. "status": "2",
  4993. "advices": advices,
  4994. "advices_two": RemoveRepeatedElement(advice_three),
  4995. "is_open_remind": config.IsOpenRemind,
  4996. "his_config_open": hisConfig.IsOpen,
  4997. "is_advice_open": is_advice_open.IsAdviceOpen,
  4998. "prescription_open": prescription_open.IsOpen,
  4999. })
  5000. }
  5001. }
  5002. }
  5003. func (c *DialysisAPIController) GetLongAdviceOne() {
  5004. patient_id, _ := c.GetInt64("id")
  5005. startTime := c.GetString("schedule_date")
  5006. timeLayout := "2006-01-02"
  5007. loc, _ := time.LoadLocation("Local")
  5008. var theStartTime int64
  5009. if len(startTime) > 0 {
  5010. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5011. if err != nil {
  5012. utils.ErrorLog(err.Error())
  5013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5014. return
  5015. }
  5016. theStartTime = theTime.Unix()
  5017. }
  5018. adminUserInfo := c.GetMobileAdminUserInfo()
  5019. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5020. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5021. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5022. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5023. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5024. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5025. c.ServeSuccessJSON(map[string]interface{}{
  5026. "status": "1",
  5027. })
  5028. return
  5029. } else { //开启推送提醒
  5030. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5031. var advice_three []*models.DoctorAdvice
  5032. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5033. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5034. for _, advice := range advices {
  5035. if advice.FrequencyType == 3 {
  5036. t := time.Now()
  5037. week := int(t.Weekday())
  5038. fmt.Println(t.Weekday())
  5039. fmt.Println(week)
  5040. switch week {
  5041. case 1:
  5042. if strings.Index(advice.WeekDay, "周一") == -1 {
  5043. advice_three = append(advice_three, advice)
  5044. }
  5045. break
  5046. case 2:
  5047. if strings.Index(advice.WeekDay, "周二") == -1 {
  5048. advice_three = append(advice_three, advice)
  5049. }
  5050. break
  5051. case 3:
  5052. if strings.Index(advice.WeekDay, "周三") == -1 {
  5053. advice_three = append(advice_three, advice)
  5054. }
  5055. break
  5056. case 4:
  5057. if strings.Index(advice.WeekDay, "周四") == -1 {
  5058. advice_three = append(advice_three, advice)
  5059. }
  5060. break
  5061. case 5:
  5062. if strings.Index(advice.WeekDay, "周五") == -1 {
  5063. advice_three = append(advice_three, advice)
  5064. }
  5065. break
  5066. case 6:
  5067. if strings.Index(advice.WeekDay, "周六") == -1 {
  5068. advice_three = append(advice_three, advice)
  5069. }
  5070. break
  5071. case 0:
  5072. if strings.Index(advice.WeekDay, "周日") == -1 {
  5073. advice_three = append(advice_three, advice)
  5074. }
  5075. break
  5076. }
  5077. }
  5078. }
  5079. for _, advice := range advices_two {
  5080. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5081. now := p.Unix()
  5082. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5083. dayStr2 := "-" + dayStr
  5084. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5085. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5086. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5087. for _, ad := range advices {
  5088. advice_three = append(advice_three, ad)
  5089. }
  5090. }
  5091. if err == nil {
  5092. c.ServeSuccessJSON(map[string]interface{}{
  5093. "status": "2",
  5094. "advices": advices,
  5095. "advices_two": RemoveRepeatedElement(advice_three),
  5096. "is_open_remind": config.IsOpenRemind,
  5097. "his_config_open": hisConfig.IsOpen,
  5098. "is_advice_open": is_advice_open.IsAdviceOpen,
  5099. "prescription_open": prescription_open.IsOpen,
  5100. })
  5101. }
  5102. }
  5103. }
  5104. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5105. newArr = make([]*models.DoctorAdvice, 0)
  5106. for i := 0; i < len(arr); i++ {
  5107. repeat := false
  5108. for j := i + 1; j < len(arr); j++ {
  5109. if arr[i].ID == arr[j].ID {
  5110. repeat = true
  5111. break
  5112. }
  5113. }
  5114. if !repeat {
  5115. newArr = append(newArr, arr[i])
  5116. }
  5117. }
  5118. return
  5119. }
  5120. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5121. patient, _ := c.GetInt64("id", 0)
  5122. groupNo, _ := c.GetInt64("groupno", 0)
  5123. if patient <= 0 {
  5124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5125. return
  5126. }
  5127. adminUserInfo := c.GetMobileAdminUserInfo()
  5128. dataBody := make(map[string]interface{}, 0)
  5129. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5130. if err != nil {
  5131. utils.ErrorLog(err.Error())
  5132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5133. return
  5134. }
  5135. utils.ErrorLog("%v", dataBody)
  5136. timeLayout := "2006-01-02 15:04"
  5137. loc, _ := time.LoadLocation("Local")
  5138. timeLayout2 := "2006-01-02"
  5139. loc2, _ := time.LoadLocation("Local")
  5140. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5141. utils.ErrorLog("advice_type")
  5142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5143. return
  5144. }
  5145. adviceType := int64(2)
  5146. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5147. utils.ErrorLog("advice_date")
  5148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5149. return
  5150. }
  5151. adviceDate, _ := dataBody["advice_date"].(string)
  5152. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5153. AdviceDate := theTime.Unix()
  5154. RecordDate := theTime.Unix()
  5155. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5156. utils.ErrorLog("start_time")
  5157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5158. return
  5159. }
  5160. startTime, _ := dataBody["start_time"].(string)
  5161. if len(startTime) == 0 {
  5162. utils.ErrorLog("len(start_time) == 0")
  5163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5164. return
  5165. }
  5166. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5167. if err != nil {
  5168. utils.ErrorLog(err.Error())
  5169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5170. return
  5171. }
  5172. StartTime := theTime.Unix()
  5173. Remark := ""
  5174. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5175. remark, _ := dataBody["remark"].(string)
  5176. Remark = remark
  5177. }
  5178. var advices []*models.GroupAdvice
  5179. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5180. utils.ErrorLog("advices")
  5181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5182. return
  5183. }
  5184. adviceNames := dataBody["advices"].([]interface{})
  5185. for _, adviceNameMap := range adviceNames {
  5186. adviceNameM := adviceNameMap.(map[string]interface{})
  5187. var advice models.GroupAdvice
  5188. advice.Remark = Remark
  5189. advice.AdviceType = adviceType
  5190. advice.StartTime = StartTime
  5191. advice.AdviceDate = AdviceDate
  5192. advice.RecordDate = RecordDate
  5193. advice.Status = 1
  5194. advice.CreatedTime = time.Now().Unix()
  5195. advice.UpdatedTime = time.Now().Unix()
  5196. advice.StopState = 2
  5197. advice.ExecutionState = 2
  5198. advice.UserOrgId = adminUserInfo.Org.Id
  5199. advice.PatientId = patient
  5200. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5201. advice.IsSettle = 2
  5202. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5203. utils.ErrorLog("advice_name")
  5204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5205. return
  5206. }
  5207. adviceName, _ := adviceNameM["advice_name"].(string)
  5208. if len(adviceName) == 0 {
  5209. utils.ErrorLog("len(advice_name) == 0")
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5211. return
  5212. }
  5213. advice.AdviceName = adviceName
  5214. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5215. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5216. advice.DrugSpec = drugSpec
  5217. }
  5218. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5219. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5220. advice.AdviceDesc = adviceDesc
  5221. }
  5222. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5223. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5224. advice.DrugSpecUnit = drugSpecUnit
  5225. }
  5226. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5227. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5228. // advice.SingleDose = singleDose
  5229. //}
  5230. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5231. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5232. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5233. }
  5234. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5235. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5236. advice.SingleDoseUnit = singleDoseUnit
  5237. }
  5238. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5239. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5240. // advice.PrescribingNumber = prescribingNumber
  5241. //}
  5242. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5243. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5244. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5245. }
  5246. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5247. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5248. advice.PrescribingNumberUnit = prescribingNumberUnit
  5249. }
  5250. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5251. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5252. advice.DeliveryWay = deliveryWay
  5253. }
  5254. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5255. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5256. advice.ExecutionFrequency = executionFrequency
  5257. }
  5258. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5259. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5260. advice.FrequencyType = frequency_type
  5261. }
  5262. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5263. day_count := int64(adviceNameM["day_count"].(float64))
  5264. advice.DayCount = day_count
  5265. }
  5266. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5267. week_day, _ := adviceNameM["week_day"].(string)
  5268. advice.WeekDay = week_day
  5269. }
  5270. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5271. way := int64(adviceNameM["way"].(float64))
  5272. advice.Way = way
  5273. }
  5274. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5275. drug_id := int64(adviceNameM["drug_id"].(float64))
  5276. advice.DrugId = drug_id
  5277. }
  5278. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5279. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5280. advice.DrugNameId = drug_name_id
  5281. }
  5282. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5283. remark, _ := adviceNameM["remark"].(string)
  5284. advice.Remark = remark
  5285. }
  5286. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5287. groupno := int64(adviceNameM["groupno"].(float64))
  5288. advice.GroupNo = groupno
  5289. }
  5290. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5291. template_id, _ := adviceNameM["template_id"].(string)
  5292. advice.TemplateId = template_id
  5293. }
  5294. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5295. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5296. advice.ExecutionFrequency = executionFrequency
  5297. }
  5298. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5299. children := adviceNameM["child"].([]interface{})
  5300. if len(children) > 0 {
  5301. for _, childrenMap := range children {
  5302. childMap := childrenMap.(map[string]interface{})
  5303. var child models.GroupAdvice
  5304. child.Remark = Remark
  5305. child.AdviceType = adviceType
  5306. child.StartTime = StartTime
  5307. child.AdviceDate = AdviceDate
  5308. child.RecordDate = RecordDate
  5309. child.Status = 1
  5310. child.CreatedTime = time.Now().Unix()
  5311. child.UpdatedTime = time.Now().Unix()
  5312. child.StopState = 2
  5313. child.ExecutionState = 2
  5314. child.UserOrgId = adminUserInfo.Org.Id
  5315. child.PatientId = patient
  5316. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5317. child.IsSettle = 1
  5318. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5319. utils.ErrorLog("child advice_name")
  5320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5321. return
  5322. }
  5323. childAdviceName, _ := childMap["advice_name"].(string)
  5324. if len(childAdviceName) == 0 {
  5325. utils.ErrorLog("len(child advice_name) == 0")
  5326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5327. return
  5328. }
  5329. child.AdviceName = childAdviceName
  5330. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5331. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5332. child.AdviceDesc = childAdviceDesc
  5333. }
  5334. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5335. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5336. child.DrugSpec = childDrugSpec
  5337. }
  5338. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5339. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5340. child.DrugSpecUnit = childDrugSpecUnit
  5341. }
  5342. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5343. child.SingleDose = childMap["single_dose"].(float64)
  5344. }
  5345. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5346. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5347. child.SingleDoseUnit = childSingleDoseUnit
  5348. }
  5349. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5350. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5351. }
  5352. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5353. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5354. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5355. }
  5356. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5357. groupno := int64(childMap["groupno"].(float64))
  5358. advice.GroupNo = groupno
  5359. }
  5360. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5361. remark, _ := childMap["remark"].(string)
  5362. child.Remark = remark
  5363. }
  5364. child.DeliveryWay = advice.DeliveryWay
  5365. child.ExecutionFrequency = advice.ExecutionFrequency
  5366. advice.Children = append(advice.Children, &child)
  5367. }
  5368. }
  5369. }
  5370. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5371. if temp_advice.ID == 0 {
  5372. advices = append(advices, &advice)
  5373. }
  5374. }
  5375. if len(advices) > 0 {
  5376. finish := models.XtDialysisFinish{
  5377. IsFinish: 1,
  5378. UserOrgId: adminUserInfo.Org.Id,
  5379. Status: 1,
  5380. Ctime: time.Now().Unix(),
  5381. Mtime: 0,
  5382. Module: 4,
  5383. RecordDate: AdviceDate,
  5384. Sourse: 1,
  5385. PatientId: patient,
  5386. }
  5387. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5388. if dialysisFinish.ID == 0 {
  5389. service.CreateDialysisFinish(finish)
  5390. }
  5391. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5392. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5393. for _, item := range advices {
  5394. byterequest, _ := json.Marshal(item)
  5395. adviceLog := models.XtDoctorAdviceLog{
  5396. UserOrgId: adminUserInfo.Org.Id,
  5397. PatientId: patient,
  5398. AdminUserId: adminUserInfo.AdminUser.Id,
  5399. Module: 1,
  5400. ErrLog: string(byterequest),
  5401. Status: 1,
  5402. Ctime: time.Now().Unix(),
  5403. Mtime: 0,
  5404. Source: "手机端医嘱推送",
  5405. RecordDate: item.AdviceDate,
  5406. }
  5407. service.CreateDoctorAdviceLog(adviceLog)
  5408. }
  5409. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5410. redis := service.RedisClient()
  5411. //清空key 值
  5412. redis.Set(key, "", time.Second)
  5413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5414. redis.Set(keyOne, "", time.Second)
  5415. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5416. defer redis.Close()
  5417. redis.Set(keyThree, "", time.Second)
  5418. if err != nil {
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5420. return
  5421. }
  5422. c.ServeSuccessJSON(map[string]interface{}{
  5423. "msg": "ok",
  5424. "advices": list,
  5425. })
  5426. } else {
  5427. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5428. for _, item := range advices {
  5429. byterequest, _ := json.Marshal(item)
  5430. adviceLog := models.XtDoctorAdviceLog{
  5431. UserOrgId: adminUserInfo.Org.Id,
  5432. PatientId: patient,
  5433. AdminUserId: adminUserInfo.AdminUser.Id,
  5434. Module: 1,
  5435. ErrLog: string(byterequest),
  5436. Status: 1,
  5437. Ctime: time.Now().Unix(),
  5438. Mtime: 0,
  5439. Source: "手机端医嘱推送",
  5440. RecordDate: item.AdviceDate,
  5441. }
  5442. service.CreateDoctorAdviceLog(adviceLog)
  5443. }
  5444. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5445. redis := service.RedisClient()
  5446. //清空key 值
  5447. redis.Set(key, "", time.Second)
  5448. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5449. redis.Set(keyOne, "", time.Second)
  5450. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5451. defer redis.Close()
  5452. redis.Set(keyThree, "", time.Second)
  5453. if err != nil {
  5454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5455. return
  5456. }
  5457. c.ServeSuccessJSON(map[string]interface{}{
  5458. "msg": "ok",
  5459. "advices": list,
  5460. })
  5461. }
  5462. } else {
  5463. c.ServeSuccessJSON(map[string]interface{}{
  5464. "msg": "ok",
  5465. })
  5466. }
  5467. return
  5468. }
  5469. func (c *DialysisAPIController) UploadDryWeight() {
  5470. patient_id, _ := c.GetInt64("id")
  5471. dry_weight, _ := c.GetFloat("dry_weight")
  5472. doctor_id, _ := c.GetInt64("doctor_id")
  5473. remark := c.GetString("remark")
  5474. adminUserInfo := c.GetMobileAdminUserInfo()
  5475. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5476. if err == gorm.ErrRecordNotFound {
  5477. dryWeight := &models.SgjPatientDryweight{
  5478. PatientId: patient_id,
  5479. DryWeight: dry_weight,
  5480. Remakes: remark,
  5481. Ctime: time.Now().Unix(),
  5482. Mtime: time.Now().Unix(),
  5483. Creator: doctor_id,
  5484. Status: 1,
  5485. UserOrgId: adminUserInfo.Org.Id,
  5486. AdjustedValue: "/",
  5487. UserId: adminUserInfo.AdminUser.Id,
  5488. }
  5489. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5490. redis := service.RedisClient()
  5491. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5492. redis.Set(keyOne, "", time.Second)
  5493. loc, _ := time.LoadLocation("Local")
  5494. nowTime := time.Now()
  5495. nowDay := nowTime.Format("2006-01-02")
  5496. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5497. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5498. redis.Set(key, "", time.Second)
  5499. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5500. redis.Set(keyTwo, "", time.Second)
  5501. redis.Close()
  5502. if createErr == nil {
  5503. c.ServeSuccessJSON(map[string]interface{}{
  5504. "msg": "提交成功",
  5505. "weight": dryWeight,
  5506. })
  5507. }
  5508. } else {
  5509. dryWeight := &models.SgjPatientDryweight{
  5510. PatientId: patient_id,
  5511. DryWeight: dry_weight,
  5512. Remakes: remark,
  5513. Ctime: time.Now().Unix(),
  5514. Mtime: time.Now().Unix(),
  5515. Creator: doctor_id,
  5516. Status: 1,
  5517. UserOrgId: adminUserInfo.Org.Id,
  5518. AdjustedValue: "/",
  5519. UserId: adminUserInfo.AdminUser.Id,
  5520. }
  5521. var value float64
  5522. value = dry_weight - weightAdjust.DryWeight
  5523. if value < 0 {
  5524. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5525. } else if value == 0 {
  5526. dryWeight.AdjustedValue = "/"
  5527. } else if value > 0 {
  5528. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5529. }
  5530. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5531. //康桥
  5532. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5533. timeNowStr := time.Now().Format("2006-01-02")
  5534. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5535. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5536. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5537. if beforAssesment.ID > 0 {
  5538. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5539. var dewater_amount float64
  5540. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5541. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5542. //获取key,清空redis
  5543. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5544. redis := service.RedisClient()
  5545. //清空key 值
  5546. redis.Set(key, "", time.Second)
  5547. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5548. //清空key 值
  5549. redis.Set(keyOne, "", time.Second)
  5550. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5551. //清空key 值
  5552. redis.Set(keyTwo, "", time.Second)
  5553. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5554. redis.Set(keySix, "", time.Second)
  5555. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5556. redis.Set(keySeven, "", time.Second)
  5557. }
  5558. }
  5559. redis := service.RedisClient()
  5560. loc, _ := time.LoadLocation("Local")
  5561. nowTime := time.Now()
  5562. nowDay := nowTime.Format("2006-01-02")
  5563. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5564. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5565. redis.Set(keyOne, "", time.Second)
  5566. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5567. redis.Set(key, "", time.Second)
  5568. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5569. redis.Set(keyTwo, "", time.Second)
  5570. redis.Close()
  5571. if createErr == nil {
  5572. c.ServeSuccessJSON(map[string]interface{}{
  5573. "msg": "提交成功",
  5574. "weight": dryWeight,
  5575. })
  5576. }
  5577. }
  5578. }
  5579. func (c *DialysisAPIController) GetSolution() {
  5580. patient_id, _ := c.GetInt64("patient_id")
  5581. mode_id, _ := c.GetInt64("mode_id")
  5582. adminUserInfo := c.GetMobileAdminUserInfo()
  5583. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5584. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5585. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5586. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5587. if err != nil {
  5588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5589. return
  5590. }
  5591. c.ServeSuccessJSON(map[string]interface{}{
  5592. "solution": solution,
  5593. "prescription": prescription,
  5594. "system_prescription": system_prescription,
  5595. "dialysisPrescription": dialysisPrescription,
  5596. })
  5597. }
  5598. func (c *DialysisAPIController) GetSchedule() {
  5599. schedual_type, _ := c.GetInt64("schedual_type")
  5600. adminUserInfo := c.GetMobileAdminUserInfo()
  5601. scheduleTime, _ := c.GetInt64("record_date")
  5602. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5603. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5604. c.ServeSuccessJSON(map[string]interface{}{
  5605. "number": deviceNumber,
  5606. "list": list,
  5607. })
  5608. }
  5609. func (c *DialysisAPIController) GetPatientId() {
  5610. id, _ := c.GetInt64("id")
  5611. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5612. patientId, _ := service.GetPatientId(id)
  5613. //获取该患者的所有传染病
  5614. list, _ := service.GetPatientInfectious(id)
  5615. c.ServeSuccessJSON(map[string]interface{}{
  5616. "patient": patientId,
  5617. "infectioulist": list,
  5618. })
  5619. }
  5620. func (this *DialysisAPIController) GetDialysisSchedule() {
  5621. schedualDate := this.GetString("date")
  5622. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5623. if parseDateErr != nil {
  5624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5625. return
  5626. }
  5627. adminInfo := this.GetMobileAdminUserInfo()
  5628. orgID := adminInfo.Org.Id
  5629. redis := service.RedisClient()
  5630. defer redis.Close()
  5631. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5632. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5633. if len(scheduals) > 0 {
  5634. //缓存数据
  5635. scheduals_json, err := json.Marshal(scheduals)
  5636. if err == nil {
  5637. redis.Set(key, scheduals_json, time.Second*30)
  5638. }
  5639. }
  5640. this.ServeSuccessJSON(map[string]interface{}{
  5641. "scheduals": scheduals,
  5642. })
  5643. }
  5644. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5645. change_type, _ := this.GetInt64("type", 0)
  5646. record_date := this.GetString("record_time")
  5647. patient_id, _ := this.GetInt64("patient_id", 0)
  5648. timeLayout := "2006-01-02"
  5649. loc, _ := time.LoadLocation("Local")
  5650. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5651. record_time := theAdviceRecordTime.Unix()
  5652. adminUserInfo := this.GetMobileAdminUserInfo()
  5653. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5654. if err == nil {
  5655. if len(advices) == 0 {
  5656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5657. return
  5658. } else {
  5659. this.ServeSuccessJSON(map[string]interface{}{
  5660. "advices": advices,
  5661. "schedule": sch,
  5662. })
  5663. return
  5664. }
  5665. } else {
  5666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5667. return
  5668. }
  5669. }
  5670. func (c *DialysisAPIController) CreateConsumables() {
  5671. record_date := c.GetString("record_time")
  5672. patient_id, _ := c.GetInt64("patient_id", 0)
  5673. active, _ := c.GetInt64("active")
  5674. adminUser := c.GetMobileAdminUserInfo()
  5675. timeLayout := "2006-01-02"
  5676. loc, _ := time.LoadLocation("Local")
  5677. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5678. record_time := theRecordTime.Unix()
  5679. // 查询信息规挡的设置天数
  5680. orgid := c.GetMobileAdminUserInfo().Org.Id
  5681. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5682. if infor.ID > 0 {
  5683. var cha_time int64
  5684. timeNowStr := time.Now().Format("2006-01-02")
  5685. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5686. //今日的日期减去设置的日期
  5687. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5688. if cha_time >= record_time {
  5689. //查询审核是否允许
  5690. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5691. //申请状态不允许的情况 拒绝修改
  5692. if infor.ApplicationStatus != 1 {
  5693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5694. return
  5695. }
  5696. }
  5697. }
  5698. dataBody := make(map[string]interface{}, 0)
  5699. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5700. if err != nil {
  5701. utils.ErrorLog(err.Error())
  5702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5703. return
  5704. }
  5705. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5706. var beforePrepares []*models.DialysisBeforePrepareGoods
  5707. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5708. var dialysisBefor []*models.DialysisBeforePrepare
  5709. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5710. goods, _ := dataBody["goods"].([]interface{})
  5711. if len(goods) > 0 {
  5712. for _, item := range goods {
  5713. items := item.(map[string]interface{})
  5714. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5715. utils.ErrorLog("good_id")
  5716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5717. return
  5718. }
  5719. good_id := int64(items["good_id"].(float64))
  5720. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5721. utils.ErrorLog("good_type_id")
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5723. return
  5724. }
  5725. good_type_id := int64(items["good_type_id"].(float64))
  5726. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5727. utils.ErrorLog("count")
  5728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5729. return
  5730. }
  5731. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5732. commdity_code := items["commdity_code"].(string)
  5733. fmt.Println("commdity", commdity_code)
  5734. prepareGoods := &models.DialysisBeforePrepareGoods{
  5735. GoodTypeId: good_type_id,
  5736. GoodId: good_id,
  5737. Count: count,
  5738. StorehouseId: houseConfig.StorehouseOutInfo,
  5739. }
  5740. beforePrepares = append(beforePrepares, prepareGoods)
  5741. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5742. GoodTypeId: good_type_id,
  5743. GoodId: good_id,
  5744. Count: count,
  5745. StorehouseId: houseConfig.StorehouseOutInfo,
  5746. }
  5747. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5748. prepare := &models.DialysisBeforePrepare{
  5749. GoodTypeId: good_type_id,
  5750. GoodId: good_id,
  5751. Count: count,
  5752. PatientId: patient_id,
  5753. RecordDate: record_time,
  5754. UserOrgId: adminUser.Org.Id,
  5755. Status: 1,
  5756. Ctime: time.Now().Unix(),
  5757. Creater: adminUser.AdminUser.Id,
  5758. CommdityCode: commdity_code,
  5759. StorehouseId: houseConfig.StorehouseOutInfo,
  5760. }
  5761. dialysisBefor = append(dialysisBefor, prepare)
  5762. }
  5763. }
  5764. //查询是否有库存
  5765. for _, item := range dialysisBefor {
  5766. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5767. if err == gorm.ErrRecordNotFound {
  5768. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5769. c.ServeSuccessJSON(map[string]interface{}{
  5770. "message": "1",
  5771. "good_name": goodObj.GoodName,
  5772. "specification_name": goodObj.SpecificationName,
  5773. })
  5774. return
  5775. }
  5776. if err != nil {
  5777. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5778. c.ServeSuccessJSON(map[string]interface{}{
  5779. "message": "1",
  5780. "good_name": goodObj.GoodName,
  5781. "specification_name": goodObj.SpecificationName,
  5782. })
  5783. return
  5784. }
  5785. }
  5786. fmt.Println("active-----------------------", active)
  5787. fmt.Println("len(goods)-----------------------", len(goods))
  5788. //新增
  5789. if active == 1 && len(goods) > 0 {
  5790. for _, item := range dialysisBefor {
  5791. dialyPrepareOne := models.DialysisBeforePrepare{
  5792. GoodTypeId: item.GoodTypeId,
  5793. GoodId: item.GoodId,
  5794. PatientId: item.PatientId,
  5795. RecordDate: item.RecordDate,
  5796. UserOrgId: item.UserOrgId,
  5797. Count: item.Count,
  5798. Ctime: time.Now().Unix(),
  5799. Creater: item.Creater,
  5800. CommdityCode: item.CommdityCode,
  5801. Status: 1,
  5802. StorehouseId: houseConfig.StorehouseOutInfo,
  5803. }
  5804. //先清除再插入
  5805. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5806. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5807. //查询默认仓库
  5808. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5809. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5810. var total_count int64
  5811. for _, it := range stockList {
  5812. total_count += it.StockCount
  5813. }
  5814. //基础库插入数据
  5815. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5816. //更新库存
  5817. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5818. var flush_count int64
  5819. for _, it := range goodList {
  5820. flush_count += it.StockCount
  5821. }
  5822. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5823. }
  5824. if err == nil {
  5825. c.ServeSuccessJSON(map[string]interface{}{
  5826. "msg": "保存成功",
  5827. "message": "2",
  5828. })
  5829. return
  5830. } else {
  5831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5832. return
  5833. }
  5834. }
  5835. if len(beforePrepares) > 0 && active == 2 {
  5836. for _, item := range beforePrepares {
  5837. //1.查看该患者该耗材型号最后一次出库数量
  5838. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5839. //判断当前出库数量和最后一次出库数量的大小
  5840. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5841. if item.Count <= goodInfo.Count {
  5842. //退库
  5843. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5844. //查询今日出库数据
  5845. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5846. for _, it := range list {
  5847. prepare := models.DialysisBeforePrepare{
  5848. UserOrgId: it.OrgId,
  5849. PatientId: patient_id,
  5850. RecordDate: it.RecordTime,
  5851. GoodId: it.GoodId,
  5852. GoodTypeId: it.GoodTypeId,
  5853. Count: it.Count,
  5854. Ctime: time.Now().Unix(),
  5855. Creater: adminUser.AdminUser.Id,
  5856. Status: 1,
  5857. StorehouseId: houseConfig.StorehouseOutInfo,
  5858. }
  5859. //删除准备表数据
  5860. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5861. service.CreateDialysisBeforePrepareOne(&prepare)
  5862. }
  5863. }
  5864. var last_total int64
  5865. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5866. if item.Count >= goodInfo.Count {
  5867. //查询当前批次当前耗材最后一条出库数据
  5868. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5869. //计算当前出库和最后一次出库数据相差数据
  5870. last_total = item.Count - lastOutInfo.Count
  5871. //查询该批次剩余库存
  5872. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5873. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5874. if lastInfo.StockCount >= last_total {
  5875. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5876. //查询今日出库数据
  5877. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5878. for _, it := range list {
  5879. prepare := models.DialysisBeforePrepare{
  5880. UserOrgId: it.OrgId,
  5881. PatientId: patient_id,
  5882. RecordDate: it.RecordTime,
  5883. GoodId: it.GoodId,
  5884. GoodTypeId: it.GoodTypeId,
  5885. Count: it.Count,
  5886. Ctime: time.Now().Unix(),
  5887. Creater: adminUser.AdminUser.Id,
  5888. Status: 1,
  5889. StorehouseId: houseConfig.StorehouseOutInfo,
  5890. }
  5891. //删除准备表数据
  5892. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5893. service.CreateDialysisBeforePrepareOne(&prepare)
  5894. //查询默认仓库
  5895. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5896. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5897. var total_count int64
  5898. for _, it := range stockList {
  5899. total_count += it.StockCount
  5900. }
  5901. //基础库插入数据
  5902. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5903. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5904. var flush_count int64
  5905. for _, it := range goodList {
  5906. flush_count += it.StockCount
  5907. }
  5908. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5909. }
  5910. }
  5911. //如果库存不够,则出库到下一个批次
  5912. if lastInfo.StockCount < last_total {
  5913. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5914. //查询今日出库数据
  5915. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5916. for _, it := range list {
  5917. prepare := models.DialysisBeforePrepare{
  5918. UserOrgId: it.OrgId,
  5919. PatientId: patient_id,
  5920. RecordDate: it.RecordTime,
  5921. GoodId: it.GoodId,
  5922. GoodTypeId: it.GoodTypeId,
  5923. Count: it.Count,
  5924. Ctime: time.Now().Unix(),
  5925. Creater: adminUser.AdminUser.Id,
  5926. Status: 1,
  5927. StorehouseId: houseConfig.StorehouseOutInfo,
  5928. }
  5929. //删除准备表数据
  5930. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5931. service.CreateDialysisBeforePrepareOne(&prepare)
  5932. //查询默认仓库
  5933. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5934. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5935. var total_count int64
  5936. for _, it := range stockList {
  5937. total_count += it.StockCount
  5938. }
  5939. //基础库插入数据
  5940. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5941. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5942. var flush_count int64
  5943. for _, it := range goodList {
  5944. flush_count += it.StockCount
  5945. }
  5946. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5947. }
  5948. if err != nil {
  5949. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5950. c.ServeSuccessJSON(map[string]interface{}{
  5951. "message": "1",
  5952. "good_name": goodObj.GoodName,
  5953. "specification_name": goodObj.SpecificationName,
  5954. })
  5955. return
  5956. }
  5957. }
  5958. }
  5959. if err != nil {
  5960. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5961. c.ServeSuccessJSON(map[string]interface{}{
  5962. "message": "1",
  5963. "good_name": goodObj.GoodName,
  5964. "specification_name": goodObj.SpecificationName,
  5965. })
  5966. return
  5967. }
  5968. }
  5969. }
  5970. }
  5971. var errs error
  5972. if errs == nil {
  5973. c.ServeSuccessJSON(map[string]interface{}{
  5974. "msg": "提交成功",
  5975. "message": "2",
  5976. "good_name": "",
  5977. "specification_name": "",
  5978. })
  5979. return
  5980. } else {
  5981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5982. return
  5983. }
  5984. }
  5985. func (c *DialysisAPIController) CreateStockOutInfo() {
  5986. patient_id, _ := c.GetInt64("patient_id", 0)
  5987. record_date := c.GetString("record_time")
  5988. if patient_id <= 0 {
  5989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5990. return
  5991. }
  5992. adminInfo := c.GetMobileAdminUserInfo()
  5993. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5994. timeLayout := "2006-01-02"
  5995. loc, _ := time.LoadLocation("Local")
  5996. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5997. record_time := theRecordTime.Unix()
  5998. // 查询信息规挡的设置天数
  5999. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6000. if infor.ID > 0 && infor.WeekDay > 0 {
  6001. var cha_time int64
  6002. timeNowStr := time.Now().Format("2006-01-02")
  6003. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6004. //今日的日期减去设置的日期
  6005. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6006. if cha_time >= record_time {
  6007. //查询审核是否允许
  6008. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6009. //申请状态不允许的情况 拒绝修改
  6010. if infor.ApplicationStatus != 1 {
  6011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6012. return
  6013. }
  6014. }
  6015. }
  6016. //创建步骤表
  6017. finish := models.XtDialysisFinish{
  6018. IsFinish: 1,
  6019. UserOrgId: adminInfo.Org.Id,
  6020. Status: 1,
  6021. Ctime: time.Now().Unix(),
  6022. Mtime: 0,
  6023. Module: 11,
  6024. RecordDate: record_time,
  6025. Sourse: 1,
  6026. PatientId: patient_id,
  6027. }
  6028. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6029. if dialysisFinish.ID == 0 {
  6030. service.CreateDialysisFinish(finish)
  6031. }
  6032. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6033. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6034. //去重
  6035. consumables = RemoveRepeatedGood(consumables)
  6036. if adminInfo.Org.Id == 9919 {
  6037. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6038. //查询是否有库存
  6039. for _, item := range consumables {
  6040. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6041. if item.Count > warehouse.Count {
  6042. goodErrcode := models.XtGoodErrcode{
  6043. UserOrgId: item.UserOrgId,
  6044. Errcode: "自动出库库存不足",
  6045. GoodId: item.GoodId,
  6046. Status: 1,
  6047. Ctime: time.Now().Unix(),
  6048. Mtime: 0,
  6049. Count: 0,
  6050. StockCount: 0,
  6051. Creater: creator,
  6052. BatchNumberId: warehouse.ID,
  6053. WarehouseOutId: 0,
  6054. }
  6055. service.CreateGoodErrcode(goodErrcode)
  6056. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6057. c.ServeSuccessJSON(map[string]interface{}{
  6058. "message": "1",
  6059. "good_name": goodObj.GoodName,
  6060. "specification_name": goodObj.SpecificationName,
  6061. })
  6062. return
  6063. }
  6064. }
  6065. //查询是否有出库单
  6066. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6067. if err == gorm.ErrRecordNotFound {
  6068. //没有记录,则创建出库单
  6069. timeStr := time.Now().Format("2006-01-02")
  6070. timeArr := strings.Split(timeStr, "-")
  6071. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6072. total = total + 1
  6073. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6074. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6075. number = number + total
  6076. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6077. creater := adminInfo.AdminUser.Id
  6078. warehouseOut := models.WarehouseOut{
  6079. WarehouseOutOrderNumber: warehousing_out_order,
  6080. OperationTime: time.Now().Unix(),
  6081. OrgId: adminInfo.Org.Id,
  6082. Creater: creater,
  6083. Ctime: time.Now().Unix(),
  6084. Status: 1,
  6085. WarehouseOutTime: record_time,
  6086. Dealer: 0,
  6087. Manufacturer: 0,
  6088. Type: 1,
  6089. IsSys: 1,
  6090. StorehouseId: houseConfig.StorehouseOutInfo,
  6091. IsCheck: 1,
  6092. }
  6093. err := service.AddSigleWarehouseOut(&warehouseOut)
  6094. if err != nil {
  6095. goodErrcode := models.XtGoodErrcode{
  6096. UserOrgId: adminInfo.Org.Id,
  6097. Errcode: "创建出库单失败",
  6098. GoodId: 0,
  6099. Status: 1,
  6100. Ctime: time.Now().Unix(),
  6101. Mtime: 0,
  6102. Count: 0,
  6103. StockCount: 0,
  6104. Creater: creator,
  6105. BatchNumberId: 0,
  6106. WarehouseOutId: 0,
  6107. }
  6108. service.CreateGoodErrcode(goodErrcode)
  6109. utils.TraceLog("创建出库单失败 err = %v", err)
  6110. } else {
  6111. for _, item := range consumables {
  6112. //出库
  6113. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6114. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6115. if err == nil {
  6116. goodErrcode := models.XtGoodErrcode{
  6117. UserOrgId: adminInfo.Org.Id,
  6118. Errcode: "自动出库接口报错",
  6119. GoodId: 0,
  6120. Status: 1,
  6121. Ctime: time.Now().Unix(),
  6122. Mtime: 0,
  6123. Count: 0,
  6124. StockCount: 0,
  6125. Creater: creator,
  6126. BatchNumberId: 0,
  6127. WarehouseOutId: 0,
  6128. }
  6129. service.CreateGoodErrcode(goodErrcode)
  6130. utils.TraceLog("创建出库单失败 err = %v", err)
  6131. }
  6132. //查询
  6133. //出库数量相加
  6134. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6135. if errs != nil {
  6136. goodErrcode := models.XtGoodErrcode{
  6137. UserOrgId: item.UserOrgId,
  6138. Errcode: "创建剩余库存字段报错",
  6139. GoodId: item.GoodId,
  6140. Status: 1,
  6141. Ctime: time.Now().Unix(),
  6142. Mtime: 0,
  6143. Count: 0,
  6144. StockCount: 0,
  6145. Creater: creater,
  6146. BatchNumberId: 0,
  6147. WarehouseOutId: 0,
  6148. }
  6149. service.CreateGoodErrcode(goodErrcode)
  6150. }
  6151. }
  6152. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6153. if len(list) == 0 {
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6155. return
  6156. }
  6157. for _, item := range list {
  6158. prepare := models.DialysisBeforePrepare{
  6159. UserOrgId: adminInfo.Org.Id,
  6160. PatientId: patient_id,
  6161. RecordDate: record_time,
  6162. GoodId: item.GoodId,
  6163. GoodTypeId: item.GoodTypeId,
  6164. Count: item.Count,
  6165. Creater: adminInfo.AdminUser.Id,
  6166. Status: 1,
  6167. Ctime: time.Now().Unix(),
  6168. StorehouseId: houseConfig.StorehouseOutInfo,
  6169. }
  6170. //清空准备表数据
  6171. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6172. if err != nil {
  6173. goodErrcode := models.XtGoodErrcode{
  6174. UserOrgId: item.OrgId,
  6175. Errcode: "自动出库清空准备表数据报错",
  6176. GoodId: item.GoodId,
  6177. Status: 1,
  6178. Ctime: time.Now().Unix(),
  6179. Mtime: 0,
  6180. Count: 0,
  6181. StockCount: 0,
  6182. Creater: creater,
  6183. BatchNumberId: 0,
  6184. WarehouseOutId: 0,
  6185. }
  6186. service.CreateGoodErrcode(goodErrcode)
  6187. }
  6188. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6189. if errs != nil {
  6190. goodErrcode := models.XtGoodErrcode{
  6191. UserOrgId: item.OrgId,
  6192. Errcode: "自动出库创建准备表数据报错",
  6193. GoodId: item.GoodId,
  6194. Status: 1,
  6195. Ctime: time.Now().Unix(),
  6196. Mtime: 0,
  6197. Count: 0,
  6198. StockCount: 0,
  6199. Creater: creater,
  6200. BatchNumberId: 0,
  6201. WarehouseOutId: 0,
  6202. }
  6203. service.CreateGoodErrcode(goodErrcode)
  6204. }
  6205. //查询默认仓库
  6206. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6207. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6208. var total_count int64
  6209. for _, it := range stockList {
  6210. total_count += it.StockCount
  6211. }
  6212. //基础库插入数据
  6213. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6214. if errcodes != nil {
  6215. goodErrcode := models.XtGoodErrcode{
  6216. UserOrgId: item.OrgId,
  6217. Errcode: "自动出库基础库插入数据",
  6218. GoodId: item.GoodId,
  6219. Status: 1,
  6220. Ctime: time.Now().Unix(),
  6221. Mtime: 0,
  6222. Count: 0,
  6223. StockCount: 0,
  6224. Creater: creater,
  6225. BatchNumberId: 0,
  6226. WarehouseOutId: 0,
  6227. }
  6228. service.CreateGoodErrcode(goodErrcode)
  6229. }
  6230. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6231. var flush_count int64
  6232. for _, it := range goodList {
  6233. flush_count += it.StockCount
  6234. }
  6235. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6236. if errsss != nil {
  6237. goodErrcode := models.XtGoodErrcode{
  6238. UserOrgId: item.OrgId,
  6239. Errcode: "自动出库剩余库存更新数据",
  6240. GoodId: item.GoodId,
  6241. Status: 1,
  6242. Ctime: time.Now().Unix(),
  6243. Mtime: 0,
  6244. Count: 0,
  6245. StockCount: 0,
  6246. Creater: creater,
  6247. BatchNumberId: 0,
  6248. WarehouseOutId: 0,
  6249. }
  6250. service.CreateGoodErrcode(goodErrcode)
  6251. }
  6252. }
  6253. }
  6254. //
  6255. } else if err == nil {
  6256. for _, item := range consumables {
  6257. //出库
  6258. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6259. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6260. if err != nil {
  6261. goodErrcode := models.XtGoodErrcode{
  6262. UserOrgId: adminInfo.Org.Id,
  6263. Errcode: "自动出库接口报错",
  6264. GoodId: 0,
  6265. Status: 1,
  6266. Ctime: time.Now().Unix(),
  6267. Mtime: 0,
  6268. Count: 0,
  6269. StockCount: 0,
  6270. Creater: creator,
  6271. BatchNumberId: 0,
  6272. WarehouseOutId: 0,
  6273. }
  6274. service.CreateGoodErrcode(goodErrcode)
  6275. }
  6276. //出库数量相加
  6277. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6278. if errss != nil {
  6279. goodErrcode := models.XtGoodErrcode{
  6280. UserOrgId: item.UserOrgId,
  6281. Errcode: "创建剩余库存字段报错",
  6282. GoodId: item.GoodId,
  6283. Status: 1,
  6284. Ctime: time.Now().Unix(),
  6285. Mtime: time.Now().Unix(),
  6286. Count: 0,
  6287. StockCount: 0,
  6288. Creater: item.Creater,
  6289. BatchNumberId: 0,
  6290. WarehouseOutId: 0,
  6291. }
  6292. service.CreateGoodErrcode(goodErrcode)
  6293. }
  6294. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6295. if len(list) == 0 {
  6296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6297. return
  6298. }
  6299. for _, item := range list {
  6300. prepare := models.DialysisBeforePrepare{
  6301. UserOrgId: adminInfo.Org.Id,
  6302. PatientId: patient_id,
  6303. RecordDate: record_time,
  6304. GoodId: item.GoodId,
  6305. GoodTypeId: item.GoodTypeId,
  6306. Count: item.Count,
  6307. Creater: adminInfo.AdminUser.Id,
  6308. Status: 1,
  6309. Ctime: time.Now().Unix(),
  6310. StorehouseId: houseConfig.StorehouseOutInfo,
  6311. }
  6312. //清空准备表数据
  6313. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6314. if errs != nil {
  6315. goodErrcode := models.XtGoodErrcode{
  6316. UserOrgId: adminInfo.Org.Id,
  6317. Errcode: "自动出库清空准备表数据报错",
  6318. GoodId: 0,
  6319. Status: 1,
  6320. Ctime: time.Now().Unix(),
  6321. Mtime: 0,
  6322. Count: 0,
  6323. StockCount: 0,
  6324. Creater: creator,
  6325. BatchNumberId: 0,
  6326. WarehouseOutId: 0,
  6327. }
  6328. service.CreateGoodErrcode(goodErrcode)
  6329. }
  6330. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6331. if errcodes != nil {
  6332. goodErrcode := models.XtGoodErrcode{
  6333. UserOrgId: adminInfo.Org.Id,
  6334. Errcode: "自动出库创建准备表数据报错",
  6335. GoodId: 0,
  6336. Status: 1,
  6337. Ctime: time.Now().Unix(),
  6338. Mtime: 0,
  6339. Count: 0,
  6340. StockCount: 0,
  6341. Creater: creator,
  6342. BatchNumberId: 0,
  6343. WarehouseOutId: 0,
  6344. }
  6345. service.CreateGoodErrcode(goodErrcode)
  6346. }
  6347. //查询默认仓库
  6348. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6349. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6350. var total_count int64
  6351. for _, it := range stockList {
  6352. total_count += it.StockCount
  6353. }
  6354. //基础库插入数据
  6355. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6356. if errcodes != nil {
  6357. goodErrcode := models.XtGoodErrcode{
  6358. UserOrgId: adminInfo.Org.Id,
  6359. Errcode: "自动出库基础库插入数据报错",
  6360. GoodId: 0,
  6361. Status: 1,
  6362. Ctime: time.Now().Unix(),
  6363. Mtime: 0,
  6364. Count: 0,
  6365. StockCount: 0,
  6366. Creater: creator,
  6367. BatchNumberId: 0,
  6368. WarehouseOutId: 0,
  6369. }
  6370. service.CreateGoodErrcode(goodErrcode)
  6371. }
  6372. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6373. var flush_count int64
  6374. for _, it := range goodList {
  6375. flush_count += it.StockCount
  6376. }
  6377. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6378. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6379. if errss != nil {
  6380. goodErrcode := models.XtGoodErrcode{
  6381. UserOrgId: item.OrgId,
  6382. Errcode: "自动出库剩余库存更新数据",
  6383. GoodId: item.GoodId,
  6384. Status: 1,
  6385. Ctime: time.Now().Unix(),
  6386. Mtime: 0,
  6387. Count: 0,
  6388. StockCount: 0,
  6389. Creater: creater,
  6390. BatchNumberId: 0,
  6391. WarehouseOutId: 0,
  6392. }
  6393. service.CreateGoodErrcode(goodErrcode)
  6394. }
  6395. }
  6396. }
  6397. }
  6398. c.ServeSuccessJSON(map[string]interface{}{
  6399. "msg": "提交成功",
  6400. "message": "2",
  6401. "good_name": "",
  6402. "specification_name": "",
  6403. })
  6404. return
  6405. }
  6406. if record.IsOpen == 1 {
  6407. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6408. //查询是否有库存
  6409. for _, item := range consumables {
  6410. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6411. if item.Count > warehouse.Count {
  6412. goodErrcode := models.XtGoodErrcode{
  6413. UserOrgId: item.UserOrgId,
  6414. Errcode: "自动出库库存不足",
  6415. GoodId: item.GoodId,
  6416. Status: 1,
  6417. Ctime: time.Now().Unix(),
  6418. Mtime: 0,
  6419. Count: 0,
  6420. StockCount: 0,
  6421. Creater: creator,
  6422. BatchNumberId: warehouse.ID,
  6423. WarehouseOutId: 0,
  6424. }
  6425. service.CreateGoodErrcode(goodErrcode)
  6426. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6427. c.ServeSuccessJSON(map[string]interface{}{
  6428. "message": "1",
  6429. "good_name": goodObj.GoodName,
  6430. "specification_name": goodObj.SpecificationName,
  6431. })
  6432. return
  6433. }
  6434. }
  6435. //查询是否有出库单
  6436. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6437. if err == gorm.ErrRecordNotFound {
  6438. //没有记录,则创建出库单
  6439. timeStr := time.Now().Format("2006-01-02")
  6440. timeArr := strings.Split(timeStr, "-")
  6441. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6442. total = total + 1
  6443. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6444. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6445. number = number + total
  6446. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6447. creater := adminInfo.AdminUser.Id
  6448. warehouseOut := models.WarehouseOut{
  6449. WarehouseOutOrderNumber: warehousing_out_order,
  6450. OperationTime: time.Now().Unix(),
  6451. OrgId: adminInfo.Org.Id,
  6452. Creater: creater,
  6453. Ctime: time.Now().Unix(),
  6454. Status: 1,
  6455. WarehouseOutTime: record_time,
  6456. Dealer: 0,
  6457. Manufacturer: 0,
  6458. Type: 1,
  6459. IsSys: 1,
  6460. StorehouseId: houseConfig.StorehouseOutInfo,
  6461. IsCheck: 1,
  6462. }
  6463. err := service.AddSigleWarehouseOut(&warehouseOut)
  6464. if err != nil {
  6465. goodErrcode := models.XtGoodErrcode{
  6466. UserOrgId: adminInfo.Org.Id,
  6467. Errcode: "创建出库单失败",
  6468. GoodId: 0,
  6469. Status: 1,
  6470. Ctime: time.Now().Unix(),
  6471. Mtime: 0,
  6472. Count: 0,
  6473. StockCount: 0,
  6474. Creater: creator,
  6475. BatchNumberId: 0,
  6476. WarehouseOutId: 0,
  6477. }
  6478. service.CreateGoodErrcode(goodErrcode)
  6479. utils.TraceLog("创建出库单失败 err = %v", err)
  6480. } else {
  6481. for _, item := range consumables {
  6482. //出库
  6483. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6484. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6485. if err == nil {
  6486. goodErrcode := models.XtGoodErrcode{
  6487. UserOrgId: adminInfo.Org.Id,
  6488. Errcode: "自动出库接口报错",
  6489. GoodId: 0,
  6490. Status: 1,
  6491. Ctime: time.Now().Unix(),
  6492. Mtime: 0,
  6493. Count: 0,
  6494. StockCount: 0,
  6495. Creater: creator,
  6496. BatchNumberId: 0,
  6497. WarehouseOutId: 0,
  6498. }
  6499. service.CreateGoodErrcode(goodErrcode)
  6500. utils.TraceLog("创建出库单失败 err = %v", err)
  6501. }
  6502. //查询
  6503. //出库数量相加
  6504. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6505. if errs != nil {
  6506. goodErrcode := models.XtGoodErrcode{
  6507. UserOrgId: item.UserOrgId,
  6508. Errcode: "创建剩余库存字段报错",
  6509. GoodId: item.GoodId,
  6510. Status: 1,
  6511. Ctime: time.Now().Unix(),
  6512. Mtime: 0,
  6513. Count: 0,
  6514. StockCount: 0,
  6515. Creater: creater,
  6516. BatchNumberId: 0,
  6517. WarehouseOutId: 0,
  6518. }
  6519. service.CreateGoodErrcode(goodErrcode)
  6520. }
  6521. }
  6522. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6523. if len(list) == 0 {
  6524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6525. return
  6526. }
  6527. for _, item := range list {
  6528. prepare := models.DialysisBeforePrepare{
  6529. UserOrgId: adminInfo.Org.Id,
  6530. PatientId: patient_id,
  6531. RecordDate: record_time,
  6532. GoodId: item.GoodId,
  6533. GoodTypeId: item.GoodTypeId,
  6534. Count: item.Count,
  6535. Creater: adminInfo.AdminUser.Id,
  6536. Status: 1,
  6537. Ctime: time.Now().Unix(),
  6538. StorehouseId: houseConfig.StorehouseOutInfo,
  6539. }
  6540. //清空准备表数据
  6541. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6542. if err != nil {
  6543. goodErrcode := models.XtGoodErrcode{
  6544. UserOrgId: item.OrgId,
  6545. Errcode: "自动出库清空准备表数据报错",
  6546. GoodId: item.GoodId,
  6547. Status: 1,
  6548. Ctime: time.Now().Unix(),
  6549. Mtime: 0,
  6550. Count: 0,
  6551. StockCount: 0,
  6552. Creater: creater,
  6553. BatchNumberId: 0,
  6554. WarehouseOutId: 0,
  6555. }
  6556. service.CreateGoodErrcode(goodErrcode)
  6557. }
  6558. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6559. if errs != nil {
  6560. goodErrcode := models.XtGoodErrcode{
  6561. UserOrgId: item.OrgId,
  6562. Errcode: "自动出库创建准备表数据报错",
  6563. GoodId: item.GoodId,
  6564. Status: 1,
  6565. Ctime: time.Now().Unix(),
  6566. Mtime: 0,
  6567. Count: 0,
  6568. StockCount: 0,
  6569. Creater: creater,
  6570. BatchNumberId: 0,
  6571. WarehouseOutId: 0,
  6572. }
  6573. service.CreateGoodErrcode(goodErrcode)
  6574. }
  6575. //查询默认仓库
  6576. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6577. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6578. var total_count int64
  6579. for _, it := range stockList {
  6580. total_count += it.StockCount
  6581. }
  6582. //基础库插入数据
  6583. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6584. if errcodes != nil {
  6585. goodErrcode := models.XtGoodErrcode{
  6586. UserOrgId: item.OrgId,
  6587. Errcode: "自动出库基础库插入数据",
  6588. GoodId: item.GoodId,
  6589. Status: 1,
  6590. Ctime: time.Now().Unix(),
  6591. Mtime: 0,
  6592. Count: 0,
  6593. StockCount: 0,
  6594. Creater: creater,
  6595. BatchNumberId: 0,
  6596. WarehouseOutId: 0,
  6597. }
  6598. service.CreateGoodErrcode(goodErrcode)
  6599. }
  6600. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6601. var flush_count int64
  6602. for _, it := range goodList {
  6603. flush_count += it.StockCount
  6604. }
  6605. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6606. if errsss != nil {
  6607. goodErrcode := models.XtGoodErrcode{
  6608. UserOrgId: item.OrgId,
  6609. Errcode: "自动出库剩余库存更新数据",
  6610. GoodId: item.GoodId,
  6611. Status: 1,
  6612. Ctime: time.Now().Unix(),
  6613. Mtime: 0,
  6614. Count: 0,
  6615. StockCount: 0,
  6616. Creater: creater,
  6617. BatchNumberId: 0,
  6618. WarehouseOutId: 0,
  6619. }
  6620. service.CreateGoodErrcode(goodErrcode)
  6621. }
  6622. }
  6623. }
  6624. //
  6625. } else if err == nil {
  6626. for _, item := range consumables {
  6627. //出库
  6628. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6629. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6630. if err != nil {
  6631. goodErrcode := models.XtGoodErrcode{
  6632. UserOrgId: adminInfo.Org.Id,
  6633. Errcode: "自动出库接口报错",
  6634. GoodId: 0,
  6635. Status: 1,
  6636. Ctime: time.Now().Unix(),
  6637. Mtime: 0,
  6638. Count: 0,
  6639. StockCount: 0,
  6640. Creater: creator,
  6641. BatchNumberId: 0,
  6642. WarehouseOutId: 0,
  6643. }
  6644. service.CreateGoodErrcode(goodErrcode)
  6645. }
  6646. //出库数量相加
  6647. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6648. if errss != nil {
  6649. goodErrcode := models.XtGoodErrcode{
  6650. UserOrgId: item.UserOrgId,
  6651. Errcode: "创建剩余库存字段报错",
  6652. GoodId: item.GoodId,
  6653. Status: 1,
  6654. Ctime: time.Now().Unix(),
  6655. Mtime: time.Now().Unix(),
  6656. Count: 0,
  6657. StockCount: 0,
  6658. Creater: item.Creater,
  6659. BatchNumberId: 0,
  6660. WarehouseOutId: 0,
  6661. }
  6662. service.CreateGoodErrcode(goodErrcode)
  6663. }
  6664. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6665. if len(list) == 0 {
  6666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6667. return
  6668. }
  6669. for _, item := range list {
  6670. prepare := models.DialysisBeforePrepare{
  6671. UserOrgId: adminInfo.Org.Id,
  6672. PatientId: patient_id,
  6673. RecordDate: record_time,
  6674. GoodId: item.GoodId,
  6675. GoodTypeId: item.GoodTypeId,
  6676. Count: item.Count,
  6677. Creater: adminInfo.AdminUser.Id,
  6678. Status: 1,
  6679. Ctime: time.Now().Unix(),
  6680. StorehouseId: houseConfig.StorehouseOutInfo,
  6681. }
  6682. //清空准备表数据
  6683. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6684. if errs != nil {
  6685. goodErrcode := models.XtGoodErrcode{
  6686. UserOrgId: adminInfo.Org.Id,
  6687. Errcode: "自动出库清空准备表数据报错",
  6688. GoodId: 0,
  6689. Status: 1,
  6690. Ctime: time.Now().Unix(),
  6691. Mtime: 0,
  6692. Count: 0,
  6693. StockCount: 0,
  6694. Creater: creator,
  6695. BatchNumberId: 0,
  6696. WarehouseOutId: 0,
  6697. }
  6698. service.CreateGoodErrcode(goodErrcode)
  6699. }
  6700. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6701. if errcodes != nil {
  6702. goodErrcode := models.XtGoodErrcode{
  6703. UserOrgId: adminInfo.Org.Id,
  6704. Errcode: "自动出库创建准备表数据报错",
  6705. GoodId: 0,
  6706. Status: 1,
  6707. Ctime: time.Now().Unix(),
  6708. Mtime: 0,
  6709. Count: 0,
  6710. StockCount: 0,
  6711. Creater: creator,
  6712. BatchNumberId: 0,
  6713. WarehouseOutId: 0,
  6714. }
  6715. service.CreateGoodErrcode(goodErrcode)
  6716. }
  6717. //查询默认仓库
  6718. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6719. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6720. var total_count int64
  6721. for _, it := range stockList {
  6722. total_count += it.StockCount
  6723. }
  6724. //基础库插入数据
  6725. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6726. if errcodes != nil {
  6727. goodErrcode := models.XtGoodErrcode{
  6728. UserOrgId: adminInfo.Org.Id,
  6729. Errcode: "自动出库基础库插入数据报错",
  6730. GoodId: 0,
  6731. Status: 1,
  6732. Ctime: time.Now().Unix(),
  6733. Mtime: 0,
  6734. Count: 0,
  6735. StockCount: 0,
  6736. Creater: creator,
  6737. BatchNumberId: 0,
  6738. WarehouseOutId: 0,
  6739. }
  6740. service.CreateGoodErrcode(goodErrcode)
  6741. }
  6742. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6743. var flush_count int64
  6744. for _, it := range goodList {
  6745. flush_count += it.StockCount
  6746. }
  6747. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6748. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6749. if errss != nil {
  6750. goodErrcode := models.XtGoodErrcode{
  6751. UserOrgId: item.OrgId,
  6752. Errcode: "自动出库剩余库存更新数据",
  6753. GoodId: item.GoodId,
  6754. Status: 1,
  6755. Ctime: time.Now().Unix(),
  6756. Mtime: 0,
  6757. Count: 0,
  6758. StockCount: 0,
  6759. Creater: creater,
  6760. BatchNumberId: 0,
  6761. WarehouseOutId: 0,
  6762. }
  6763. service.CreateGoodErrcode(goodErrcode)
  6764. }
  6765. }
  6766. }
  6767. }
  6768. c.ServeSuccessJSON(map[string]interface{}{
  6769. "msg": "提交成功",
  6770. "message": "2",
  6771. "good_name": "",
  6772. "specification_name": "",
  6773. })
  6774. return
  6775. } else {
  6776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6777. return
  6778. }
  6779. }
  6780. func (c *DialysisAPIController) EditConsumables() {
  6781. patient_id, _ := c.GetInt64("patient_id", 0)
  6782. record_date := c.GetString("record_time")
  6783. if patient_id <= 0 {
  6784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6785. return
  6786. }
  6787. adminInfo := c.GetMobileAdminUserInfo()
  6788. timeLayout := "2006-01-02"
  6789. loc, _ := time.LoadLocation("Local")
  6790. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6791. record_time := theRecordTime.Unix()
  6792. // 查询信息规挡的设置天数
  6793. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6794. if infor.ID > 0 && infor.WeekDay > 0 {
  6795. var cha_time int64
  6796. timeNowStr := time.Now().Format("2006-01-02")
  6797. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6798. //今日的日期减去设置的日期
  6799. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6800. if cha_time >= record_time {
  6801. //查询审核是否允许
  6802. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6803. //申请状态不允许的情况 拒绝修改
  6804. if infor.ApplicationStatus != 1 {
  6805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6806. return
  6807. }
  6808. }
  6809. }
  6810. dataBody := make(map[string]interface{}, 0)
  6811. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6812. if err != nil {
  6813. utils.ErrorLog(err.Error())
  6814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6815. return
  6816. }
  6817. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6818. var beforePrepares []*models.DialysisBeforePrepareGoods
  6819. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6820. var cancelbefor []*models.DialysisBeforePrepareGoods
  6821. var outbefor []*models.DialysisBeforePrepareGoods
  6822. //判断是否开启自动出库
  6823. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6824. if record.IsOpen == 1 {
  6825. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6826. goods, _ := dataBody["goods"].([]interface{})
  6827. if len(goods) > 0 {
  6828. for _, item := range goods {
  6829. items := item.(map[string]interface{})
  6830. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6831. utils.ErrorLog("good_id")
  6832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6833. return
  6834. }
  6835. good_id := int64(items["good_id"].(float64))
  6836. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6837. utils.ErrorLog("good_type_id")
  6838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6839. return
  6840. }
  6841. good_type_id := int64(items["good_type_id"].(float64))
  6842. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6843. utils.ErrorLog("count")
  6844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6845. return
  6846. }
  6847. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6848. commdity_code := items["commdity_code"].(string)
  6849. fmt.Println(commdity_code)
  6850. prepareGoods := &models.DialysisBeforePrepareGoods{
  6851. GoodTypeId: good_type_id,
  6852. GoodId: good_id,
  6853. Count: count,
  6854. StorehouseId: houseConfig.StorehouseOutInfo,
  6855. }
  6856. beforePrepares = append(beforePrepares, prepareGoods)
  6857. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6858. GoodTypeId: good_type_id,
  6859. GoodId: good_id,
  6860. Count: count,
  6861. StorehouseId: houseConfig.StorehouseOutInfo,
  6862. }
  6863. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6864. }
  6865. for _, item := range beforePrepares {
  6866. //1.查看该患者该耗材型号最后一次出库数量
  6867. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6868. //判断当前出库数量和最后一次出库数量的大小
  6869. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6870. if item.Count < goodInfo.Count {
  6871. cancelbefor = append(cancelbefor, item)
  6872. }
  6873. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6874. if item.Count > goodInfo.Count {
  6875. outbefor = append(outbefor, item)
  6876. }
  6877. //处理编辑耗材新增不了的问题
  6878. if goodInfo.Count == item.Count {
  6879. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6880. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6881. }
  6882. }
  6883. if len(cancelbefor) > 0 {
  6884. //退库
  6885. for _, item := range cancelbefor {
  6886. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6887. creater := adminInfo.AdminUser.Id
  6888. //查询该患者当天已经出库的耗材信息
  6889. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6890. var delete_count int64 = 0
  6891. delete_count = warehouseOutInfos.Count - item.Count
  6892. //增加库存数量
  6893. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6894. //减少实际出库库存数量
  6895. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6896. // 删除出库完成后,要增加对应批次的库存数量
  6897. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6898. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6899. //更新剩余库存
  6900. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6901. var flush_count int64
  6902. for _, it := range goodListOne {
  6903. flush_count += it.StockCount
  6904. }
  6905. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6906. //查询剩余库存
  6907. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6908. var sum_count int64
  6909. for _, item := range goodList {
  6910. sum_count += item.StockCount
  6911. }
  6912. // 在出库记录表里记录退库详情
  6913. warehouseOutInfo := &models.WarehouseOutInfo{
  6914. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6915. WarehouseOutId: warehouseOut.ID,
  6916. Status: 1,
  6917. Ctime: time.Now().Unix(),
  6918. OrgId: adminInfo.Org.Id,
  6919. Type: 1,
  6920. IsSys: 1,
  6921. SysRecordTime: record_time,
  6922. GoodTypeId: item.GoodTypeId,
  6923. GoodId: item.GoodId,
  6924. PatientId: patient_id,
  6925. ConsumableType: 2,
  6926. StorehouseId: houseConfig.StorehouseOutInfo,
  6927. IsCheck: 1,
  6928. OverCount: sum_count,
  6929. }
  6930. warehouseOutInfo.Count = item.Count
  6931. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6932. warehouseOutInfo.Price = stockInInfo.Price
  6933. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6934. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6935. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6936. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6937. warehouseOutInfo.Number = warehouseOutInfos.Number
  6938. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6939. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6940. //查找当天是否存在出库记录
  6941. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6942. if errcod == gorm.ErrRecordNotFound {
  6943. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6944. //插入详情明细表
  6945. stockFlow := models.VmStockFlow{
  6946. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6947. WarehouseOutId: warehouseOut.ID,
  6948. GoodId: item.GoodId,
  6949. Number: warehouseOutInfos.Number,
  6950. ProductDate: stockInInfo.ProductDate,
  6951. ExpireDate: stockInInfo.ExpiryDate,
  6952. Count: item.Count,
  6953. Price: stockInInfo.Price,
  6954. Status: 1,
  6955. Ctime: record_time,
  6956. UserOrgId: adminInfo.Org.Id,
  6957. Manufacturer: stockInInfo.Manufacturer,
  6958. Dealer: stockInInfo.Dealer,
  6959. LicenseNumber: stockInInfo.LicenseNumber,
  6960. IsEdit: 2,
  6961. Creator: creater,
  6962. SystemTime: record_time,
  6963. ConsumableType: 3,
  6964. WarehousingDetailId: 0,
  6965. IsSys: 1,
  6966. UpdateCreator: creater,
  6967. PatientId: patient_id,
  6968. StorehouseId: houseConfig.StorehouseOutInfo,
  6969. }
  6970. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6971. if errflow == gorm.ErrRecordNotFound {
  6972. //创建流水表
  6973. err := service.CreateStockFlowOne(stockFlow)
  6974. fmt.Println("err", err)
  6975. } else if errflow == nil {
  6976. //插入详情明细表
  6977. stockFlow := models.VmStockFlow{
  6978. ID: exsit.ID,
  6979. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6980. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6981. WarehouseOutId: warehouseOut.ID,
  6982. GoodId: item.GoodId,
  6983. Number: warehouseOutInfos.Number,
  6984. ProductDate: stockInInfo.ProductDate,
  6985. ExpireDate: stockInInfo.ExpiryDate,
  6986. Count: exsit.Count - delete_count,
  6987. Price: stockInInfo.Price,
  6988. Status: 1,
  6989. Ctime: record_time,
  6990. UserOrgId: adminInfo.Org.Id,
  6991. Manufacturer: stockInInfo.Manufacturer,
  6992. Dealer: stockInInfo.Dealer,
  6993. LicenseNumber: stockInInfo.LicenseNumber,
  6994. IsEdit: 2,
  6995. Creator: creater,
  6996. SystemTime: record_time,
  6997. ConsumableType: 3,
  6998. WarehousingDetailId: 0,
  6999. IsSys: 1,
  7000. UpdateCreator: creater,
  7001. PatientId: patient_id,
  7002. StorehouseId: houseConfig.StorehouseOutInfo,
  7003. }
  7004. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7005. }
  7006. } else if errcod == nil {
  7007. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7008. //查询剩余库存
  7009. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7010. var sum_count int64
  7011. for _, item := range goodList {
  7012. sum_count += item.StockCount
  7013. }
  7014. //创建退库单,生成退库数据
  7015. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7016. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7017. operation_time := time.Now().Unix()
  7018. creater := adminInfo.AdminUser.Id
  7019. //创建退库单
  7020. timeStr := time.Now().Format("2006-01-02")
  7021. timeArr := strings.Split(timeStr, "-")
  7022. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7023. total = total + 1
  7024. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7025. cancelStock := models.CancelStock{
  7026. OrderNumber: orderNumber,
  7027. OperaTime: operation_time,
  7028. OrgId: adminInfo.Org.Id,
  7029. Creater: creater,
  7030. Ctime: time.Now().Unix(),
  7031. Status: 1,
  7032. ReturnTime: record_time,
  7033. Type: 1,
  7034. StorehouseId: houseConfig.StorehouseOutInfo,
  7035. IsCheck: 1,
  7036. }
  7037. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7038. if msgerrkonde == gorm.ErrRecordNotFound {
  7039. service.AddSigleCancelStock(&cancelStock)
  7040. }
  7041. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7042. //查询是否有出库
  7043. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7044. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7045. deaerler, _ := service.GetDealerById(info.Dealer)
  7046. if info.ID > 0 {
  7047. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7048. cancelStockInfo := models.CancelStockInfo{
  7049. GoodId: item.GoodId,
  7050. CancelStockId: cancel.ID,
  7051. GoodTypeId: good.GoodTypeId,
  7052. Count: delete_count,
  7053. Price: info.Price,
  7054. Total: 0,
  7055. ProductDate: info.ProductDate,
  7056. ExpiryDate: info.ExpiryDate,
  7057. Ctime: time.Now().Unix(),
  7058. Status: 1,
  7059. OrgId: adminInfo.Org.Id,
  7060. OrderNumber: cancel.OrderNumber,
  7061. Type: 0,
  7062. Dealer: deaerler.DealerName,
  7063. Manufacturer: manufacturer.ManufacturerName,
  7064. Number: info.Number,
  7065. RegisterAccount: "",
  7066. Remark: "",
  7067. WarehouseInfoId: info.WarehouseInfotId,
  7068. PatientId: info.PatientId,
  7069. RecordDate: info.SysRecordTime,
  7070. StorehouseId: houseConfig.StorehouseOutInfo,
  7071. IsCheck: 1,
  7072. }
  7073. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7074. //退库数量增加
  7075. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7076. //查询剩余库存
  7077. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7078. var over_count int64
  7079. for _, it := range goodList {
  7080. over_count += it.StockCount
  7081. }
  7082. flow := models.VmStockFlow{
  7083. WarehousingId: info.WarehouseInfotId,
  7084. GoodId: item.GoodId,
  7085. Number: info.Number,
  7086. LicenseNumber: info.LicenseNumber,
  7087. Count: delete_count,
  7088. UserOrgId: adminInfo.Org.Id,
  7089. PatientId: patient_id,
  7090. SystemTime: info.SysRecordTime,
  7091. ConsumableType: 7,
  7092. IsSys: 0,
  7093. WarehousingOrder: "",
  7094. WarehouseOutId: info.WarehouseOutId,
  7095. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7096. IsEdit: 0,
  7097. CancelStockId: cancel.ID,
  7098. CancelOrderNumber: cancel.OrderNumber,
  7099. Manufacturer: manufacturer.ID,
  7100. Dealer: 0,
  7101. Creator: adminInfo.AdminUser.Id,
  7102. UpdateCreator: 0,
  7103. Status: 1,
  7104. Ctime: record_time,
  7105. Mtime: 0,
  7106. Price: info.Price,
  7107. WarehousingDetailId: info.WarehouseInfotId,
  7108. WarehouseOutDetailId: info.ID,
  7109. CancelOutDetailId: cancelInfo.ID,
  7110. ProductDate: info.ProductDate,
  7111. ExpireDate: info.ExpiryDate,
  7112. StorehouseId: houseConfig.StorehouseOutInfo,
  7113. OverCount: over_count,
  7114. }
  7115. service.CreateStockFlowOne(flow)
  7116. }
  7117. }
  7118. //更改自动出库的表格
  7119. details := models.BloodAutomaticReduceDetail{
  7120. WarehouseOutId: warehouseOutInfo.ID,
  7121. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7122. PatientId: patient_id,
  7123. Ctime: time.Now().Unix(),
  7124. Mtime: time.Now().Unix(),
  7125. Status: 1,
  7126. RecordTime: record_time,
  7127. OrgId: adminInfo.Org.Id,
  7128. GoodId: item.GoodId,
  7129. GoodTypeId: item.GoodTypeId,
  7130. Count: item.Count,
  7131. StorehouseId: houseConfig.StorehouseOutInfo,
  7132. }
  7133. //查询当天耗材是否已经存在数据
  7134. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7135. if errcode == gorm.ErrRecordNotFound {
  7136. service.CreateAutoReduceRecord(&details)
  7137. } else if errcode == nil {
  7138. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7139. service.CreateAutoReduceRecord(&details)
  7140. }
  7141. //查询默认仓库
  7142. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7143. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7144. var total_count int64
  7145. for _, it := range stockList {
  7146. total_count += it.StockCount
  7147. }
  7148. //基础库插入数据
  7149. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7150. }
  7151. }
  7152. if len(outbefor) > 0 {
  7153. //出库
  7154. for _, item := range outbefor {
  7155. var last_total int64
  7156. //1.查看该患者该耗材型号最后一次出库数量
  7157. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7158. //计算当前出库和最后一次出库数据相差数据
  7159. last_total = item.Count - goodInfoOne.Count
  7160. //查询该耗材的总库存
  7161. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7162. // 如果库存差大于剩余库存则提示库存不足
  7163. if last_total > wareinfo.StockCount {
  7164. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7165. c.ServeSuccessJSON(map[string]interface{}{
  7166. "message": "1",
  7167. "good_name": goodObj.GoodName,
  7168. "specification_name": goodObj.SpecificationName,
  7169. })
  7170. return
  7171. } else {
  7172. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7173. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7174. if err == gorm.ErrRecordNotFound {
  7175. //没有记录,则创建出库单
  7176. timeStr := time.Now().Format("2006-01-02")
  7177. timeArr := strings.Split(timeStr, "-")
  7178. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7179. total = total + 1
  7180. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7181. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7182. number = number + total
  7183. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7184. warehouseOut := models.WarehouseOut{
  7185. WarehouseOutOrderNumber: warehousing_out_order,
  7186. OperationTime: time.Now().Unix(),
  7187. OrgId: adminInfo.Org.Id,
  7188. Creater: adminInfo.AdminUser.Id,
  7189. Ctime: time.Now().Unix(),
  7190. Status: 1,
  7191. WarehouseOutTime: record_time,
  7192. Dealer: 0,
  7193. Manufacturer: 0,
  7194. Type: 1,
  7195. IsSys: 1,
  7196. StorehouseId: houseConfig.StorehouseOutInfo,
  7197. IsCheck: 1,
  7198. }
  7199. service.AddSigleWarehouseOut(&warehouseOut)
  7200. }
  7201. //出库
  7202. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7203. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7204. //1.查看该患者该耗材型号最后一次出库数量
  7205. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7206. prepare := models.DialysisBeforePrepare{
  7207. UserOrgId: adminInfo.Org.Id,
  7208. PatientId: patient_id,
  7209. RecordDate: record_time,
  7210. GoodId: item.GoodId,
  7211. GoodTypeId: item.GoodTypeId,
  7212. Count: item.Count - goodInfoTwo.Count,
  7213. Ctime: time.Now().Unix(),
  7214. Mtime: 0,
  7215. Creater: adminInfo.AdminUser.Id,
  7216. Modifier: adminInfo.AdminUser.Id,
  7217. Status: 1,
  7218. CommdityCode: "",
  7219. NewCount: 0,
  7220. ProjectId: 0,
  7221. StorehouseId: houseConfig.StorehouseOutInfo,
  7222. }
  7223. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7224. //增加出库数量
  7225. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7226. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7227. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7228. var total_count int64
  7229. for _, it := range stockList {
  7230. total_count += it.StockCount
  7231. }
  7232. //基础库插入数据
  7233. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7234. //剩余库存
  7235. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7236. var flush_count int64
  7237. for _, it := range goodList {
  7238. flush_count += it.StockCount
  7239. }
  7240. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7241. }
  7242. }
  7243. }
  7244. //查询今日出库数据
  7245. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7246. for _, it := range list {
  7247. prepare := models.DialysisBeforePrepare{
  7248. UserOrgId: it.OrgId,
  7249. PatientId: patient_id,
  7250. RecordDate: it.RecordTime,
  7251. GoodId: it.GoodId,
  7252. GoodTypeId: it.GoodTypeId,
  7253. Count: it.Count,
  7254. Ctime: time.Now().Unix(),
  7255. Creater: adminInfo.AdminUser.Id,
  7256. Status: 1,
  7257. StorehouseId: houseConfig.StorehouseOutInfo,
  7258. ProjectId: it.ProjectId,
  7259. }
  7260. //删除准备表数据
  7261. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7262. service.CreateDialysisBeforePrepareOne(&prepare)
  7263. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7264. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7265. var total_count int64
  7266. for _, it := range stockList {
  7267. total_count += it.StockCount
  7268. }
  7269. //基础库插入数据
  7270. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7271. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7272. var flush_count int64
  7273. for _, it := range goodList {
  7274. flush_count += it.StockCount
  7275. }
  7276. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7277. }
  7278. }
  7279. }
  7280. //更新自动出库的地方
  7281. var errs error
  7282. if errs == nil {
  7283. c.ServeSuccessJSON(map[string]interface{}{
  7284. "msg": "修改成功",
  7285. "message": "2",
  7286. "good_name": "",
  7287. "specification_name": "",
  7288. })
  7289. return
  7290. } else {
  7291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7292. return
  7293. }
  7294. }
  7295. }
  7296. func (c *DialysisAPIController) GetDialysisGoods() {
  7297. schedualDate := c.GetString("schedule_date")
  7298. schedule_type, _ := c.GetInt64("schedule_type")
  7299. partition_id, _ := c.GetInt64("partition_id")
  7300. page, _ := c.GetInt("page")
  7301. patient_id, _ := c.GetInt64("patient_id")
  7302. schedualEndDate := int64(0)
  7303. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7304. if parseDateErr != nil && len(schedualDate) != 0 {
  7305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7306. return
  7307. }
  7308. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7309. if parseDateErr != nil && len(schedualDate) != 0 {
  7310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7311. return
  7312. }
  7313. schedualEndDate = endDate.Unix()
  7314. adminUser := c.GetMobileAdminUserInfo()
  7315. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7316. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7317. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7318. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7319. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7320. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7321. //获取当天该病人的透析处方
  7322. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7323. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7324. if err == gorm.ErrRecordNotFound {
  7325. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7326. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7327. if patient_id != 0 {
  7328. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7329. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7330. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7331. //获取患者总的出库数据
  7332. item.LastAutomaticReduceDetail = goodUser
  7333. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7334. item.Project = project
  7335. for _, it := range item.AutomaticReduceDetail {
  7336. var total int64
  7337. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7338. for _, its := range auto {
  7339. total += its.Count
  7340. }
  7341. it.Count = total
  7342. }
  7343. }
  7344. }
  7345. c.ServeSuccessJSON(map[string]interface{}{
  7346. "dialysis_goods": dialysisGoods,
  7347. "good_type": goodTypes,
  7348. "total": total,
  7349. "prescribe": prescribe,
  7350. "good_info": good_info,
  7351. "warehouseOutList": warehouseOutList,
  7352. "config": config,
  7353. "outConfig": outConfig,
  7354. "settleConfig": settleConfig,
  7355. })
  7356. return
  7357. } else if err == nil {
  7358. //获取当天排班的每个患者的库存使用情况
  7359. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7360. //获取患者总的出库数据
  7361. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7362. if patient_id != 0 {
  7363. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7364. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7365. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7366. item.Project = project
  7367. item.LastAutomaticReduceDetail = goodUser
  7368. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7369. for _, it := range item.AutomaticReduceDetail {
  7370. var total int64
  7371. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7372. for _, its := range auto {
  7373. total += its.Count
  7374. }
  7375. it.Count = total
  7376. }
  7377. }
  7378. }
  7379. if err == nil {
  7380. c.ServeSuccessJSON(map[string]interface{}{
  7381. "dialysis_goods": dialysisGoods,
  7382. "good_type": goodTypes,
  7383. "total": total,
  7384. "prescribe": prescribe,
  7385. "good_info": good_info,
  7386. "project": project,
  7387. "warehouseOutList": warehouseOutList,
  7388. "config": config,
  7389. "outConfig": outConfig,
  7390. "settleConfig": settleConfig,
  7391. })
  7392. return
  7393. } else {
  7394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7395. return
  7396. }
  7397. } else if err != nil {
  7398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7399. return
  7400. }
  7401. }
  7402. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7403. start_time := c.GetString("start_time")
  7404. end_time := c.GetString("end_time")
  7405. timeLayout := "2006-01-02"
  7406. loc, _ := time.LoadLocation("Local")
  7407. var theStartTime int64
  7408. if len(start_time) > 0 {
  7409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7410. if err != nil {
  7411. utils.ErrorLog(err.Error())
  7412. }
  7413. theStartTime = theTime.Unix()
  7414. }
  7415. var theEndtTime int64
  7416. if len(end_time) > 0 {
  7417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7418. if err != nil {
  7419. utils.ErrorLog(err.Error())
  7420. }
  7421. theEndtTime = theTime.Unix()
  7422. }
  7423. adminUser := c.GetMobileAdminUserInfo()
  7424. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7425. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7426. if err == nil {
  7427. c.ServeSuccessJSON(map[string]interface{}{
  7428. "stock_out": outInfo,
  7429. "stockCount": stockCount,
  7430. })
  7431. return
  7432. } else {
  7433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7434. return
  7435. }
  7436. }
  7437. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7438. patient_id, _ := c.GetInt64("patient_id", 0)
  7439. record_time := c.GetString("record_time")
  7440. adminUser := c.GetMobileAdminUserInfo()
  7441. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7442. if parseDateErr != nil && len(record_time) != 0 {
  7443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7444. return
  7445. }
  7446. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7447. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7448. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7449. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7450. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7451. //获取今日患者的透析处方参数
  7452. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7453. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7454. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7455. c.ServeSuccessJSON(map[string]interface{}{
  7456. "good_type": goodTypes,
  7457. "good_user": goodUser,
  7458. "good_info": good_info,
  7459. "last_good_user": lastGoodUserDetial,
  7460. "project": project,
  7461. "prescription": prescribe,
  7462. "outInfo": outInfo,
  7463. "configs": configs,
  7464. })
  7465. return
  7466. }
  7467. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7468. patient_id, _ := c.GetInt64("patient_id", 0)
  7469. record_date := c.GetString("record_time")
  7470. timeLayout := "2006-01-02"
  7471. loc, _ := time.LoadLocation("Local")
  7472. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7473. record_time := theRecordTime.Unix()
  7474. adminInfo := c.GetMobileAdminUserInfo()
  7475. dataBody := make(map[string]interface{}, 0)
  7476. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7477. if err != nil {
  7478. utils.ErrorLog(err.Error())
  7479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7480. return
  7481. }
  7482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7483. var beforePrepares []*models.DialysisBeforePrepareGoods
  7484. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7485. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7486. goods, _ := dataBody["goods"].([]interface{})
  7487. if len(goods) > 0 {
  7488. for _, item := range goods {
  7489. items := item.(map[string]interface{})
  7490. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7491. utils.ErrorLog("good_id")
  7492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7493. return
  7494. }
  7495. good_id := int64(items["good_id"].(float64))
  7496. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7497. utils.ErrorLog("good_type_id")
  7498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7499. return
  7500. }
  7501. good_type_id := int64(items["good_type_id"].(float64))
  7502. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7503. utils.ErrorLog("count")
  7504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7505. return
  7506. }
  7507. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7508. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7509. utils.ErrorLog("project_id")
  7510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7511. return
  7512. }
  7513. project_id := int64(items["project_id"].(float64))
  7514. new_count := int64(items["new_count"].(float64))
  7515. old_count := int64(items["old_count"].(float64))
  7516. prepare := &models.DialysisBeforePrepareGoods{
  7517. GoodId: good_id,
  7518. GoodTypeId: good_type_id,
  7519. Count: count,
  7520. ProjectId: project_id,
  7521. StorehouseId: houseConfig.StorehouseOutInfo,
  7522. NewCount: new_count,
  7523. OldCount: old_count,
  7524. }
  7525. beforePrepares = append(beforePrepares, prepare)
  7526. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7527. GoodId: good_id,
  7528. GoodTypeId: good_type_id,
  7529. Count: count,
  7530. ProjectId: project_id,
  7531. StorehouseId: houseConfig.StorehouseOutInfo,
  7532. NewCount: new_count,
  7533. OldCount: old_count,
  7534. }
  7535. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7536. }
  7537. }
  7538. }
  7539. //查询是否有库存
  7540. for _, item := range beforePrepares {
  7541. if item.NewCount > 0 {
  7542. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7543. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7544. if item.Count > warehouse.Count {
  7545. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7546. c.ServeSuccessJSON(map[string]interface{}{
  7547. "message": "1",
  7548. "good_name": goodObj.GoodName,
  7549. "specification_name": goodObj.SpecificationName,
  7550. })
  7551. return
  7552. }
  7553. }
  7554. }
  7555. // 查询信息规挡的设置天数
  7556. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7557. if infor.ID > 0 && infor.WeekDay > 0 {
  7558. var cha_time int64
  7559. timeNowStr := time.Now().Format("2006-01-02")
  7560. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7561. //今日的日期减去设置的日期
  7562. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7563. if cha_time >= record_time {
  7564. //查询审核是否允许
  7565. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7566. //申请状态不允许的情况 拒绝修改
  7567. if infor.ApplicationStatus != 1 {
  7568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7569. return
  7570. }
  7571. }
  7572. }
  7573. //出库逻辑
  7574. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7575. if err != nil {
  7576. utils.ErrorLog(err.Error())
  7577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7578. return
  7579. }
  7580. finish := models.XtDialysisFinish{
  7581. IsFinish: 1,
  7582. UserOrgId: adminInfo.Org.Id,
  7583. Status: 1,
  7584. Ctime: time.Now().Unix(),
  7585. Mtime: 0,
  7586. Module: 11,
  7587. RecordDate: record_time,
  7588. Sourse: 1,
  7589. PatientId: patient_id,
  7590. }
  7591. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7592. if dialysisFinish.ID == 0 {
  7593. service.CreateDialysisFinish(finish)
  7594. }
  7595. //查询当天出库的数据
  7596. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7597. for _, item := range list {
  7598. prepare := models.DialysisBeforePrepare{
  7599. UserOrgId: item.OrgId,
  7600. PatientId: item.PatientId,
  7601. RecordDate: item.RecordTime,
  7602. GoodId: item.GoodId,
  7603. GoodTypeId: item.GoodTypeId,
  7604. Count: item.Count,
  7605. Creater: adminInfo.AdminUser.Id,
  7606. Status: 1,
  7607. Ctime: time.Now().Unix(),
  7608. ProjectId: item.ProjectId,
  7609. StorehouseId: houseConfig.StorehouseOutInfo,
  7610. }
  7611. //清空准备表的数据
  7612. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7613. //插入准备表数据
  7614. service.CreateDialysisBeforePrepareOne(&prepare)
  7615. //查询默认仓库
  7616. //查询默认仓库
  7617. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7618. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7619. var total_count int64
  7620. for _, it := range stockList {
  7621. total_count += it.StockCount
  7622. }
  7623. //基础库插入数据
  7624. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7625. ////更新剩余库存
  7626. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7627. var flush_count int64
  7628. for _, it := range goodList {
  7629. flush_count += it.StockCount
  7630. }
  7631. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7632. if errs != nil {
  7633. goodErrcode := models.XtGoodErrcode{
  7634. UserOrgId: item.OrgId,
  7635. Errcode: "手动出库更新剩余出库失败",
  7636. GoodId: item.GoodId,
  7637. Status: 1,
  7638. Ctime: time.Now().Unix(),
  7639. Mtime: 0,
  7640. Count: 0,
  7641. StockCount: 0,
  7642. Creater: adminInfo.AdminUser.Id,
  7643. BatchNumberId: 0,
  7644. WarehouseOutId: 0,
  7645. }
  7646. service.CreateGoodErrcode(goodErrcode)
  7647. }
  7648. }
  7649. //更新自动出库的地方
  7650. var errs error
  7651. if errs == nil {
  7652. c.ServeSuccessJSON(map[string]interface{}{
  7653. "msg": "修改成功",
  7654. "message": "2",
  7655. "good_name": "",
  7656. "specification_name": "",
  7657. })
  7658. return
  7659. } else {
  7660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7661. return
  7662. }
  7663. }
  7664. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7665. newArr = make([]*models.DialysisBeforePrepare, 0)
  7666. for i := 0; i < len(arr); i++ {
  7667. repeat := false
  7668. for j := i + 1; j < len(arr); j++ {
  7669. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7670. repeat = true
  7671. break
  7672. }
  7673. }
  7674. if !repeat {
  7675. newArr = append(newArr, arr[i])
  7676. }
  7677. }
  7678. return
  7679. }
  7680. func (c *DialysisAPIController) GetAllDrug() {
  7681. patient_id, _ := c.GetInt64("patient_id", 0)
  7682. adminInfo := c.GetMobileAdminUserInfo()
  7683. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7684. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7685. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7686. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7687. c.ServeSuccessJSON(map[string]interface{}{
  7688. "base_drug_config": drugStockConfig,
  7689. "private_drug_config": privateDrugConfig,
  7690. "base_drug_list": drugList,
  7691. "private_drug_list": privateDrugList,
  7692. })
  7693. }
  7694. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7695. newArr = make([]*models.DialysisBeforePrepare, 0)
  7696. for i := 0; i < len(arr); i++ {
  7697. repeat := false
  7698. for j := i + 1; j < len(arr); j++ {
  7699. if arr[i].GoodId == arr[j].GoodId {
  7700. repeat = true
  7701. break
  7702. }
  7703. }
  7704. if !repeat {
  7705. newArr = append(newArr, arr[i])
  7706. }
  7707. }
  7708. return
  7709. }
  7710. func (c *DialysisAPIController) GetDepartment() {
  7711. adminInfo := c.GetMobileAdminUserInfo()
  7712. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7713. if err == nil {
  7714. c.ServeSuccessJSON(map[string]interface{}{
  7715. "departments": departments,
  7716. })
  7717. } else {
  7718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7719. return
  7720. }
  7721. }
  7722. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7723. types, _ := c.GetInt("type", 0)
  7724. start_time := c.GetString("start_time")
  7725. end_time := c.GetString("end_time")
  7726. orgId := c.GetMobileAdminUserInfo().Org.Id
  7727. timeLayout := "2006-01-02"
  7728. loc, _ := time.LoadLocation("Local")
  7729. var startTime int64
  7730. if len(start_time) > 0 {
  7731. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7732. if err != nil {
  7733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7734. return
  7735. }
  7736. startTime = theTime.Unix()
  7737. }
  7738. var endTime int64
  7739. if len(end_time) > 0 {
  7740. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7741. if err != nil {
  7742. utils.ErrorLog(err.Error())
  7743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7744. return
  7745. }
  7746. endTime = theTime.Unix()
  7747. }
  7748. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7749. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7750. if err != nil {
  7751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7752. } else {
  7753. c.ServeSuccessJSON(map[string]interface{}{
  7754. "list": list,
  7755. "type": types,
  7756. "stockTotal": stockTotal,
  7757. })
  7758. }
  7759. }
  7760. func (c *DialysisAPIController) GetPrescriptionList() {
  7761. start_time := c.GetString("start_time")
  7762. end_time := c.GetString("end_time")
  7763. schedule_type, _ := c.GetInt64("schedule_type")
  7764. partion_id, _ := c.GetInt64("partion_id")
  7765. orgId := c.GetMobileAdminUserInfo().Org.Id
  7766. timeLayout := "2006-01-02"
  7767. loc, _ := time.LoadLocation("Local")
  7768. var startTime int64
  7769. if len(start_time) > 0 {
  7770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7771. if err != nil {
  7772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7773. return
  7774. }
  7775. startTime = theTime.Unix()
  7776. }
  7777. var endTime int64
  7778. if len(end_time) > 0 {
  7779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7780. if err != nil {
  7781. utils.ErrorLog(err.Error())
  7782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7783. return
  7784. }
  7785. endTime = theTime.Unix()
  7786. }
  7787. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7788. fmt.Println("schedulelist22222222", schedulelist)
  7789. c.ServeSuccessJSON(map[string]interface{}{
  7790. "list": schedulelist,
  7791. })
  7792. return
  7793. }
  7794. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7795. ids := c.GetString("ids")
  7796. //patient_id, _ := c.GetInt64("patient_id")
  7797. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7798. idArray := strings.Split(ids, ",")
  7799. err := service.BatchDeleteMonitor(idArray)
  7800. fmt.Print("err", err)
  7801. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7802. //redis := service.RedisClient()
  7803. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7804. //redis.Set(key, "", time.Second)
  7805. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7806. //redis.Set(keyOne, "", time.Second)
  7807. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7808. //redis.Close()
  7809. c.ServeSuccessJSON(map[string]interface{}{
  7810. "msg": "批量删除成功",
  7811. })
  7812. return
  7813. }
  7814. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7815. id, _ := c.GetInt64("id")
  7816. timeLayout := "2006-01-02"
  7817. loc, _ := time.LoadLocation("Local")
  7818. //start_time := time.Now().Format("2006-01-02")
  7819. start_time := c.GetString("start_time")
  7820. end_time := c.GetString("end_time")
  7821. var startdateunix int64
  7822. if len(start_time) > 0 {
  7823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7824. if err != nil {
  7825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7826. return
  7827. }
  7828. startdateunix = theTime.Unix()
  7829. }
  7830. var enddateunix int64
  7831. if len(end_time) > 0 {
  7832. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7833. if err != nil {
  7834. utils.ErrorLog(err.Error())
  7835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7836. return
  7837. }
  7838. enddateunix = theTime.Unix()
  7839. }
  7840. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7841. //nowTime := time.Now()
  7842. //endTime := nowTime.AddDate(-30, 0, 0)
  7843. //endTimes := endTime.Format("2006-01-02")
  7844. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7845. org_id := c.GetMobileAdminUserInfo().Org.Id
  7846. //if org_id == 10579 {
  7847. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7848. // c.ServeSuccessJSON(map[string]interface{}{
  7849. // "list": list,
  7850. // })
  7851. // return
  7852. //} else {
  7853. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7854. // c.ServeSuccessJSON(map[string]interface{}{
  7855. // "list": list,
  7856. // })
  7857. // return
  7858. //}
  7859. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7860. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7861. c.ServeSuccessJSON(map[string]interface{}{
  7862. "list": list,
  7863. })
  7864. return
  7865. } else {
  7866. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7867. c.ServeSuccessJSON(map[string]interface{}{
  7868. "list": list,
  7869. })
  7870. }
  7871. return
  7872. }
  7873. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7874. dataBody := make(map[string]interface{}, 0)
  7875. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7876. ids := c.GetString("ids")
  7877. idArray := strings.Split(ids, ",")
  7878. origin, _ := c.GetInt64("origin")
  7879. if origin == 1 {
  7880. err = service.BatchDeleteAdvice(idArray)
  7881. fmt.Print("err", err)
  7882. c.ServeSuccessJSON(map[string]interface{}{
  7883. "msg": "批量删除成功",
  7884. })
  7885. return
  7886. }
  7887. if origin == 2 {
  7888. service.BatchDeleteHisAdvice(idArray)
  7889. }
  7890. }
  7891. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7892. good_id, _ := c.GetInt64("good_id")
  7893. count, _ := c.GetInt64("count")
  7894. record_time, _ := c.GetInt64("record_time")
  7895. patient_id, _ := c.GetInt64("patient_id")
  7896. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7897. c.ServeSuccessJSON(map[string]interface{}{
  7898. "detail": detail,
  7899. })
  7900. return
  7901. }
  7902. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7903. good_id, _ := c.GetInt64("good_id")
  7904. record_time, _ := c.GetInt64("record_time")
  7905. patient_id, _ := c.GetInt64("patient_id")
  7906. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7907. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7908. fmt.Print("err", err)
  7909. c.ServeSuccessJSON(map[string]interface{}{
  7910. "msg": "批量删除成功",
  7911. })
  7912. return
  7913. }
  7914. func (c *DialysisAPIController) BatchAdviceCheck() {
  7915. ids := c.GetString("ids")
  7916. idArray := strings.Split(ids, ",")
  7917. creator, _ := c.GetInt64("creator")
  7918. origin, _ := c.GetInt64("origin")
  7919. if origin == 1 {
  7920. err := service.BatchAdviceCheck(idArray, creator)
  7921. fmt.Println(err)
  7922. list, _ := service.GetAdviceExecutionById(idArray)
  7923. c.ServeSuccessJSON(map[string]interface{}{
  7924. "list": list,
  7925. })
  7926. return
  7927. }
  7928. if origin == 2 {
  7929. service.BatchHisAdviceCheck(idArray, creator)
  7930. list, _ := service.GetHisAdviceExecutionById(idArray)
  7931. c.ServeSuccessJSON(map[string]interface{}{
  7932. "list": list,
  7933. })
  7934. return
  7935. }
  7936. }
  7937. func (c *DialysisAPIController) BatchAdviceExecution() {
  7938. ids := c.GetString("ids")
  7939. idArray := strings.Split(ids, ",")
  7940. executionTime := c.GetString("execution_time")
  7941. creator, _ := c.GetInt64("creator")
  7942. timeLayout := "2006-01-02 15:04:05"
  7943. loc, _ := time.LoadLocation("Local")
  7944. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7945. orgin, _ := c.GetInt64("origin")
  7946. if orgin == 1 {
  7947. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7948. list, _ := service.GetAdviceExecutionById(idArray)
  7949. fmt.Println(err)
  7950. c.ServeSuccessJSON(map[string]interface{}{
  7951. "list": list,
  7952. })
  7953. return
  7954. }
  7955. if orgin == 2 {
  7956. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7957. list, _ := service.GetHisAdviceExecutionById(idArray)
  7958. fmt.Println(err)
  7959. c.ServeSuccessJSON(map[string]interface{}{
  7960. "list": list,
  7961. })
  7962. return
  7963. }
  7964. }
  7965. func (c *DialysisAPIController) UpdateStockGoods() {
  7966. good_id, _ := c.GetInt64("good_id")
  7967. record_time, _ := c.GetInt64("record_time")
  7968. patient_id, _ := c.GetInt64("patient_id")
  7969. count, _ := c.GetInt64("count")
  7970. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7971. fmt.Print("err", err)
  7972. c.ServeSuccessJSON(map[string]interface{}{
  7973. "msg": "更新成功",
  7974. })
  7975. return
  7976. }
  7977. // 当前数据比上一次出库数据少
  7978. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7979. //查询该患者当天已经出库的耗材信息
  7980. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7981. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7982. for i := len(goods_yc) - 1; i >= 0; i-- {
  7983. goods_yc_temp := goods_yc[i]
  7984. for j := len(goods) - 1; j >= 0; j-- {
  7985. goods_temp := goods[j]
  7986. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7987. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7988. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7989. if goods_yc_temp.Count == goods_temp.Count {
  7990. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7991. goods = append(goods[:j], goods[j+1:]...)
  7992. break
  7993. }
  7994. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7995. if goods_yc_temp.Count > goods_temp.Count {
  7996. temp_count := goods_yc_temp.Count - goods_temp.Count
  7997. goods_yc[i].Count = temp_count
  7998. goods = append(goods[:j], goods[j+1:]...)
  7999. break
  8000. }
  8001. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8002. if goods_yc_temp.Count < goods_temp.Count {
  8003. temp_count := goods_temp.Count - goods_yc_temp.Count
  8004. goods[j].Count = temp_count
  8005. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8006. break
  8007. }
  8008. }
  8009. }
  8010. }
  8011. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8012. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8013. //退库
  8014. if len(goods_yc) > 0 {
  8015. for _, good_yc := range goods_yc {
  8016. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8017. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8018. }
  8019. }
  8020. return nil
  8021. }
  8022. // 耗材出库删除
  8023. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8024. // 先根据相关信息查询当天该耗材的出库信息
  8025. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8026. if err != nil {
  8027. return err
  8028. }
  8029. var delete_count int64 = 0
  8030. delete_count = warehouseOutInfos.Count - count
  8031. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8032. // 在出库记录表里记录退库详情
  8033. warehouseOutInfo := &models.WarehouseOutInfo{
  8034. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8035. WarehouseOutId: warehouseOut.ID,
  8036. Status: 1,
  8037. Ctime: time.Now().Unix(),
  8038. OrgId: orgID,
  8039. Type: 1,
  8040. IsSys: 1,
  8041. SysRecordTime: record_time,
  8042. GoodTypeId: good_yc.GoodTypeId,
  8043. GoodId: good_yc.GoodId,
  8044. PatientId: good_yc.PatientId,
  8045. ConsumableType: 2,
  8046. StorehouseId: houseConfig.StorehouseOutInfo,
  8047. IsCheck: 1,
  8048. }
  8049. warehouseOutInfo.Count = count
  8050. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8051. warehouseOutInfo.Price = stockInInfo.Price
  8052. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8053. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8054. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8055. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8056. warehouseOutInfo.Number = warehouseOutInfos.Number
  8057. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8058. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8059. //查找当天是否存在出库记录
  8060. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8061. if errcod == gorm.ErrRecordNotFound {
  8062. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8063. //插入详情明细表
  8064. stockFlow := models.VmStockFlow{
  8065. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8066. WarehouseOutId: warehouseOut.ID,
  8067. GoodId: good_yc.GoodId,
  8068. Number: warehouseOutInfos.Number,
  8069. ProductDate: stockInInfo.ProductDate,
  8070. ExpireDate: stockInInfo.ExpiryDate,
  8071. Count: count,
  8072. Price: stockInInfo.Price,
  8073. Status: 1,
  8074. Ctime: time.Now().Unix(),
  8075. UserOrgId: good_yc.OrgId,
  8076. Manufacturer: stockInInfo.Manufacturer,
  8077. Dealer: stockInInfo.Dealer,
  8078. LicenseNumber: stockInInfo.LicenseNumber,
  8079. IsEdit: 2,
  8080. Creator: creater,
  8081. SystemTime: record_time,
  8082. ConsumableType: 3,
  8083. WarehousingDetailId: 0,
  8084. IsSys: 1,
  8085. UpdateCreator: creater,
  8086. PatientId: patient_id,
  8087. StorehouseId: houseConfig.StorehouseOutInfo,
  8088. }
  8089. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8090. if errflow == gorm.ErrRecordNotFound {
  8091. //创建流水表
  8092. err := service.CreateStockFlowOne(stockFlow)
  8093. fmt.Println("err", err)
  8094. } else if errflow == nil {
  8095. //插入详情明细表
  8096. stockFlow := models.VmStockFlow{
  8097. ID: exsit.ID,
  8098. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8099. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8100. WarehouseOutId: warehouseOut.ID,
  8101. GoodId: good_yc.GoodId,
  8102. Number: warehouseOutInfos.Number,
  8103. ProductDate: stockInInfo.ProductDate,
  8104. ExpireDate: stockInInfo.ExpiryDate,
  8105. Count: exsit.Count - delete_count,
  8106. Price: stockInInfo.Price,
  8107. Status: 1,
  8108. Ctime: time.Now().Unix(),
  8109. UserOrgId: good_yc.OrgId,
  8110. Manufacturer: stockInInfo.Manufacturer,
  8111. Dealer: stockInInfo.Dealer,
  8112. LicenseNumber: stockInInfo.LicenseNumber,
  8113. IsEdit: 2,
  8114. Creator: creater,
  8115. SystemTime: record_time,
  8116. ConsumableType: 3,
  8117. WarehousingDetailId: 0,
  8118. IsSys: 1,
  8119. UpdateCreator: creater,
  8120. PatientId: patient_id,
  8121. StorehouseId: houseConfig.StorehouseOutInfo,
  8122. }
  8123. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8124. }
  8125. if errOne != nil {
  8126. return errOne
  8127. }
  8128. } else if errcod == nil {
  8129. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8130. //插入详情明细表
  8131. stockFlow := models.VmStockFlow{
  8132. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8133. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8134. WarehouseOutId: warehouseOut.ID,
  8135. GoodId: good_yc.GoodId,
  8136. Number: warehouseOutInfos.Number,
  8137. ProductDate: stockInInfo.ProductDate,
  8138. ExpireDate: stockInInfo.ExpiryDate,
  8139. Count: count,
  8140. Price: stockInInfo.Price,
  8141. Status: 1,
  8142. Ctime: time.Now().Unix(),
  8143. UserOrgId: good_yc.OrgId,
  8144. Manufacturer: stockInInfo.Manufacturer,
  8145. Dealer: stockInInfo.Dealer,
  8146. LicenseNumber: stockInInfo.LicenseNumber,
  8147. IsEdit: 2,
  8148. Creator: creater,
  8149. SystemTime: record_time,
  8150. ConsumableType: 3,
  8151. WarehousingDetailId: 0,
  8152. IsSys: 1,
  8153. UpdateCreator: creater,
  8154. PatientId: patient_id,
  8155. ReturnCount: delete_count,
  8156. StorehouseId: houseConfig.StorehouseOutInfo,
  8157. }
  8158. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8159. if errflows == gorm.ErrRecordNotFound {
  8160. //创建流水表
  8161. service.CreateStockFlowOne(stockFlow)
  8162. } else if errflows == nil {
  8163. stockFlow := models.VmStockFlow{
  8164. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8165. ID: exsit.ID,
  8166. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8167. WarehouseOutId: warehouseOut.ID,
  8168. GoodId: good_yc.GoodId,
  8169. Number: warehouseOutInfos.Number,
  8170. ProductDate: stockInInfo.ProductDate,
  8171. ExpireDate: stockInInfo.ExpiryDate,
  8172. Count: exsit.Count - delete_count,
  8173. Price: stockInInfo.Price,
  8174. Status: 1,
  8175. Ctime: time.Now().Unix(),
  8176. UserOrgId: good_yc.OrgId,
  8177. Manufacturer: stockInInfo.Manufacturer,
  8178. Dealer: stockInInfo.Dealer,
  8179. LicenseNumber: stockInInfo.LicenseNumber,
  8180. IsEdit: 2,
  8181. Creator: creater,
  8182. SystemTime: record_time,
  8183. ConsumableType: 3,
  8184. WarehousingDetailId: 0,
  8185. IsSys: 1,
  8186. UpdateCreator: creater,
  8187. PatientId: patient_id,
  8188. ReturnCount: delete_count,
  8189. StorehouseId: houseConfig.StorehouseOutInfo,
  8190. }
  8191. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8192. }
  8193. }
  8194. //更改自动出库的表格
  8195. details := models.BloodAutomaticReduceDetail{
  8196. WarehouseOutId: warehouseOutInfo.ID,
  8197. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8198. PatientId: patient_id,
  8199. Ctime: time.Now().Unix(),
  8200. Mtime: time.Now().Unix(),
  8201. Status: 1,
  8202. RecordTime: record_time,
  8203. OrgId: orgID,
  8204. GoodId: good_yc.GoodId,
  8205. GoodTypeId: good_yc.GoodTypeId,
  8206. Count: count,
  8207. StorehouseId: houseConfig.StorehouseOutInfo,
  8208. }
  8209. //查询当天耗材是否已经存在数据
  8210. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8211. if errcode == gorm.ErrRecordNotFound {
  8212. errTwo := service.CreateAutoReduceRecord(&details)
  8213. if errTwo != nil {
  8214. return errTwo
  8215. }
  8216. } else if errcode == nil {
  8217. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8218. service.CreateAutoReduceRecord(&details)
  8219. }
  8220. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8221. //增加出库库存数量
  8222. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8223. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8224. fmt.Println("errOne", errOne)
  8225. // 删除出库完成后,要增加对应批次的库存数量
  8226. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8227. if errThree != nil {
  8228. return errThree
  8229. }
  8230. if good_yc.Count == 0 {
  8231. return nil
  8232. } else {
  8233. return errors.New("退库和出库数据不匹配")
  8234. }
  8235. }
  8236. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8237. //查询该患者当天已经出库的耗材信息
  8238. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8239. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8240. for i := len(goods_yc) - 1; i >= 0; i-- {
  8241. goods_yc_temp := goods_yc[i]
  8242. for j := len(goods) - 1; j >= 0; j-- {
  8243. goods_temp := goods[j]
  8244. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8245. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8246. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8247. if goods_yc_temp.Count == goods_temp.Count {
  8248. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8249. goods = append(goods[:j], goods[j+1:]...)
  8250. break
  8251. }
  8252. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8253. if goods_yc_temp.Count > goods_temp.Count {
  8254. temp_count := goods_yc_temp.Count - goods_temp.Count
  8255. goods_yc[i].Count = temp_count
  8256. goods = append(goods[:j], goods[j+1:]...)
  8257. break
  8258. }
  8259. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8260. if goods_yc_temp.Count < goods_temp.Count {
  8261. temp_count := goods_temp.Count - goods_yc_temp.Count
  8262. goods[j].Count = temp_count
  8263. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8264. break
  8265. }
  8266. }
  8267. }
  8268. }
  8269. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8270. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8271. fmt.Println("剩余需要出库的", len(goods))
  8272. if len(goods) > 0 {
  8273. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8274. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8275. if err == gorm.ErrRecordNotFound {
  8276. //没有记录,则创建出库单
  8277. timeStr := time.Now().Format("2006-01-02")
  8278. timeArr := strings.Split(timeStr, "-")
  8279. total, _ := service.FindAllWarehouseOut(orgID)
  8280. total = total + 1
  8281. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8282. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8283. number = number + total
  8284. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8285. warehouseOut := models.WarehouseOut{
  8286. WarehouseOutOrderNumber: warehousing_out_order,
  8287. OperationTime: time.Now().Unix(),
  8288. OrgId: orgID,
  8289. Creater: creater,
  8290. Ctime: time.Now().Unix(),
  8291. Status: 1,
  8292. WarehouseOutTime: record_time,
  8293. Dealer: 0,
  8294. Manufacturer: 0,
  8295. Type: 1,
  8296. IsSys: 1,
  8297. StorehouseId: houseConfig.StorehouseOutInfo,
  8298. IsCheck: 1,
  8299. }
  8300. err := service.AddSigleWarehouseOut(&warehouseOut)
  8301. if err != nil {
  8302. utils.TraceLog("创建出库单失败 err = %v", err)
  8303. return err
  8304. } else {
  8305. out = warehouseOut
  8306. }
  8307. }
  8308. for _, item := range goods {
  8309. var newCount int64 = 0
  8310. for _, it := range goodOne {
  8311. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8312. newCount = it.Count
  8313. }
  8314. }
  8315. prepare := models.DialysisBeforePrepare{
  8316. GoodTypeId: item.GoodTypeId,
  8317. GoodId: item.GoodId,
  8318. Count: item.Count,
  8319. StorehouseId: houseConfig.StorehouseOutInfo,
  8320. }
  8321. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8322. //增加出库数量
  8323. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8324. }
  8325. }
  8326. if len(goods_yc) > 0 {
  8327. for _, good_yc := range goods_yc {
  8328. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8329. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8330. }
  8331. }
  8332. return nil
  8333. }
  8334. // 耗材出库删除
  8335. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8336. // 先根据相关信息查询当天该耗材的出库信息
  8337. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8338. if err != nil {
  8339. return err
  8340. }
  8341. var delete_count int64 = 0
  8342. for _, ware := range warehouseOutInfos {
  8343. // 判断当前出库的数据和删除出库数量
  8344. if good_yc.Count <= ware.Count {
  8345. delete_count = good_yc.Count
  8346. } else {
  8347. delete_count = ware.Count
  8348. }
  8349. warehouseOutInfo := &models.WarehouseOutInfo{
  8350. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8351. WarehouseOutId: warehouseOut.ID,
  8352. Status: 1,
  8353. Ctime: time.Now().Unix(),
  8354. Remark: "",
  8355. OrgId: orgID,
  8356. Type: 1,
  8357. Manufacturer: 0,
  8358. Dealer: 0,
  8359. IsSys: 0,
  8360. SysRecordTime: record_time,
  8361. GoodTypeId: good_yc.GoodTypeId,
  8362. GoodId: good_yc.GoodId,
  8363. StorehouseId: warehouseOut.StorehouseId,
  8364. IsCheck: 1,
  8365. }
  8366. warehouseOutInfo.Count = delete_count
  8367. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8368. warehouseOutInfo.Price = stockInInfo.Price
  8369. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8370. if errOne != nil {
  8371. return errOne
  8372. }
  8373. // 删除出库完成后,要改变流水库存(有疑问)
  8374. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8375. fmt.Println("errOne", errOne)
  8376. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8377. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8378. //扣减出库数量
  8379. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8380. if errThree != nil {
  8381. return errThree
  8382. }
  8383. }
  8384. if good_yc.Count == 0 {
  8385. return nil
  8386. } else {
  8387. return errors.New("退库和出库数据不匹配")
  8388. }
  8389. }
  8390. func (this *DialysisAPIController) GetMobileScheduleList() {
  8391. limit, _ := this.GetInt64("limit")
  8392. page, _ := this.GetInt64("page")
  8393. type_options_visible, _ := this.GetInt64("type_options_visible")
  8394. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8395. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8396. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8397. }
  8398. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8399. newArr = make([]*models.HisPrescriptionProject, 0)
  8400. for i := 0; i < len(arr); i++ {
  8401. repeat := false
  8402. for j := i + 1; j < len(arr); j++ {
  8403. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8404. repeat = true
  8405. break
  8406. }
  8407. }
  8408. if !repeat {
  8409. newArr = append(newArr, arr[i])
  8410. }
  8411. }
  8412. return
  8413. }
  8414. func (this *DialysisAPIController) GetRoleList() {
  8415. admin_user_id, _ := this.GetInt64("admin_user_id")
  8416. orgid := this.GetMobileAdminUserInfo().Org.Id
  8417. list, err := service.GetRoleList(orgid, admin_user_id)
  8418. fmt.Println(err)
  8419. this.ServeSuccessJSON(map[string]interface{}{
  8420. "list": list,
  8421. })
  8422. return
  8423. }
  8424. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8425. // 先根据相关信息查询当天该耗材的出库信息
  8426. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8427. if err != nil {
  8428. return err
  8429. }
  8430. var delete_count int64 = 0
  8431. delete_count = warehouseOutInfos.Count - count
  8432. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8433. // 删除出库完成后,要增加对应批次的库存数量
  8434. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8435. if errThree != nil {
  8436. return errThree
  8437. }
  8438. //增加退库数量
  8439. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8440. //扣减出库数量
  8441. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8442. //查询剩余库存
  8443. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8444. var sum_count int64
  8445. for _, item := range goodList {
  8446. sum_count += item.StockCount
  8447. }
  8448. // 在出库记录表里记录退库详情
  8449. warehouseOutInfo := &models.WarehouseOutInfo{
  8450. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8451. WarehouseOutId: warehouseOut.ID,
  8452. Status: 1,
  8453. Ctime: time.Now().Unix(),
  8454. OrgId: orgID,
  8455. Type: 1,
  8456. IsSys: 1,
  8457. SysRecordTime: record_time,
  8458. GoodTypeId: good_yc.GoodTypeId,
  8459. GoodId: good_yc.GoodId,
  8460. PatientId: good_yc.PatientId,
  8461. ConsumableType: 2,
  8462. StorehouseId: houseConfig.StorehouseOutInfo,
  8463. IsCheck: 1,
  8464. OverCount: sum_count,
  8465. }
  8466. warehouseOutInfo.Count = count
  8467. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8468. warehouseOutInfo.Price = stockInInfo.Price
  8469. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8470. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8471. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8472. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8473. warehouseOutInfo.Number = warehouseOutInfos.Number
  8474. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8475. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8476. //查找当天是否存在出库记录
  8477. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8478. if errcod == gorm.ErrRecordNotFound {
  8479. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8480. //插入详情明细表
  8481. if errOne != nil {
  8482. return errOne
  8483. }
  8484. //插入详情明细表
  8485. stockFlow := models.VmStockFlow{
  8486. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8487. WarehouseOutId: warehouseOut.ID,
  8488. GoodId: good_yc.GoodId,
  8489. Number: warehouseOutInfos.Number,
  8490. ProductDate: stockInInfo.ProductDate,
  8491. ExpireDate: stockInInfo.ExpiryDate,
  8492. Count: count,
  8493. Price: stockInInfo.Price,
  8494. Status: 1,
  8495. Ctime: record_time,
  8496. UserOrgId: good_yc.OrgId,
  8497. Manufacturer: stockInInfo.Manufacturer,
  8498. Dealer: stockInInfo.Dealer,
  8499. LicenseNumber: stockInInfo.LicenseNumber,
  8500. IsEdit: 2,
  8501. Creator: creater,
  8502. SystemTime: record_time,
  8503. ConsumableType: 3,
  8504. WarehousingDetailId: 0,
  8505. IsSys: 1,
  8506. UpdateCreator: creater,
  8507. PatientId: patient_id,
  8508. StorehouseId: houseConfig.StorehouseOutInfo,
  8509. OverCount: sum_count,
  8510. ProjectId: good_yc.ProjectId,
  8511. }
  8512. err := service.CreateStockFlowOne(stockFlow)
  8513. fmt.Println("err", err)
  8514. } else if errcod == nil {
  8515. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8516. }
  8517. //创建退库单
  8518. operation_time := time.Now().Unix()
  8519. //创建退库单
  8520. timeStr := time.Now().Format("2006-01-02")
  8521. timeArr := strings.Split(timeStr, "-")
  8522. total, _ := service.FindAllCancelStockTotal(orgID)
  8523. total = total + 1
  8524. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8525. cancelStock := models.CancelStock{
  8526. OrderNumber: orderNumber,
  8527. OperaTime: operation_time,
  8528. OrgId: orgID,
  8529. Creater: warehouseOut.Creater,
  8530. Ctime: time.Now().Unix(),
  8531. Status: 1,
  8532. ReturnTime: record_time,
  8533. Type: 1,
  8534. StorehouseId: stockInInfo.StorehouseId,
  8535. IsCheck: 1,
  8536. }
  8537. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8538. if msgerrkonde == gorm.ErrRecordNotFound {
  8539. service.AddSigleCancelStock(&cancelStock)
  8540. }
  8541. cancel, _ := service.GetLastCancelStockById(orgID)
  8542. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8543. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8544. cancelStockInfo := models.CancelStockInfo{
  8545. GoodId: stockInInfo.GoodId,
  8546. CancelStockId: cancel.ID,
  8547. GoodTypeId: stockInInfo.GoodTypeId,
  8548. Count: delete_count,
  8549. Price: stockInInfo.PackingPrice,
  8550. Total: 0,
  8551. ProductDate: stockInInfo.ProductDate,
  8552. ExpiryDate: stockInInfo.ExpiryDate,
  8553. Ctime: record_time,
  8554. Status: 1,
  8555. OrgId: orgID,
  8556. OrderNumber: cancel.OrderNumber,
  8557. Type: 0,
  8558. Dealer: deaerler.DealerName,
  8559. Manufacturer: manufacturer.ManufacturerName,
  8560. Number: stockInInfo.Number,
  8561. RegisterAccount: "",
  8562. Remark: "",
  8563. WarehouseInfoId: stockInInfo.ID,
  8564. PatientId: patient_id,
  8565. RecordDate: record_time,
  8566. StorehouseId: stockInInfo.StorehouseId,
  8567. IsCheck: 1,
  8568. }
  8569. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8570. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8571. flow := models.VmStockFlow{
  8572. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8573. GoodId: good_yc.GoodId,
  8574. Number: warehouseOutInfos.Number,
  8575. LicenseNumber: stockInInfo.LicenseNumber,
  8576. Count: delete_count,
  8577. UserOrgId: orgID,
  8578. PatientId: patient_id,
  8579. SystemTime: record_time,
  8580. ConsumableType: 7,
  8581. IsSys: 0,
  8582. WarehousingOrder: "",
  8583. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8584. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8585. IsEdit: 0,
  8586. CancelStockId: cancel.ID,
  8587. CancelOrderNumber: cancel.OrderNumber,
  8588. Manufacturer: manufacturer.ID,
  8589. Dealer: 0,
  8590. Creator: warehouseOut.Creater,
  8591. UpdateCreator: 0,
  8592. Status: 1,
  8593. Ctime: record_time,
  8594. Mtime: 0,
  8595. Price: stockInInfo.Price,
  8596. WarehousingDetailId: stockInInfo.ID,
  8597. WarehouseOutDetailId: warehouseOutInfos.ID,
  8598. CancelOutDetailId: cancelInfo.ID,
  8599. ProductDate: stockInInfo.ProductDate,
  8600. ExpireDate: stockInInfo.ExpiryDate,
  8601. StorehouseId: houseConfig.StorehouseOutInfo,
  8602. OverCount: sum_count,
  8603. }
  8604. service.CreateStockFlowOne(flow)
  8605. //更改自动出库的表格
  8606. details := models.BloodAutomaticReduceDetail{
  8607. WarehouseOutId: warehouseOutInfo.ID,
  8608. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8609. PatientId: patient_id,
  8610. Ctime: time.Now().Unix(),
  8611. Mtime: time.Now().Unix(),
  8612. Status: 1,
  8613. RecordTime: record_time,
  8614. OrgId: orgID,
  8615. GoodId: good_yc.GoodId,
  8616. GoodTypeId: good_yc.GoodTypeId,
  8617. Count: count,
  8618. StorehouseId: houseConfig.StorehouseOutInfo,
  8619. }
  8620. //查询当天耗材是否已经存在数据
  8621. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8622. if errcode == gorm.ErrRecordNotFound {
  8623. errTwo := service.CreateAutoReduceRecord(&details)
  8624. if errTwo != nil {
  8625. return errTwo
  8626. }
  8627. } else if errcode == nil {
  8628. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8629. service.CreateAutoReduceRecord(&details)
  8630. }
  8631. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8632. //增加出库库存数量
  8633. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8634. if good_yc.Count == 0 {
  8635. return nil
  8636. } else {
  8637. return errors.New("退库和出库数据不匹配")
  8638. }
  8639. }
  8640. func (this *DialysisAPIController) SavePatientSign() {
  8641. adminUserInfo := this.GetMobileAdminUserInfo()
  8642. patient_id, _ := this.GetInt64("patient_id")
  8643. dialysis_date, _ := this.GetInt64("dialysis_date")
  8644. orgid := adminUserInfo.Org.Id
  8645. var esdata models.DialysisOrder
  8646. var err error
  8647. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8649. return
  8650. }
  8651. esdata.Hash = esdata.Hash
  8652. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8653. order := models.DialysisOrder{
  8654. Hash: esdata.Hash,
  8655. Url: esdata.Url,
  8656. }
  8657. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8658. redis := service.RedisClient()
  8659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8660. redis.Set(key, "", time.Second)
  8661. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8662. //清空key 值
  8663. redis.Set(keyOne, "", time.Second)
  8664. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8665. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8666. //redis.Set(keyTwo, "", time.Second)
  8667. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8668. redis.Set(keyThree, "", time.Second)
  8669. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8670. redis.Set(keyFour, "", time.Second)
  8671. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8672. redis.Set(keyFive, "", time.Second)
  8673. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8674. redis.Set(keySix, "", time.Second)
  8675. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8676. redis.Set(keySeven, "", time.Second)
  8677. if err != nil {
  8678. fmt.Println(err)
  8679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8680. return
  8681. }
  8682. this.ServeSuccessJSON(map[string]interface{}{
  8683. "electronic_signature": esdata,
  8684. })
  8685. }
  8686. func (this *DialysisAPIController) GetPatientSign() {
  8687. patient_id, _ := this.GetInt64("patient_id")
  8688. dialysis_date, _ := this.GetInt64("dialysis_date")
  8689. adminUserInfo := this.GetMobileAdminUserInfo()
  8690. orgId := adminUserInfo.Org.Id
  8691. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8692. if err != nil {
  8693. fmt.Println(err)
  8694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8695. return
  8696. }
  8697. this.ServeSuccessJSON(map[string]interface{}{
  8698. "dialysisOrder": dialysisOrder,
  8699. })
  8700. }
  8701. func (this *DialysisAPIController) GetScheduleByPatient() {
  8702. patient_id, _ := this.GetInt64("patient_id")
  8703. schedule_date, _ := this.GetInt64("schedule_date")
  8704. orgid := this.GetMobileAdminUserInfo().Org.Id
  8705. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8706. this.ServeSuccessJSON(map[string]interface{}{
  8707. "schedule": schedule,
  8708. })
  8709. }
  8710. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8711. org_id := this.GetMobileAdminUserInfo().Org.Id
  8712. patient_id, _ := this.GetInt64("patient_id")
  8713. schedule_date, _ := this.GetInt64("schedule_date")
  8714. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8715. this.ServeSuccessJSON(map[string]interface{}{
  8716. "order": order,
  8717. })
  8718. }
  8719. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8720. org_id := this.GetMobileAdminUserInfo().Org.Id
  8721. schedule_date := this.GetString("schedule_date")
  8722. schedule_type, _ := this.GetInt64("schedule_type")
  8723. timeLayout := "2006-01-02"
  8724. loc, _ := time.LoadLocation("Local")
  8725. var startdateunix int64
  8726. if len(schedule_date) > 0 {
  8727. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8728. if err != nil {
  8729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8730. return
  8731. }
  8732. startdateunix = theTime.Unix()
  8733. }
  8734. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8735. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8736. devices, _ := service.GetAllDevicetByListSix(org_id)
  8737. for key, item := range scheduals {
  8738. // 床位信息
  8739. for _, device := range devices {
  8740. if item.BedId == device.ID {
  8741. scheduals[key].DeviceNumber = device
  8742. break
  8743. }
  8744. }
  8745. }
  8746. this.ServeSuccessJSON(map[string]interface{}{
  8747. "list": list,
  8748. "scheduals": scheduals,
  8749. })
  8750. }
  8751. func (this *DialysisAPIController) SavePatientPicture() {
  8752. patient_id, _ := this.GetInt64("patient_id")
  8753. dialysis_date, _ := this.GetInt64("schedule_date")
  8754. avatar := this.GetString("avatar")
  8755. fmt.Println("patient_id", patient_id)
  8756. orgId := this.GetMobileAdminUserInfo().Org.Id
  8757. order := models.DialysisOrder{
  8758. Url: avatar,
  8759. }
  8760. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8761. redis := service.RedisClient()
  8762. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8763. redis.Set(key, "", time.Second)
  8764. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8765. //清空key 值
  8766. redis.Set(keyOne, "", time.Second)
  8767. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8768. redis.Set(keyThree, "", time.Second)
  8769. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8770. redis.Set(keyFour, "", time.Second)
  8771. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8772. redis.Set(keyFive, "", time.Second)
  8773. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8774. redis.Set(keySix, "", time.Second)
  8775. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8776. redis.Set(keySeven, "", time.Second)
  8777. if err != nil {
  8778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8779. return
  8780. }
  8781. this.ServeSuccessJSON(map[string]interface{}{
  8782. "order": order,
  8783. })
  8784. }
  8785. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8786. ids := this.GetString("ids")
  8787. idSplit := strings.Split(ids, ",")
  8788. orgId := this.GetMobileAdminUserInfo().Org.Id
  8789. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8790. execution_time := this.GetString("exce_time")
  8791. timeLayout2 := "2006-01-02 15:04:05"
  8792. loc, _ := time.LoadLocation("Local")
  8793. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8794. if errs != nil {
  8795. utils.ErrorLog(errs.Error())
  8796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8797. return
  8798. }
  8799. //his客户
  8800. if config.IsOpen == 1 {
  8801. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8802. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8803. for _, item := range list {
  8804. for _, it := range adviceList {
  8805. if item.DrugId == it.DrugId {
  8806. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8807. }
  8808. }
  8809. }
  8810. for _, item := range list {
  8811. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8812. var sum_out_count int64
  8813. for _, itemThree := range item.ChildDoctorAdvice {
  8814. var prescribing_number int64
  8815. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8816. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8817. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8818. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8819. }
  8820. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8821. prescribing_number = parseIntPrescribingNumber
  8822. }
  8823. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8824. prescribing_number = parseIntPrescribingNumber
  8825. }
  8826. sum_out_count += prescribing_number
  8827. }
  8828. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8829. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8830. //库存不足
  8831. if sum_out_count > drugStockOut.FlushCount {
  8832. this.ServeSuccessJSON(map[string]interface{}{
  8833. "msg": "2",
  8834. "drug": medical,
  8835. "ids": ids,
  8836. })
  8837. return
  8838. }
  8839. }
  8840. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8841. //执行医嘱
  8842. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8843. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8844. for _, item := range advices {
  8845. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8846. redis := service.RedisClient()
  8847. //清空key 值
  8848. redis.Set(key, "", time.Second)
  8849. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8850. redis.Set(keyTwo, "", time.Second)
  8851. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8852. redis.Set(keyThree, "", time.Second)
  8853. recordDate := theTime.Format("2006-01-02")
  8854. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8855. redis.Set(keyFour, "", time.Second)
  8856. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8857. redis.Set(keyFive, "", time.Second)
  8858. defer redis.Close()
  8859. }
  8860. if errs == nil {
  8861. //药品管理信息
  8862. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8863. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8864. if drugStockConfig.IsOpen == 1 {
  8865. for _, item := range advices {
  8866. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8867. config, _ := service.GetDrugOpenConfigOne(orgId)
  8868. if config.IsOpen != 1 {
  8869. //查询该药品是否有库存
  8870. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8871. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8872. if medical.IsUse == 2 {
  8873. if config.IsOpen != 1 {
  8874. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8875. service.HisDrugsDelivery(orgId, creater, &advice)
  8876. if orgId == 3877 || orgId == 10265 {
  8877. //查询该药品是否有出库记录
  8878. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8879. if len(flowMap) == 0 {
  8880. errs := service.UpdateHisAdviceById(advice.ID)
  8881. if errs != nil {
  8882. drugError := models.XtDrugError{
  8883. UserOrgId: orgId,
  8884. DrugId: item.DrugId,
  8885. RecordDate: item.AdviceDate,
  8886. PatientId: item.PatientId,
  8887. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8888. Status: 1,
  8889. Ctime: time.Now().Unix(),
  8890. Mtime: 0,
  8891. SumCount: 0,
  8892. Prescribingnumber: advice.PrescribingNumber,
  8893. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8894. }
  8895. service.CreateDrugError(drugError)
  8896. }
  8897. this.ServeSuccessJSON(map[string]interface{}{
  8898. "msg": "2",
  8899. "drug": medical,
  8900. "ids": ids,
  8901. })
  8902. return
  8903. }
  8904. }
  8905. }
  8906. if pharmacyConfig.IsOpen != 1 {
  8907. service.HisDrugsDelivery(orgId, creater, &advice)
  8908. if orgId == 3877 || orgId == 10265 {
  8909. //查询该药品是否有出库记录
  8910. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8911. if len(flowMap) == 0 {
  8912. errs := service.UpdateHisAdviceById(advice.ID)
  8913. if errs != nil {
  8914. drugError := models.XtDrugError{
  8915. UserOrgId: orgId,
  8916. DrugId: item.DrugId,
  8917. RecordDate: item.AdviceDate,
  8918. PatientId: item.PatientId,
  8919. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8920. Status: 1,
  8921. Ctime: time.Now().Unix(),
  8922. Mtime: 0,
  8923. SumCount: 0,
  8924. Prescribingnumber: advice.PrescribingNumber,
  8925. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8926. }
  8927. service.CreateDrugError(drugError)
  8928. }
  8929. this.ServeSuccessJSON(map[string]interface{}{
  8930. "msg": "2",
  8931. "drug": medical,
  8932. "ids": ids,
  8933. })
  8934. return
  8935. }
  8936. }
  8937. }
  8938. //更新字典里面的库存
  8939. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8940. var sum_count int64
  8941. for _, its := range stockInfo {
  8942. if its.MaxUnit == medical.MaxUnit {
  8943. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8944. }
  8945. sum_count += its.StockMaxNumber + its.StockMinNumber
  8946. }
  8947. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8948. //剩余库存
  8949. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8950. }
  8951. }
  8952. }
  8953. }
  8954. }
  8955. this.ServeSuccessJSON(map[string]interface{}{
  8956. "msg": "1",
  8957. "ids": ids,
  8958. })
  8959. return
  8960. } else {
  8961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8962. }
  8963. }
  8964. //血透客户
  8965. if config.IsOpen == 2 || config.IsOpen == 0 {
  8966. //药品管理信息
  8967. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8968. if drugStockConfig.IsOpen == 1 {
  8969. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8970. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8971. for _, item := range list {
  8972. for _, it := range adviceList {
  8973. if item.DrugId == it.DrugId {
  8974. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8975. }
  8976. }
  8977. }
  8978. for _, item := range list {
  8979. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8980. var sum_out_count int64
  8981. for _, itemThree := range item.ChildDoctorAdvice {
  8982. var prescribing_number int64
  8983. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8984. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8985. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8986. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8987. }
  8988. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8989. prescribing_number = parseIntPrescribingNumber
  8990. }
  8991. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8992. prescribing_number = parseIntPrescribingNumber
  8993. }
  8994. sum_out_count += prescribing_number
  8995. }
  8996. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8997. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8998. //库存不足
  8999. if sum_out_count > drugStockOut.FlushCount {
  9000. this.ServeSuccessJSON(map[string]interface{}{
  9001. "msg": "2",
  9002. "drug": medical,
  9003. "ids": ids,
  9004. })
  9005. return
  9006. }
  9007. }
  9008. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9009. //执行医嘱
  9010. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9011. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9012. for _, item := range advices {
  9013. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9014. redis := service.RedisClient()
  9015. //清空key 值
  9016. redis.Set(key, "", time.Second)
  9017. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9018. redis.Set(keyTwo, "", time.Second)
  9019. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9020. redis.Set(keyThree, "", time.Second)
  9021. recordDate := theTime.Format("2006-01-02")
  9022. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9023. redis.Set(keyFour, "", time.Second)
  9024. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9025. redis.Set(keyFive, "", time.Second)
  9026. defer redis.Close()
  9027. }
  9028. if errs == nil {
  9029. for _, item := range advices {
  9030. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9031. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9032. //查询是否出库按钮开启
  9033. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9034. if adviceSetting.IsAdviceOpen == 1 {
  9035. //查询是否出库按钮开启
  9036. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9037. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9038. if prescriptionConfig.IsOpen == 1 {
  9039. if medical.IsUse == 2 {
  9040. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9041. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9042. }
  9043. if pharmacyConfig.IsOpen != 1 {
  9044. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9045. }
  9046. //更新字典里面的库存
  9047. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9048. var sum_count int64
  9049. for _, its := range stockInfo {
  9050. if its.MaxUnit == medical.MaxUnit {
  9051. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9052. }
  9053. sum_count += its.StockMaxNumber + its.StockMinNumber
  9054. }
  9055. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9056. //剩余库存
  9057. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9058. }
  9059. }
  9060. } else {
  9061. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9062. if medical.IsUse == 2 {
  9063. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9064. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9065. }
  9066. if pharmacyConfig.IsOpen != 1 {
  9067. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9068. }
  9069. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9070. var sum_count int64
  9071. for _, its := range stockInfo {
  9072. if its.MaxUnit == medical.MaxUnit {
  9073. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9074. }
  9075. sum_count += its.StockMaxNumber + its.StockMinNumber
  9076. }
  9077. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9078. //剩余库存
  9079. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9080. }
  9081. }
  9082. }
  9083. }
  9084. this.ServeSuccessJSON(map[string]interface{}{
  9085. "msg": "1",
  9086. "ids": ids,
  9087. })
  9088. return
  9089. } else {
  9090. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9091. //执行医嘱
  9092. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9093. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9094. for _, item := range advices {
  9095. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9096. redis := service.RedisClient()
  9097. //清空key 值
  9098. redis.Set(key, "", time.Second)
  9099. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9100. redis.Set(keyTwo, "", time.Second)
  9101. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9102. redis.Set(keyThree, "", time.Second)
  9103. recordDate := theTime.Format("2006-01-02")
  9104. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9105. redis.Set(keyFour, "", time.Second)
  9106. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9107. redis.Set(keyFive, "", time.Second)
  9108. defer redis.Close()
  9109. }
  9110. this.ServeSuccessJSON(map[string]interface{}{
  9111. "msg": "1",
  9112. "ids": ids,
  9113. })
  9114. return
  9115. }
  9116. }
  9117. }
  9118. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9119. ids := this.GetString("ids")
  9120. idSplit := strings.Split(ids, ",")
  9121. orgId := this.GetMobileAdminUserInfo().Org.Id
  9122. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9123. if config.IsOpen == 1 {
  9124. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9125. this.ServeSuccessJSON(map[string]interface{}{
  9126. "msg": "1",
  9127. "ids": ids,
  9128. })
  9129. return
  9130. }
  9131. if config.IsOpen == 0 || config.IsOpen == 2 {
  9132. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9133. this.ServeSuccessJSON(map[string]interface{}{
  9134. "msg": "1",
  9135. "ids": ids,
  9136. })
  9137. return
  9138. }
  9139. }
  9140. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9141. ids := this.GetString("ids")
  9142. idSplit := strings.Split(ids, ",")
  9143. orgId := this.GetMobileAdminUserInfo().Org.Id
  9144. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9145. //his
  9146. if config.IsOpen == 1 {
  9147. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9148. theTime := time.Now()
  9149. advices := models.HisDoctorAdviceThirty{
  9150. CheckTime: theTime.Unix(),
  9151. Checker: checker,
  9152. UpdatedTime: time.Now().Unix(),
  9153. }
  9154. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9155. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9156. for _, item := range list {
  9157. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9158. redis := service.RedisClient()
  9159. //清空key 值
  9160. redis.Set(key, "", time.Second)
  9161. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9162. redis.Set(keyTwo, "", time.Second)
  9163. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9164. redis.Set(keyThree, "", time.Second)
  9165. recordDate := theTime.Format("2006-01-02")
  9166. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9167. redis.Set(keyFour, "", time.Second)
  9168. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9169. redis.Set(keyFive, "", time.Second)
  9170. defer redis.Close()
  9171. }
  9172. this.ServeSuccessJSON(map[string]interface{}{
  9173. "msg": "1",
  9174. "ids": ids,
  9175. })
  9176. return
  9177. }
  9178. //血透
  9179. if config.IsOpen == 0 || config.IsOpen == 2 {
  9180. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9181. theTime := time.Now()
  9182. advices := models.DoctorAdvice{
  9183. CheckTime: theTime.Unix(),
  9184. Checker: checker,
  9185. UpdatedTime: time.Now().Unix(),
  9186. }
  9187. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9188. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9189. for _, item := range list {
  9190. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9191. redis := service.RedisClient()
  9192. //清空key 值
  9193. redis.Set(key, "", time.Second)
  9194. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9195. redis.Set(keyTwo, "", time.Second)
  9196. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9197. redis.Set(keyThree, "", time.Second)
  9198. recordDate := theTime.Format("2006-01-02")
  9199. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9200. redis.Set(keyFour, "", time.Second)
  9201. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9202. redis.Set(keyFive, "", time.Second)
  9203. defer redis.Close()
  9204. }
  9205. this.ServeSuccessJSON(map[string]interface{}{
  9206. "msg": "1",
  9207. "ids": ids,
  9208. })
  9209. return
  9210. }
  9211. }
  9212. func (this *DialysisAPIController) CheckSchedule() {
  9213. patientID, _ := this.GetInt64("patient_id")
  9214. recordDateStr := this.GetString("record_date")
  9215. nurseID, _ := this.GetInt64("start_nurse")
  9216. schedual_type, _ := this.GetInt64("schedual_type")
  9217. bedID, _ := this.GetInt64("bed")
  9218. start_time := this.GetString("start_time")
  9219. fmt.Println("patientID", patientID)
  9220. fmt.Println("recordDateStr", recordDateStr)
  9221. fmt.Println("nurseID", nurseID)
  9222. fmt.Println("schedual_type------", schedual_type)
  9223. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9225. return
  9226. }
  9227. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9228. if parseStartDateErr != nil {
  9229. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9231. return
  9232. }
  9233. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9234. if parseErr != nil {
  9235. this.ErrorLog("时间解析失败:%v", parseErr)
  9236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9237. return
  9238. }
  9239. adminUserInfo := this.GetMobileAdminUserInfo()
  9240. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9241. if getPatientErr != nil {
  9242. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9244. return
  9245. } else if patient == nil {
  9246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9247. return
  9248. }
  9249. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9250. if getNurseErr != nil {
  9251. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9253. return
  9254. } else if nurse == nil {
  9255. this.ErrorLog("护士不存在")
  9256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9257. return
  9258. }
  9259. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9260. if getDeviceNumberErr != nil {
  9261. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9263. return
  9264. } else if deviceNumber == nil {
  9265. this.ErrorLog("床位号不存在")
  9266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9267. return
  9268. }
  9269. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9270. if getRecordErr != nil {
  9271. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9273. return
  9274. } else if dialysisRecord != nil {
  9275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9276. return
  9277. }
  9278. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9279. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9280. timeLayout := "2006-01-02 15:04:05"
  9281. loc, _ := time.LoadLocation("Local")
  9282. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9283. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9284. schedulestartTime := theStartTime.Unix()
  9285. scheduleendTime := theEndTime.Unix()
  9286. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9287. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9288. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9289. //查询该床位是否有人用了
  9290. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9291. if err == nil {
  9292. if schedule.ID == 0 {
  9293. this.ServeSuccessJSON(map[string]interface{}{
  9294. "status": 0,
  9295. "msg": "请求失败",
  9296. })
  9297. } else {
  9298. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9299. if order.ID > 0 { //该机位被其他人占用了
  9300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9301. return
  9302. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9303. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9304. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9305. this.ServeSuccessJSON(map[string]interface{}{
  9306. "status": 1,
  9307. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9308. })
  9309. return
  9310. } else {
  9311. this.ServeSuccessJSON(map[string]interface{}{
  9312. "status": 0,
  9313. "msg": "",
  9314. })
  9315. }
  9316. }
  9317. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9318. this.ServeSuccessJSON(map[string]interface{}{
  9319. "status": 2,
  9320. "msg": "当前机位已有患者在使用,请重新选择!",
  9321. })
  9322. }
  9323. }
  9324. } else {
  9325. this.ServeSuccessJSON(map[string]interface{}{
  9326. "status": 0,
  9327. "msg": "",
  9328. })
  9329. }
  9330. }
  9331. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9332. orgId := this.GetMobileAdminUserInfo().Org.Id
  9333. schedule_type, _ := this.GetInt64("schedule_type")
  9334. partion_type, _ := this.GetInt64("partion_type")
  9335. start_time := this.GetString("start_time")
  9336. timeLayout := "2006-01-02"
  9337. loc, _ := time.LoadLocation("Local")
  9338. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9339. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9340. _, config := service.FindXTHisRecordByOrgId(orgId)
  9341. appId := this.GetMobileAdminUserInfo().App.Id
  9342. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9343. if err == nil {
  9344. this.ServeSuccessJSON(map[string]interface{}{
  9345. "list": list,
  9346. "config": config,
  9347. "doctorList": doctorList,
  9348. })
  9349. return
  9350. } else {
  9351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9352. return
  9353. }
  9354. }
  9355. func (this *DialysisAPIController) SaveMobileInformation() {
  9356. patient_id, _ := this.GetInt64("patient_id")
  9357. record_date, _ := this.GetInt64("record_date")
  9358. startTime := this.GetString("start_time")
  9359. module, _ := this.GetInt64("module")
  9360. remark := this.GetString("remark")
  9361. timeLayout := "2006-01-02 15:04"
  9362. loc, _ := time.LoadLocation("Local")
  9363. if len(startTime) == 0 {
  9364. utils.ErrorLog("len(start_time) == 0")
  9365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9366. return
  9367. }
  9368. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9369. if err != nil {
  9370. utils.ErrorLog(err.Error())
  9371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9372. return
  9373. }
  9374. StartTime := theTime.Unix()
  9375. fmt.Println("startime-------------", StartTime)
  9376. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9377. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9378. information := models.XtDialysisInformation{
  9379. Module: module,
  9380. PatientId: patient_id,
  9381. RecordDate: record_date,
  9382. ApplicationDate: StartTime,
  9383. Creater: creater,
  9384. ApplicationStatus: 2,
  9385. Checker: 0,
  9386. CheckTime: 0,
  9387. Remark: remark,
  9388. UserOrgId: user_org_id,
  9389. Ctime: time.Now().Unix(),
  9390. Status: 1,
  9391. Mtime: 0,
  9392. }
  9393. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9394. if infor.ID == 0 {
  9395. service.SaveDialysisInformation(information)
  9396. }
  9397. if infor.ID > 0 {
  9398. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9399. }
  9400. this.ServeSuccessJSON(map[string]interface{}{
  9401. "information": information,
  9402. })
  9403. return
  9404. }
  9405. func (this *DialysisAPIController) GetMobileInformation() {
  9406. limit, _ := this.GetInt64("limit")
  9407. page, _ := this.GetInt64("page")
  9408. orgid := this.GetMobileAdminUserInfo().Org.Id
  9409. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9410. appid := this.GetMobileAdminUserInfo().App.Id
  9411. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9412. patients, _ := service.GetAllpatientThirty(orgid)
  9413. this.ServeSuccessJSON(map[string]interface{}{
  9414. "information": information,
  9415. "total": total,
  9416. "doclist": doclist,
  9417. "patients": patients,
  9418. })
  9419. return
  9420. }
  9421. func (this *DialysisAPIController) GetMobileInformationOne() {
  9422. limit, _ := this.GetInt64("limit")
  9423. page, _ := this.GetInt64("page")
  9424. orgid := this.GetMobileAdminUserInfo().Org.Id
  9425. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9426. appid := this.GetMobileAdminUserInfo().App.Id
  9427. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9428. patients, _ := service.GetAllpatientThirty(orgid)
  9429. this.ServeSuccessJSON(map[string]interface{}{
  9430. "information": information,
  9431. "total": total,
  9432. "doclist": doclist,
  9433. "patients": patients,
  9434. })
  9435. return
  9436. }
  9437. func (this *DialysisAPIController) CheckMobileInformation() {
  9438. id, _ := this.GetInt64("id")
  9439. application_status, _ := this.GetInt64("application_status")
  9440. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9441. checktime := time.Now().Unix()
  9442. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9443. if err == nil {
  9444. this.ServeSuccessJSON(map[string]interface{}{
  9445. "msg": "ok",
  9446. })
  9447. return
  9448. }
  9449. }
  9450. func (c *DialysisAPIController) GetControlMonitorList() {
  9451. partition, _ := c.GetInt64("partition")
  9452. monitorDate := c.GetString("date")
  9453. patient_id, _ := c.GetInt64("patient_id")
  9454. pat_type, _ := c.GetInt64("pat_type")
  9455. timeLayout := "2006-01-02"
  9456. loc, _ := time.LoadLocation("Local")
  9457. var theStartTime int64
  9458. if len(monitorDate) > 0 {
  9459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9460. if err != nil {
  9461. theStartTime = 0
  9462. }
  9463. theStartTime = theTime.Unix()
  9464. }
  9465. adminInfo := c.GetMobileAdminUserInfo()
  9466. orgID := adminInfo.Org.Id
  9467. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9468. if err != nil {
  9469. c.ErrorLog("获取排班信息失败:%v", err)
  9470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9471. } else {
  9472. if len(monitor) > 0 {
  9473. //获取所有床位
  9474. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9475. //获取所有分区
  9476. zoneList, _ := service.GetAllZoneByList(orgID)
  9477. //获取透析处方
  9478. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9479. //获取透前评估
  9480. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9481. //获取上机
  9482. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9483. //获取透后
  9484. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9485. //获取透后监测
  9486. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9487. //获取所有的患者
  9488. patients, _ := service.GetAllPatientListByListOne(orgID)
  9489. //获取所有透析模式
  9490. treatments, _ := service.GetAllTreatModeByList(orgID)
  9491. //获取所有医嘱
  9492. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9493. //获取双人核对
  9494. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9495. //治疗小结
  9496. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9497. //待消毒
  9498. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9499. for key, item := range monitor {
  9500. // 获取床位信息
  9501. for _, it := range numberList {
  9502. if item.BedId == it.ID {
  9503. monitor[key].DeviceNumber = it
  9504. break
  9505. }
  9506. }
  9507. //获取分区信息
  9508. for _, it := range zoneList {
  9509. if item.PartitionId == it.ID {
  9510. monitor[key].DeviceZone = it
  9511. }
  9512. }
  9513. for _, prescription := range prescriptions {
  9514. if item.PatientId == prescription.PatientId {
  9515. monitor[key].Prescription = prescription
  9516. break
  9517. }
  9518. }
  9519. for _, it := range checkList {
  9520. if item.PatientId == it.PatientId {
  9521. monitor[key].DoubleCheck = it
  9522. break
  9523. }
  9524. }
  9525. for _, it := range summaryList {
  9526. if item.PatientId == it.PatientId {
  9527. monitor[key].TreatmentSummaryForList = it
  9528. break
  9529. }
  9530. }
  9531. // 透前评估
  9532. for _, assessmentBefore := range assessmentBefores {
  9533. if item.PatientId == assessmentBefore.PatientId {
  9534. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9535. break
  9536. }
  9537. }
  9538. // 透析上下机
  9539. for _, dialysisOrder := range dialysisOrders {
  9540. if item.PatientId == dialysisOrder.PatientId {
  9541. monitor[key].DialysisOrder = dialysisOrder
  9542. break
  9543. }
  9544. }
  9545. // 治疗小节
  9546. for _, afterDislysis := range AssessmentAfterDislysis {
  9547. if item.PatientId == afterDislysis.PatientId {
  9548. monitor[key].AssessmentAfterDislysis = afterDislysis
  9549. break
  9550. }
  9551. }
  9552. for _, it := range monitorlist {
  9553. if item.PatientId == it.PatientId {
  9554. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9555. }
  9556. }
  9557. for _, it := range adviceList {
  9558. if item.PatientId == it.PatientId {
  9559. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9560. }
  9561. }
  9562. for _, patient := range patients {
  9563. if item.PatientId == patient.ID {
  9564. monitor[key].MonitorPatients = patient
  9565. break
  9566. }
  9567. }
  9568. for _, treatment := range treatments {
  9569. if item.ModeId == treatment.ID {
  9570. monitor[key].TreatmentMode = treatment
  9571. break
  9572. }
  9573. }
  9574. for _, infor := range informationList {
  9575. if item.PatientId == infor.PatientId {
  9576. monitor[key].NewDeviceInformation = infor
  9577. break
  9578. }
  9579. }
  9580. }
  9581. }
  9582. }
  9583. patients, err := service.GetAllpatientFourty(orgID)
  9584. var mds []*models.NewMonitorDialysisScheduleList
  9585. if pat_type == 0 {
  9586. for _, item := range monitor {
  9587. mds = append(mds, item)
  9588. }
  9589. }
  9590. //待医嘱核对
  9591. if pat_type == 1 {
  9592. for _, item := range monitor {
  9593. if len(item.AdviceList) > 0 {
  9594. mds = append(mds, item)
  9595. }
  9596. }
  9597. }
  9598. //待开小结
  9599. if pat_type == 2 {
  9600. for _, item := range monitor {
  9601. if item.TreatmentSummaryForList == nil {
  9602. mds = append(mds, item)
  9603. }
  9604. }
  9605. }
  9606. //待下机
  9607. if pat_type == 3 {
  9608. for _, item := range monitor {
  9609. if item.DialysisOrder != nil {
  9610. if item.DialysisOrder.ID > 0 {
  9611. mds = append(mds, item)
  9612. }
  9613. }
  9614. }
  9615. }
  9616. //待消毒
  9617. if pat_type == 4 {
  9618. for _, item := range monitor {
  9619. if item.NewDeviceInformation == nil {
  9620. mds = append(mds, item)
  9621. }
  9622. }
  9623. }
  9624. //待双人核对
  9625. if pat_type == 5 {
  9626. for _, item := range monitor {
  9627. if item.DoubleCheck == nil {
  9628. mds = append(mds, item)
  9629. }
  9630. }
  9631. }
  9632. //医嘱未执行
  9633. if pat_type == 6 {
  9634. for _, item := range monitor {
  9635. if len(item.AdviceList) > 0 {
  9636. mds = append(mds, item)
  9637. }
  9638. }
  9639. }
  9640. //患者未签名
  9641. if pat_type == 7 {
  9642. for _, item := range monitor {
  9643. if item.DialysisOrder != nil {
  9644. if item.DialysisOrder.ID > 0 {
  9645. mds = append(mds, item)
  9646. }
  9647. }
  9648. }
  9649. }
  9650. //目标超滤于实际超滤不同
  9651. if pat_type == 8 {
  9652. for _, item := range monitor {
  9653. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9654. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9655. mds = append(mds, item)
  9656. }
  9657. }
  9658. }
  9659. }
  9660. //血压少于5次
  9661. if pat_type == 9 {
  9662. for _, item := range monitor {
  9663. if len(item.MonitoringRecord) < 5 {
  9664. mds = append(mds, item)
  9665. }
  9666. }
  9667. }
  9668. if pat_type == 10 {
  9669. for _, item := range monitor {
  9670. if len(item.MonitoringRecord) == 0 {
  9671. mds = append(mds, item)
  9672. }
  9673. }
  9674. }
  9675. if pat_type == 11 {
  9676. for _, item := range monitor {
  9677. if len(item.MonitoringRecord) > 0 {
  9678. mds = append(mds, item)
  9679. }
  9680. }
  9681. }
  9682. if pat_type == 12 {
  9683. for _, item := range monitor {
  9684. if len(item.MonitoringRecord) > 0 {
  9685. mds = append(mds, item)
  9686. }
  9687. }
  9688. }
  9689. if err == nil {
  9690. c.ServeSuccessJSON(map[string]interface{}{
  9691. "monitor": mds,
  9692. "patients": patients,
  9693. })
  9694. } else {
  9695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9696. }
  9697. }
  9698. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9699. admin_user_id, _ := c.GetInt64("admin_user_id")
  9700. timeStr := time.Now().Format("2006-01-02")
  9701. timeLayout := "2006-01-02 15:04:05"
  9702. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9703. timenow := timeStringToTime.Unix()
  9704. orgId := c.GetMobileAdminUserInfo().Org.Id
  9705. //查询当前护士的患者
  9706. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9707. var patientIds []int64
  9708. for _, item := range orderList {
  9709. patientIds = append(patientIds, item.PatientId)
  9710. }
  9711. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9712. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9713. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9714. //药品管理信息
  9715. _, drugStockConfig := service.FindHisConfig(orgId)
  9716. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9717. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9718. c.ServeSuccessJSON(map[string]interface{}{
  9719. "adviceList": adviceList,
  9720. "hisAdviceList": hisAdviceList,
  9721. "projectList": projectList,
  9722. "drugStockConfig": drugStockConfig,
  9723. "patientList": patientList,
  9724. "projectConfig": projectConfig,
  9725. })
  9726. }
  9727. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9728. patient_id, _ := c.GetInt64("patient_id")
  9729. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9730. c.ServeSuccessJSON(map[string]interface{}{
  9731. "recrods": recrods,
  9732. })
  9733. }
  9734. func (c *DialysisAPIController) ExMobileChangeSch() {
  9735. id_one, _ := c.GetInt64("id_one")
  9736. id_two, _ := c.GetInt64("id_two")
  9737. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9738. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9739. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9740. //if order2.ID > 0 {
  9741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9742. // return
  9743. //}
  9744. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9745. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9746. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9747. if count > 0 {
  9748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9749. return
  9750. }
  9751. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9752. if count1 > 0 {
  9753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9754. return
  9755. }
  9756. }
  9757. err := service.UpdateScheduleThree(sch, sch_two)
  9758. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9759. if order.ID > 0 {
  9760. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9761. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9762. redis := service.RedisClient()
  9763. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9764. redis.Set(key, "", time.Second)
  9765. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9766. //清空key 值
  9767. redis.Set(keyOne, "", time.Second)
  9768. }
  9769. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9770. if orderOne.ID > 0 {
  9771. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9772. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9773. redis := service.RedisClient()
  9774. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9775. redis.Set(key, "", time.Second)
  9776. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9777. //清空key 值
  9778. redis.Set(keyOne, "", time.Second)
  9779. }
  9780. if err == nil {
  9781. //去除当天患者排班中重复数据,保留最后一条数据
  9782. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9783. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9784. c.ServeSuccessJSON(map[string]interface{}{
  9785. "msg": "交换成功",
  9786. })
  9787. } else {
  9788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9789. return
  9790. }
  9791. }
  9792. func (c *DialysisAPIController) MobileCoverSch() {
  9793. id_one, _ := c.GetInt64("id_one")
  9794. id_two, _ := c.GetInt64("id_two")
  9795. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9796. //针对凤凰医院
  9797. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9798. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9799. if len(advice) > 0 {
  9800. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9801. }
  9802. }
  9803. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9804. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9805. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9806. if len(hisAdvice) > 0 {
  9807. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9808. }
  9809. if len(project) > 0 {
  9810. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9811. }
  9812. }
  9813. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9814. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9815. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9816. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9817. if count > 0 {
  9818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9819. return
  9820. }
  9821. }
  9822. var new_sch models.Schedule
  9823. new_sch = sch
  9824. new_sch.BedId = sch_two.BedId
  9825. new_sch.ScheduleDate = sch_two.ScheduleDate
  9826. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9827. new_sch.PartitionId = sch_two.PartitionId
  9828. new_sch.ScheduleType = sch_two.ScheduleType
  9829. new_sch.ID = 0
  9830. //删除原来的排班
  9831. err := service.SaveSchTwo(sch, sch_two)
  9832. //生成新的排班
  9833. if err == nil {
  9834. err2 := service.SaveSch(&new_sch)
  9835. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9836. if order.ID > 0 {
  9837. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9838. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9839. redis := service.RedisClient()
  9840. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9841. redis.Set(key, "", time.Second)
  9842. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9843. //清空key 值
  9844. redis.Set(keyOne, "", time.Second)
  9845. }
  9846. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9847. if orderOne.ID > 0 {
  9848. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9849. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9850. redis := service.RedisClient()
  9851. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9852. redis.Set(key, "", time.Second)
  9853. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9854. //清空key 值
  9855. redis.Set(keyOne, "", time.Second)
  9856. }
  9857. if err2 == nil {
  9858. //去除当天患者排班中重复数据,保留最后一条数据
  9859. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9860. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9861. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9862. c.ServeSuccessJSON(map[string]interface{}{
  9863. "msg": "覆盖成功",
  9864. "new_sch": new_sch,
  9865. })
  9866. } else {
  9867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9868. return
  9869. }
  9870. } else {
  9871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9872. return
  9873. }
  9874. }
  9875. func (c *DialysisAPIController) BatchCheckAdvice() {
  9876. patient_id, _ := c.GetInt64("patient_id")
  9877. advice_date, _ := c.GetInt64("advice_date")
  9878. org_id := c.GetMobileAdminUserInfo().Org.Id
  9879. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9880. //查询是his系统还是血透系统
  9881. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9882. //his客户
  9883. if configs.IsOpen == 1 {
  9884. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9885. for _, item := range adviceList {
  9886. service.BatchCheckHisAdvice(item.ID, creater)
  9887. }
  9888. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9889. for _, item := range projectList {
  9890. service.BatchCheckProject(item.ID, creater)
  9891. }
  9892. c.ServeSuccessJSON(map[string]interface{}{
  9893. "adviceList": adviceList,
  9894. "projectList": projectList,
  9895. })
  9896. }
  9897. if configs.IsOpen != 1 {
  9898. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9899. for _, item := range adviceList {
  9900. service.BatchAdviceList(item.ID, creater)
  9901. }
  9902. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9903. for _, item := range projectList {
  9904. service.BatchCheckProject(item.ID, creater)
  9905. }
  9906. c.ServeSuccessJSON(map[string]interface{}{
  9907. "adviceList": adviceList,
  9908. "projectList": projectList,
  9909. })
  9910. }
  9911. return
  9912. }
  9913. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9914. org_id := c.GetMobileAdminUserInfo().Org.Id
  9915. drugList, _ := service.GetAllDrugList(org_id)
  9916. c.ServeSuccessJSON(map[string]interface{}{
  9917. "drugList": drugList,
  9918. })
  9919. }
  9920. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9921. org_id := c.GetMobileAdminUserInfo().Org.Id
  9922. dataBody := make(map[string]interface{}, 0)
  9923. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9924. if err != nil {
  9925. utils.ErrorLog(err.Error())
  9926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9927. return
  9928. }
  9929. timeLayout := "2006-01-02"
  9930. loc, _ := time.LoadLocation("Local")
  9931. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9932. utils.ErrorLog("advice_type")
  9933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9934. return
  9935. }
  9936. adviceType := int64(dataBody["advice_type"].(float64))
  9937. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9938. utils.ErrorLog("start_time")
  9939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9940. return
  9941. }
  9942. startTime2, _ := dataBody["start_time"].(string)
  9943. time_arr := strings.Split(startTime2, " ")
  9944. if len(time_arr) > 0 {
  9945. startTime2 = time_arr[0]
  9946. }
  9947. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9948. utils.ErrorLog("advice_date")
  9949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9950. return
  9951. }
  9952. advice_date, _ := dataBody["advice_date"].(string)
  9953. var advicedateunix int64
  9954. if len(advice_date) > 0 {
  9955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9956. if err != nil {
  9957. fmt.Println(err)
  9958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9959. return
  9960. }
  9961. advicedateunix = theTime.Unix()
  9962. }
  9963. adviceDate := startTime2
  9964. if len(adviceDate) == 0 {
  9965. utils.ErrorLog("len(adviceDate) == 0")
  9966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9967. return
  9968. }
  9969. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9970. if err != nil {
  9971. utils.ErrorLog(err.Error())
  9972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9973. return
  9974. }
  9975. AdviceDate := advicedateunix
  9976. RecordDate := advicedateunix
  9977. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9978. utils.ErrorLog("start_time")
  9979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9980. return
  9981. }
  9982. startTime, _ := dataBody["start_time"].(string)
  9983. if len(startTime) == 0 {
  9984. utils.ErrorLog("len(start_time) == 0")
  9985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9986. return
  9987. }
  9988. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9989. if err != nil {
  9990. utils.ErrorLog(err.Error())
  9991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9992. return
  9993. }
  9994. StartTime := theTime.Unix()
  9995. advice_name, _ := dataBody["advice_name"].(string)
  9996. advice_desc, _ := dataBody["advice_desc"].(string)
  9997. delivery_way, _ := dataBody["delivery_way"].(string)
  9998. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9999. frequency_type := int64(dataBody["frequency_type"].(float64))
  10000. frequency_week, _ := dataBody["frequency_week"].(string)
  10001. prescribing_number := dataBody["prescribing_number"].(float64)
  10002. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10003. remark := dataBody["remark"].(string)
  10004. single_dose := dataBody["single_dose"].(float64)
  10005. single_dose_unit := dataBody["single_dose_unit"].(string)
  10006. patient_id := int64(dataBody["patient_id"].(float64))
  10007. day_count := int64(dataBody["day_count"].(float64))
  10008. groupNo := int64(dataBody["group_no"].(float64))
  10009. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10010. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10011. if groupNo <= 0 {
  10012. group := service.GetMaxAdviceGroupID(org_id)
  10013. groupNo = group + 1
  10014. }
  10015. var template_id = ""
  10016. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10017. template_id = "M" + adviceLastId
  10018. advice := models.DoctorAdvice{
  10019. UserOrgId: org_id,
  10020. PatientId: patient_id,
  10021. AdviceType: adviceType,
  10022. AdviceDate: AdviceDate,
  10023. StartTime: StartTime,
  10024. AdviceName: advice_name,
  10025. AdviceDesc: advice_desc,
  10026. ReminderDate: 0,
  10027. SingleDose: single_dose,
  10028. SingleDoseUnit: single_dose_unit,
  10029. DrugSpec: 0,
  10030. DrugSpecUnit: "",
  10031. PrescribingNumber: prescribing_number,
  10032. PrescribingNumberUnit: prescribing_number_unit,
  10033. DeliveryWay: delivery_way,
  10034. ExecutionFrequency: execution_frequency,
  10035. AdviceDoctor: advice_doctor,
  10036. Status: 1,
  10037. CreatedTime: time.Now().Unix(),
  10038. UpdatedTime: 0,
  10039. AdviceAffirm: "",
  10040. Remark: remark,
  10041. StopTime: 0,
  10042. StopReason: "",
  10043. StopDoctor: 0,
  10044. StopState: 0,
  10045. ParentId: 0,
  10046. ExecutionTime: 0,
  10047. ExecutionStaff: 0,
  10048. ExecutionState: 0,
  10049. Checker: 0,
  10050. RecordDate: RecordDate,
  10051. DialysisOrderId: 0,
  10052. CheckTime: 0,
  10053. CheckState: 0,
  10054. AdviceId: 0,
  10055. RemindType: 0,
  10056. FrequencyType: frequency_type,
  10057. DayCount: day_count,
  10058. WeekDay: frequency_week,
  10059. ChildDoctorAdvice: nil,
  10060. TemplateId: template_id,
  10061. Modifier: 0,
  10062. IsCheck: 0,
  10063. Way: 0,
  10064. DrugId: 0,
  10065. DrugNameId: 0,
  10066. IsMedicine: 0,
  10067. PushStartTime: 0,
  10068. IsSettle: 0,
  10069. IsPrescription: 0,
  10070. GroupNo: groupNo,
  10071. }
  10072. service.CreateMobileAdivce(advice)
  10073. c.ServeSuccessJSON(map[string]interface{}{
  10074. "msg": "保存成功!",
  10075. })
  10076. }
  10077. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10078. patient_id, _ := c.GetInt64("patient_id")
  10079. org_id := c.GetMobileAdminUserInfo().Org.Id
  10080. app_id := c.GetMobileAdminUserInfo().App.Id
  10081. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10082. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10083. c.ServeSuccessJSON(map[string]interface{}{
  10084. "adviceList": adviceList,
  10085. "adminRoles": adminRoles,
  10086. })
  10087. }
  10088. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10089. org_id := c.GetMobileAdminUserInfo().Org.Id
  10090. dataBody := make(map[string]interface{}, 0)
  10091. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10092. if err != nil {
  10093. utils.ErrorLog(err.Error())
  10094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10095. return
  10096. }
  10097. timeLayout := "2006-01-02"
  10098. loc, _ := time.LoadLocation("Local")
  10099. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10100. utils.ErrorLog("start_time")
  10101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10102. return
  10103. }
  10104. startTime2, _ := dataBody["start_time"].(string)
  10105. time_arr := strings.Split(startTime2, " ")
  10106. if len(time_arr) > 0 {
  10107. startTime2 = time_arr[0]
  10108. }
  10109. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10110. utils.ErrorLog("advice_date")
  10111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10112. return
  10113. }
  10114. advice_date, _ := dataBody["advice_date"].(string)
  10115. var advicedateunix int64
  10116. if len(advice_date) > 0 {
  10117. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10118. if err != nil {
  10119. fmt.Println(err)
  10120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10121. return
  10122. }
  10123. advicedateunix = theTime.Unix()
  10124. }
  10125. adviceDate := startTime2
  10126. if len(adviceDate) == 0 {
  10127. utils.ErrorLog("len(adviceDate) == 0")
  10128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10129. return
  10130. }
  10131. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10132. if err != nil {
  10133. utils.ErrorLog(err.Error())
  10134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10135. return
  10136. }
  10137. AdviceDate := advicedateunix
  10138. RecordDate := advicedateunix
  10139. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10140. utils.ErrorLog("start_time")
  10141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10142. return
  10143. }
  10144. startTime, _ := dataBody["start_time"].(string)
  10145. if len(startTime) == 0 {
  10146. utils.ErrorLog("len(start_time) == 0")
  10147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10148. return
  10149. }
  10150. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10151. if err != nil {
  10152. utils.ErrorLog(err.Error())
  10153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10154. return
  10155. }
  10156. StartTime := theTime.Unix()
  10157. advice_name, _ := dataBody["advice_name"].(string)
  10158. advice_desc, _ := dataBody["advice_desc"].(string)
  10159. delivery_way, _ := dataBody["delivery_way"].(string)
  10160. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10161. prescribing_number := dataBody["prescribing_number"].(float64)
  10162. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10163. remark := dataBody["remark"].(string)
  10164. single_dose := dataBody["single_dose"].(float64)
  10165. single_dose_unit := dataBody["single_dose_unit"].(string)
  10166. patient_id := int64(dataBody["patient_id"].(float64))
  10167. groupNo := int64(dataBody["group_no"].(float64))
  10168. parent_id := int64(dataBody["parent_id"].(float64))
  10169. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10170. advice := models.XtDoctorAdviceOne{
  10171. UserOrgId: org_id,
  10172. PatientId: patient_id,
  10173. AdviceType: 1,
  10174. AdviceDate: AdviceDate,
  10175. StartTime: StartTime,
  10176. AdviceName: advice_name,
  10177. AdviceDesc: advice_desc,
  10178. ReminderDate: 0,
  10179. SingleDose: single_dose,
  10180. SingleDoseUnit: single_dose_unit,
  10181. PrescribingNumber: prescribing_number,
  10182. PrescribingNumberUnit: prescribing_number_unit,
  10183. DeliveryWay: delivery_way,
  10184. ExecutionFrequency: execution_frequency,
  10185. AdviceDoctor: advice_doctor,
  10186. Status: 1,
  10187. CreatedTime: time.Now().Unix(),
  10188. UpdatedTime: time.Now().Unix(),
  10189. AdviceAffirm: "",
  10190. Remark: remark,
  10191. StopTime: 0,
  10192. StopReason: "",
  10193. StopDoctor: 0,
  10194. StopState: 0,
  10195. ParentId: parent_id,
  10196. ExecutionTime: 0,
  10197. ExecutionStaff: 0,
  10198. ExecutionState: 0,
  10199. Checker: 0,
  10200. RecordDate: RecordDate,
  10201. DialysisOrderId: 0,
  10202. CheckTime: 0,
  10203. CheckState: 0,
  10204. DrugSpec: 0,
  10205. DrugSpecUnit: "",
  10206. Groupno: groupNo,
  10207. RemindType: 0,
  10208. FrequencyType: 0,
  10209. DayCount: 0,
  10210. WeekDay: "",
  10211. TemplateId: "",
  10212. Modifier: 0,
  10213. }
  10214. service.CreateMobileAdivceOne(advice)
  10215. c.ServeSuccessJSON(map[string]interface{}{
  10216. "msg": "保存成功!",
  10217. })
  10218. }
  10219. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10220. id, _ := c.GetInt64("id")
  10221. service.DeleteSelfAdviceSubAdvice(id)
  10222. c.ServeSuccessJSON(map[string]interface{}{
  10223. "msg": "保存成功!",
  10224. })
  10225. }
  10226. func (c *DialysisAPIController) GetEditAdviceAction() {
  10227. id, _ := c.GetInt64("id")
  10228. org_id := c.GetMobileAdminUserInfo().Org.Id
  10229. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10230. drugList, _ := service.GetAllDrugList(org_id)
  10231. c.ServeSuccessJSON(map[string]interface{}{
  10232. "advice": advice,
  10233. "drugList": drugList,
  10234. })
  10235. }
  10236. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10237. dataBody := make(map[string]interface{}, 0)
  10238. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10239. if err != nil {
  10240. utils.ErrorLog(err.Error())
  10241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10242. return
  10243. }
  10244. timeLayout := "2006-01-02"
  10245. loc, _ := time.LoadLocation("Local")
  10246. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10247. utils.ErrorLog("start_time")
  10248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10249. return
  10250. }
  10251. startTime2, _ := dataBody["start_time"].(string)
  10252. time_arr := strings.Split(startTime2, " ")
  10253. if len(time_arr) > 0 {
  10254. startTime2 = time_arr[0]
  10255. }
  10256. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10257. utils.ErrorLog("advice_date")
  10258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10259. return
  10260. }
  10261. advice_date, _ := dataBody["advice_date"].(string)
  10262. var advicedateunix int64
  10263. if len(advice_date) > 0 {
  10264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10265. if err != nil {
  10266. fmt.Println(err)
  10267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10268. return
  10269. }
  10270. advicedateunix = theTime.Unix()
  10271. }
  10272. adviceDate := startTime2
  10273. if len(adviceDate) == 0 {
  10274. utils.ErrorLog("len(adviceDate) == 0")
  10275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10276. return
  10277. }
  10278. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10279. if err != nil {
  10280. utils.ErrorLog(err.Error())
  10281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10282. return
  10283. }
  10284. AdviceDate := advicedateunix
  10285. RecordDate := advicedateunix
  10286. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10287. utils.ErrorLog("start_time")
  10288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10289. return
  10290. }
  10291. startTime, _ := dataBody["start_time"].(string)
  10292. if len(startTime) == 0 {
  10293. utils.ErrorLog("len(start_time) == 0")
  10294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10295. return
  10296. }
  10297. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10298. if err != nil {
  10299. utils.ErrorLog(err.Error())
  10300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10301. return
  10302. }
  10303. StartTime := theTime.Unix()
  10304. advice_name, _ := dataBody["advice_name"].(string)
  10305. advice_desc, _ := dataBody["advice_desc"].(string)
  10306. delivery_way, _ := dataBody["delivery_way"].(string)
  10307. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10308. prescribing_number := dataBody["prescribing_number"].(float64)
  10309. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10310. remark := dataBody["remark"].(string)
  10311. single_dose := dataBody["single_dose"].(float64)
  10312. single_dose_unit := dataBody["single_dose_unit"].(string)
  10313. id := int64(dataBody["id"].(float64))
  10314. frequency_type := int64(dataBody["frequency_type"].(float64))
  10315. frequency_week, _ := dataBody["frequency_week"].(string)
  10316. day_count := int64(dataBody["day_count"].(float64))
  10317. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10318. advice := models.XtDoctorAdviceOne{
  10319. AdviceDate: AdviceDate,
  10320. StartTime: StartTime,
  10321. AdviceName: advice_name,
  10322. AdviceDesc: advice_desc,
  10323. SingleDose: single_dose,
  10324. SingleDoseUnit: single_dose_unit,
  10325. PrescribingNumber: prescribing_number,
  10326. PrescribingNumberUnit: prescribing_number_unit,
  10327. DeliveryWay: delivery_way,
  10328. ExecutionFrequency: execution_frequency,
  10329. AdviceDoctor: advice_doctor,
  10330. Remark: remark,
  10331. RecordDate: RecordDate,
  10332. FrequencyType: frequency_type,
  10333. DayCount: day_count,
  10334. WeekDay: frequency_week,
  10335. }
  10336. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10337. c.ServeSuccessJSON(map[string]interface{}{
  10338. "advice": advice,
  10339. })
  10340. }
  10341. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10342. dataBody := make(map[string]interface{}, 0)
  10343. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10344. if err != nil {
  10345. utils.ErrorLog(err.Error())
  10346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10347. return
  10348. }
  10349. timeLayout := "2006-01-02"
  10350. loc, _ := time.LoadLocation("Local")
  10351. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10352. utils.ErrorLog("start_time")
  10353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10354. return
  10355. }
  10356. startTime2, _ := dataBody["start_time"].(string)
  10357. time_arr := strings.Split(startTime2, " ")
  10358. if len(time_arr) > 0 {
  10359. startTime2 = time_arr[0]
  10360. }
  10361. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10362. utils.ErrorLog("advice_date")
  10363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10364. return
  10365. }
  10366. advice_date, _ := dataBody["advice_date"].(string)
  10367. var advicedateunix int64
  10368. if len(advice_date) > 0 {
  10369. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10370. if err != nil {
  10371. fmt.Println(err)
  10372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10373. return
  10374. }
  10375. advicedateunix = theTime.Unix()
  10376. }
  10377. adviceDate := startTime2
  10378. if len(adviceDate) == 0 {
  10379. utils.ErrorLog("len(adviceDate) == 0")
  10380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10381. return
  10382. }
  10383. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10384. if err != nil {
  10385. utils.ErrorLog(err.Error())
  10386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10387. return
  10388. }
  10389. AdviceDate := advicedateunix
  10390. RecordDate := advicedateunix
  10391. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10392. utils.ErrorLog("start_time")
  10393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10394. return
  10395. }
  10396. startTime, _ := dataBody["start_time"].(string)
  10397. if len(startTime) == 0 {
  10398. utils.ErrorLog("len(start_time) == 0")
  10399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10400. return
  10401. }
  10402. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10403. if err != nil {
  10404. utils.ErrorLog(err.Error())
  10405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10406. return
  10407. }
  10408. StartTime := theTime.Unix()
  10409. advice_name, _ := dataBody["advice_name"].(string)
  10410. advice_desc, _ := dataBody["advice_desc"].(string)
  10411. delivery_way, _ := dataBody["delivery_way"].(string)
  10412. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10413. prescribing_number := dataBody["prescribing_number"].(float64)
  10414. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10415. remark := dataBody["remark"].(string)
  10416. single_dose := dataBody["single_dose"].(float64)
  10417. single_dose_unit := dataBody["single_dose_unit"].(string)
  10418. id := int64(dataBody["id"].(float64))
  10419. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10420. advice := models.XtDoctorAdviceOne{
  10421. AdviceDate: AdviceDate,
  10422. StartTime: StartTime,
  10423. AdviceName: advice_name,
  10424. AdviceDesc: advice_desc,
  10425. SingleDose: single_dose,
  10426. SingleDoseUnit: single_dose_unit,
  10427. PrescribingNumber: prescribing_number,
  10428. PrescribingNumberUnit: prescribing_number_unit,
  10429. DeliveryWay: delivery_way,
  10430. ExecutionFrequency: execution_frequency,
  10431. AdviceDoctor: advice_doctor,
  10432. Remark: remark,
  10433. RecordDate: RecordDate,
  10434. }
  10435. service.UpdateMobileDoctorAdviceById(id, advice)
  10436. c.ServeSuccessJSON(map[string]interface{}{
  10437. "advice": advice,
  10438. })
  10439. }
  10440. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10441. dataBody := make(map[string]interface{}, 0)
  10442. timeLayout := "2006-01-02"
  10443. loc, _ := time.LoadLocation("Local")
  10444. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10445. if err != nil {
  10446. utils.ErrorLog(err.Error())
  10447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10448. return
  10449. }
  10450. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10451. utils.ErrorLog("start_time")
  10452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10453. return
  10454. }
  10455. startTime2, _ := dataBody["start_time"].(string)
  10456. time_arr := strings.Split(startTime2, " ")
  10457. if len(time_arr) > 0 {
  10458. startTime2 = time_arr[0]
  10459. }
  10460. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10461. utils.ErrorLog("advice_date")
  10462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10463. return
  10464. }
  10465. advice_date, _ := dataBody["advice_date"].(string)
  10466. var advicedateunix int64
  10467. if len(advice_date) > 0 {
  10468. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10469. if err != nil {
  10470. fmt.Println(err)
  10471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10472. return
  10473. }
  10474. advicedateunix = theTime.Unix()
  10475. }
  10476. adviceDate := startTime2
  10477. if len(adviceDate) == 0 {
  10478. utils.ErrorLog("len(adviceDate) == 0")
  10479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10480. return
  10481. }
  10482. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10483. if err != nil {
  10484. utils.ErrorLog(err.Error())
  10485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10486. return
  10487. }
  10488. RecordDate := advicedateunix
  10489. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10490. utils.ErrorLog("start_time")
  10491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10492. return
  10493. }
  10494. startTime, _ := dataBody["start_time"].(string)
  10495. if len(startTime) == 0 {
  10496. utils.ErrorLog("len(start_time) == 0")
  10497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10498. return
  10499. }
  10500. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10501. if err != nil {
  10502. utils.ErrorLog(err.Error())
  10503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10504. return
  10505. }
  10506. StartTime := theTime.Unix()
  10507. patient_id := int64(dataBody["patient_id"].(float64))
  10508. group_no := int64(dataBody["group_no"].(float64))
  10509. org_id := c.GetMobileAdminUserInfo().Org.Id
  10510. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10511. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10512. utils.ErrorLog("advices")
  10513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10514. return
  10515. }
  10516. adviceNames := dataBody["advices"].([]interface{})
  10517. var advices []*models.GroupAdvice
  10518. for _, adviceNameMap := range adviceNames {
  10519. var advice models.GroupAdvice
  10520. adviceNameM := adviceNameMap.(map[string]interface{})
  10521. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10522. utils.ErrorLog("advice_name")
  10523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10524. return
  10525. }
  10526. adviceName, _ := adviceNameM["advice_name"].(string)
  10527. if len(adviceName) == 0 {
  10528. utils.ErrorLog("len(advice_name) == 0")
  10529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10530. return
  10531. }
  10532. advice.AdviceName = adviceName
  10533. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10534. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10535. advice.DrugSpec = drugSpec
  10536. }
  10537. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10538. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10539. advice.AdviceDesc = adviceDesc
  10540. }
  10541. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10542. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10543. advice.DrugSpecUnit = drugSpecUnit
  10544. }
  10545. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10546. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10547. advice.SingleDose = singleDose
  10548. }
  10549. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10550. singleDose := adviceNameM["single_dose"].(float64)
  10551. advice.SingleDose = singleDose
  10552. }
  10553. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10554. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10555. advice.SingleDoseUnit = singleDoseUnit
  10556. }
  10557. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10558. tmp := adviceNameM["single_dose_unit"].(float64)
  10559. singleDoseUnit := service.TypeConversion(tmp)
  10560. advice.SingleDoseUnit = singleDoseUnit
  10561. }
  10562. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10563. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10564. advice.PrescribingNumber = prescribingNumber
  10565. }
  10566. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10567. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10568. advice.PrescribingNumber = prescribingNumber
  10569. }
  10570. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10571. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10572. advice.PrescribingNumberUnit = prescribingNumberUnit
  10573. }
  10574. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10575. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10576. advice.DeliveryWay = deliveryWay
  10577. }
  10578. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10579. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10580. advice.ExecutionFrequency = executionFrequency
  10581. }
  10582. remark, _ := adviceNameM["remark"].(string)
  10583. advice.Remark = remark
  10584. advice.AdviceType = 1
  10585. advice.StartTime = StartTime
  10586. advice.RecordDate = RecordDate
  10587. advice.PatientId = patient_id
  10588. advice.UserOrgId = org_id
  10589. advice.AdviceDoctor = advice_doctor
  10590. advices = append(advices, &advice)
  10591. }
  10592. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10593. c.ServeSuccessJSON(map[string]interface{}{
  10594. "advice": newAdvices,
  10595. })
  10596. }