dialysis_api_controller.go 454KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737
  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 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  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. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. var first_sup int64
  1771. if first_super == "是" {
  1772. first_sup = 1
  1773. }
  1774. if first_super == "否" {
  1775. first_sup = 2
  1776. }
  1777. if first_super == "请选择" {
  1778. first_sup = 0
  1779. }
  1780. is_sequential := c.GetString("is_sequential")
  1781. var is_sequent int64
  1782. if is_sequential == "是" {
  1783. is_sequent = 1
  1784. }
  1785. if is_sequential == "否" {
  1786. is_sequent = 2
  1787. }
  1788. if is_sequential == "请选择" {
  1789. is_sequent = 0
  1790. }
  1791. conduct := c.GetString("conduct")
  1792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1793. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1794. //
  1795. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1796. // if appRole.UserType == 3 {
  1797. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1798. // if getPermissionErr != nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. // return
  1801. // } else if headNursePermission == nil {
  1802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1803. // return
  1804. // }
  1805. // }
  1806. //}
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= recordDate.Unix() {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. if mode_id > 0 {
  1826. var str string
  1827. //查找该机构用的是什么透析器
  1828. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1829. if filedConfig.ID > 0 {
  1830. str = dialyzerPerfusionApparatus
  1831. } else {
  1832. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1833. }
  1834. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1835. }
  1836. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1837. var dialysis_dialyszers_id int64
  1838. var dialysis_strainer_id int64
  1839. var dialysis_irrigation_id int64
  1840. if len(goodList) > 0 {
  1841. for _, item := range goodList {
  1842. if item.SpecificationName == dialysis_dialyszers {
  1843. dialysis_dialyszers_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_irrigation {
  1846. dialysis_irrigation_id = item.ID
  1847. }
  1848. if item.SpecificationName == dialysis_strainer {
  1849. dialysis_strainer_id = item.ID
  1850. }
  1851. }
  1852. }
  1853. //TODO 需要根据角色去判断
  1854. prescription := models.DialysisPrescription{
  1855. UserOrgId: adminUserInfo.Org.Id,
  1856. PatientId: id,
  1857. RecordDate: recordDate.Unix(),
  1858. ModeId: mode_id,
  1859. DialysisDuration: dialysis_duration,
  1860. Dialyzer: dialyzer,
  1861. PerfusionApparatus: perfusion_apparatus,
  1862. BloodFlowVolume: blood_flow_volume,
  1863. DewaterAmount: dewater_amount,
  1864. DisplaceLiqui: displace_liqui,
  1865. ReplacementWay: replacement_way,
  1866. Anticoagulant: anticoagulant,
  1867. AnticoagulantShouji: anticoagulant_shouji,
  1868. AnticoagulantWeichi: anticoagulant_weichi,
  1869. AnticoagulantZongliang: anticoagulant_zongliang,
  1870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1872. Kalium: kalium,
  1873. Sodium: sodium,
  1874. Calcium: calcium,
  1875. Bicarbonate: bicarbonate,
  1876. Glucose: glucose,
  1877. // DryWeight: dry_weight,
  1878. DialysateFlow: dialysate_flow,
  1879. DialysateTemperature: dialysate_temperature,
  1880. // PrescriptionDoctor: prescription_doctor,
  1881. ReplacementTotal: replacement_total,
  1882. Conductivity: conductivity,
  1883. Remark: remark,
  1884. Status: 1,
  1885. CreatedTime: time.Now().Unix(),
  1886. UpdatedTime: time.Now().Unix(),
  1887. DialysisDurationMinute: dialysisDurationMinute,
  1888. DialysisDurationHour: dialysisDurationHour,
  1889. TargetUltrafiltration: targetUltrafiltration,
  1890. DialysateFormulation: dialysateFormulation,
  1891. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1892. BodyFluid: body_fluid,
  1893. SpecialMedicine: special_medicine,
  1894. SpecialMedicineOther: special_medicine_other,
  1895. DisplaceLiquiPart: displace_liqui_part,
  1896. DisplaceLiquiValue: displace_liqui_value,
  1897. BloodAccess: blood_access,
  1898. Ultrafiltration: ultrafiltration,
  1899. BodyFluidOther: body_fluid_other,
  1900. Niprocart: niprocart,
  1901. Jms: jms,
  1902. FistulaNeedleSet: fistula_needle_set,
  1903. FistulaNeedleSet16: fistula_needle_set_16,
  1904. Hemoperfusion: hemoperfusion,
  1905. DialyserSterilised: dialyser_sterilised,
  1906. Filtryzer: filtryzer,
  1907. Dialyzers: dialyzers,
  1908. Injector: injector,
  1909. Bloodlines: bloodlines,
  1910. TubingHemodialysis: tubing_hemodialysis,
  1911. Package: safe_package,
  1912. ALiquid: a_liquid,
  1913. TargetKtv: target_ktv,
  1914. PreImpulse: pre_impulse,
  1915. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1916. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1917. Blood: blood,
  1918. DialysisDialyszers: dialysis_dialyszers,
  1919. DialysisIrrigation: dialysis_irrigation,
  1920. AntioxidantCommodityName: antioxidant_commodity_name,
  1921. DisplaceSpeed: displace_speed,
  1922. Illness: illness,
  1923. Amylaceum: amylaceum,
  1924. SingleTime: single_time,
  1925. SingleWater: single_water,
  1926. ReplacementFlow: replacement_flow,
  1927. PlasmaSeparator: plasma_separator,
  1928. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1929. OxygenUptake: oxygen_uptake,
  1930. OxygenFlow: oxygen_flow,
  1931. OxygenTime: oxygen_time,
  1932. HemodialysisPipelines: hemodialysis_pipelines,
  1933. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1934. PunctureNeedle: puncture_needle,
  1935. PunctureNeedleCount: puncture_needle_count,
  1936. Epo: epo,
  1937. EpoCount: epo_count,
  1938. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1939. AdminUserId: admin_user_id,
  1940. IsWater: is_war,
  1941. DrhyWater: drhy_water,
  1942. DryWaterHour: dry_water_hour,
  1943. WaterMachine: water_machine,
  1944. AddAmount: add_amount,
  1945. ReduceAmount: reduce_amount,
  1946. DialysisRemark: dialysis_remark,
  1947. PrescribingNumber: prescribing_number,
  1948. StartSodium: start_sodium,
  1949. SodiumCurve: sodium_curve,
  1950. TreatmentRemark: treatment_remark,
  1951. PrescriptionSodium: prescription_sodium,
  1952. DialysisFluidFlow: dialysis_fluid_flow,
  1953. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1954. PrescriptionWater: prescription_water,
  1955. DialysisStrainer: dialysis_strainer,
  1956. Chaptalization: chaptalization,
  1957. WashingTime: washing_time,
  1958. WarshCount: warsh_count,
  1959. BloodAccessPartId: blood_access_part_id,
  1960. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1961. Dialyzate: dialyzate,
  1962. DialysisDialyszersId: dialysis_dialyszers_id,
  1963. DialysisIrrigationId: dialysis_irrigation_id,
  1964. DialysisStrainerId: dialysis_strainer_id,
  1965. FirstSuper: first_sup,
  1966. IsSequential: is_sequent,
  1967. Conduct: conduct,
  1968. }
  1969. if adminUserInfo.Org.Id == 10721 {
  1970. if prescription.ModeId == 2 {
  1971. if prescription.ReplacementTotal == 0 {
  1972. prescription.ReplacementTotal = 15
  1973. }
  1974. }
  1975. }
  1976. //查询最近透析准备表里是否存在 透析器 灌流器
  1977. //
  1978. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1979. //
  1980. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1981. //
  1982. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1983. //if len(mation)>0{
  1984. // for _, item := range splitStr {
  1985. // for _,it := range mation{
  1986. // if(item == it.SpecificationName){
  1987. //
  1988. // //查询最近一次的透析器
  1989. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1990. //
  1991. // if errcode == gorm.ErrRecordNotFound{
  1992. // //插入数据
  1993. // prepare := models.DialysisBeforePrepare{
  1994. // UserOrgId: adminUserInfo.Org.Id,
  1995. // PatientId: id,
  1996. // RecordDate: recordDate.Unix(),
  1997. // GoodTypeId: it.GoodTypeId,
  1998. // GoodId: it.ID,
  1999. // Count: 1,
  2000. // Ctime: time.Now().Unix(),
  2001. // Creater: adminUserInfo.AdminUser.Id,
  2002. // Status:1,
  2003. //
  2004. // }
  2005. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2006. // fmt.Println("",errcode)
  2007. // }
  2008. // }
  2009. // }
  2010. //
  2011. // }
  2012. //
  2013. // for _, item := range splitIrrigation {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. // //查询最近一次的透析器
  2017. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2018. // if errcode == gorm.ErrRecordNotFound{
  2019. // //插入数据
  2020. // prepare := models.DialysisBeforePrepare{
  2021. // UserOrgId: adminUserInfo.Org.Id,
  2022. // PatientId: id,
  2023. // RecordDate: recordDate.Unix(),
  2024. // GoodTypeId: it.GoodTypeId,
  2025. // GoodId: it.ID,
  2026. // Count: 1,
  2027. // Ctime: time.Now().Unix(),
  2028. // Creater: adminUserInfo.AdminUser.Id,
  2029. // Status:1,
  2030. //
  2031. // }
  2032. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2033. // fmt.Println(errcode)
  2034. // }
  2035. // }
  2036. // }
  2037. // }
  2038. //}
  2039. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2040. if dialysisPrescription.ID == 0 { //新增
  2041. if appRole.UserType == 2 || appRole.UserType == 1 {
  2042. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2043. }
  2044. prescription.Creater = adminUserInfo.AdminUser.Id
  2045. //针对河间咸得
  2046. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2047. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2048. prescription.DisplaceLiquiPart = 0
  2049. prescription.DisplaceLiquiValue = 0
  2050. }
  2051. }
  2052. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2053. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2054. }
  2055. err := service.AddSigleRecord(&prescription)
  2056. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2057. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2058. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2059. if len(monitorList) > 0 {
  2060. var ultrafiltration_rate float64
  2061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2062. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2063. var replacement_rate float64
  2064. //乘10 除10是为了保留一位小数
  2065. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2066. var firstOpeateTime = monitorList[0].OperateTime
  2067. for _, item := range monitorList {
  2068. //超滤率
  2069. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2070. //置换率
  2071. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2072. //超滤量
  2073. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2074. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2075. //置换量
  2076. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2077. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2078. }
  2079. }
  2080. }
  2081. //记录日志
  2082. byterequest, _ := json.Marshal(prescription)
  2083. prescriptionLog := models.XtDialysisPrescriptionLog{
  2084. UserOrgId: prescription.UserOrgId,
  2085. Ctime: time.Now().Unix(),
  2086. Mtime: 0,
  2087. ErrLog: string(byterequest),
  2088. AdminUserId: adminUserInfo.AdminUser.Id,
  2089. RecordDate: prescription.RecordDate,
  2090. PatientId: prescription.PatientId,
  2091. Source: "手机端新增保存处方",
  2092. Status: 1,
  2093. }
  2094. service.CreatePrescriptionLog(prescriptionLog)
  2095. finish := models.XtDialysisFinish{
  2096. IsFinish: 1,
  2097. UserOrgId: adminUserInfo.Org.Id,
  2098. Status: 1,
  2099. Ctime: time.Now().Unix(),
  2100. Mtime: 0,
  2101. Module: 1,
  2102. RecordDate: recordDate.Unix(),
  2103. Sourse: 1,
  2104. PatientId: id,
  2105. }
  2106. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2107. if dialysisFinish.ID == 0 {
  2108. service.CreateDialysisFinish(finish)
  2109. }
  2110. //长沙南雅医院,自动生成抗凝剂的临时处方
  2111. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2112. if prescribing_number == 0 {
  2113. prescribing_number = 1
  2114. }
  2115. if prescribing_number == 0 && id == 14682 {
  2116. prescribing_number = 2
  2117. }
  2118. if prescribing_number == 0 && id == 18560 {
  2119. prescribing_number = 2
  2120. }
  2121. advice := models.DoctorAdvice{
  2122. UserOrgId: adminUserInfo.Org.Id,
  2123. PatientId: id,
  2124. GroupNo: 0,
  2125. AdviceType: 2,
  2126. RecordDate: recordDate.Unix(),
  2127. AdviceDate: recordDate.Unix(),
  2128. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2129. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2130. AdviceDesc: "",
  2131. ReminderDate: 0,
  2132. SingleDose: anticoagulant_zongliang,
  2133. SingleDoseUnit: "iu",
  2134. DrugSpec: 0,
  2135. DrugSpecUnit: "",
  2136. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2137. PrescribingNumberUnit: "支",
  2138. DeliveryWay: "静脉注射",
  2139. ExecutionFrequency: "上机前",
  2140. AdviceDoctor: 0,
  2141. Status: 1,
  2142. CreatedTime: time.Now().Unix(),
  2143. UpdatedTime: time.Now().Unix(),
  2144. IsPrescription: 1,
  2145. ExecutionState: 2,
  2146. StopState: 2,
  2147. IsSettle: 2,
  2148. }
  2149. // 查询排班信息
  2150. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2151. if schedulePatient.ID > 0 {
  2152. if schedulePatient.ScheduleType == 1 {
  2153. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2154. }
  2155. if schedulePatient.ScheduleType == 2 {
  2156. advice.StartTime = recordDate.Unix() + 9*60*60
  2157. }
  2158. }
  2159. // 抗凝剂名称
  2160. switch anticoagulant {
  2161. case 1:
  2162. advice.AdviceName = "无肝素"
  2163. break
  2164. case 2:
  2165. advice.AdviceName = "普通肝素"
  2166. break
  2167. case 3:
  2168. advice.AdviceName = "低分子肝素"
  2169. break
  2170. case 4:
  2171. advice.AdviceName = "阿加曲班"
  2172. break
  2173. case 5:
  2174. advice.AdviceName = "枸橼酸钠"
  2175. break
  2176. case 6:
  2177. advice.AdviceName = "低分子肝素钙"
  2178. break
  2179. case 7:
  2180. advice.AdviceName = "低分子肝素钠"
  2181. break
  2182. case 8:
  2183. advice.AdviceName = "依诺肝素"
  2184. break
  2185. case 9:
  2186. advice.AdviceName = "达肝素"
  2187. break
  2188. case 10:
  2189. advice.AdviceName = "体外抗凝"
  2190. break
  2191. case 11:
  2192. advice.AdviceName = "那曲肝素"
  2193. break
  2194. case 12:
  2195. advice.AdviceName = "无抗凝剂"
  2196. break
  2197. }
  2198. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2199. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2200. advice.AdviceDoctor = appRole.AdminUserId
  2201. }
  2202. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2203. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2204. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2205. advice.AdviceName = "低分子肝素钠注射液"
  2206. // 修改患者临时医嘱里的抗凝剂医嘱
  2207. advice.ID = advicePrescription.ID
  2208. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2209. } else {
  2210. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2211. advice.AdviceName = "低分子肝素钠注射液"
  2212. // 新增患者临时医嘱里的抗凝剂医嘱
  2213. service.CreateDoctorAdvice(&advice)
  2214. }
  2215. }
  2216. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2217. redis := service.RedisClient()
  2218. defer redis.Close()
  2219. //清空key 值
  2220. redis.Set(key, "", time.Second)
  2221. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2222. redis.Set(keyOne, "", time.Second)
  2223. }
  2224. //获取key,清空redis
  2225. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2226. redis := service.RedisClient()
  2227. //清空key 值
  2228. redis.Set(key, "", time.Second)
  2229. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2230. //清空key 值
  2231. redis.Set(keyOne, "", time.Second)
  2232. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2233. //清空key 值
  2234. redis.Set(keyTwo, "", time.Second)
  2235. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2236. redis.Set(keySix, "", time.Second)
  2237. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2238. redis.Set(keySeven, "", time.Second)
  2239. if err == nil {
  2240. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2241. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2242. //清空key 值
  2243. redis.Set(keyThree, "", time.Second)
  2244. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2245. //清空key 值
  2246. redis.Set(keyFour, "", time.Second)
  2247. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2248. redis.Set(keyFive, "", time.Second)
  2249. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2250. redis.Set(keySix, "", time.Second)
  2251. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2252. redis.Set(keySeven, "", time.Second)
  2253. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2254. //清空key 值
  2255. redis.Set(keyOne, "", time.Second)
  2256. if updateErr != nil {
  2257. utils.ErrorLog("%v", updateErr)
  2258. }
  2259. defer redis.Close()
  2260. c.ServeSuccessJSON(map[string]interface{}{
  2261. "prescription": prescription,
  2262. })
  2263. }
  2264. } else { //修改
  2265. //if mode_id > 0 {
  2266. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2267. //}
  2268. //if template.TemplateId == 1 {
  2269. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2270. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2271. // if getPermissionErr != nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2273. // return
  2274. // } else if headNursePermission == nil {
  2275. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2276. // return
  2277. // }
  2278. // }
  2279. //}
  2280. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2281. prescription.Modifier = adminUserInfo.AdminUser.Id
  2282. if appRole.UserType == 2 || appRole.UserType == 1 {
  2283. prescription_doctor := adminUserInfo.AdminUser.Id
  2284. prescription.PrescriptionDoctor = prescription_doctor
  2285. } else {
  2286. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2287. }
  2288. if dialysisPrescription.Creater == 0 { //体重称
  2289. prescription.Creater = adminUserInfo.AdminUser.Id
  2290. } else {
  2291. prescription.Creater = dialysisPrescription.Creater
  2292. if adminUserInfo.Org.Id == 9882 {
  2293. if appRole.UserType == 2 || appRole.UserType == 1 {
  2294. prescription_doctor := adminUserInfo.AdminUser.Id
  2295. prescription.PrescriptionDoctor = prescription_doctor
  2296. prescription.Creater = prescription_doctor
  2297. }
  2298. }
  2299. }
  2300. prescription.ID = dialysisPrescription.ID
  2301. if adminUserInfo.Org.Id == 10721 {
  2302. if prescription.ModeId == 2 {
  2303. if prescription.ReplacementTotal == 0 {
  2304. prescription.ReplacementTotal = 15
  2305. }
  2306. }
  2307. }
  2308. service.UpDateDialysisPrescription(&prescription)
  2309. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2310. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2311. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2312. if len(monitorList) > 0 {
  2313. var ultrafiltration_rate float64
  2314. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2315. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2316. var replacement_rate float64
  2317. //乘10 除10是为了保留一位小数
  2318. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2319. var firstOpeateTime = monitorList[0].OperateTime
  2320. for _, item := range monitorList {
  2321. //超滤率
  2322. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2323. //置换率
  2324. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2325. //超滤量
  2326. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2327. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2328. //置换量
  2329. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2330. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2331. }
  2332. }
  2333. }
  2334. //记录日志
  2335. byterequest, _ := json.Marshal(prescription)
  2336. prescriptionLog := models.XtDialysisPrescriptionLog{
  2337. UserOrgId: prescription.UserOrgId,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: 0,
  2340. ErrLog: string(byterequest),
  2341. AdminUserId: adminUserInfo.AdminUser.Id,
  2342. RecordDate: prescription.RecordDate,
  2343. PatientId: prescription.PatientId,
  2344. Source: "手机端修改处方",
  2345. Status: 1,
  2346. }
  2347. service.CreatePrescriptionLog(prescriptionLog)
  2348. finish := models.XtDialysisFinish{
  2349. IsFinish: 1,
  2350. UserOrgId: adminUserInfo.Org.Id,
  2351. Status: 1,
  2352. Ctime: time.Now().Unix(),
  2353. Mtime: 0,
  2354. Module: 1,
  2355. RecordDate: recordDate.Unix(),
  2356. Sourse: 1,
  2357. PatientId: id,
  2358. }
  2359. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2360. if dialysisFinish.ID == 0 {
  2361. service.CreateDialysisFinish(finish)
  2362. }
  2363. //修改处方
  2364. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2365. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2366. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2367. if advicePrescription.ID > 0 {
  2368. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2369. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2370. redis := service.RedisClient()
  2371. defer redis.Close()
  2372. //清空key 值
  2373. redis.Set(key, "", time.Second)
  2374. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2375. redis.Set(keyOne, "", time.Second)
  2376. }
  2377. }
  2378. //获取key,清空redis
  2379. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2380. redis := service.RedisClient()
  2381. //清空key 值
  2382. redis.Set(key, "", time.Second)
  2383. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2384. //清空key 值
  2385. redis.Set(keyOne, "", time.Second)
  2386. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2387. redis.Set(keySix, "", time.Second)
  2388. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2389. redis.Set(keySeven, "", time.Second)
  2390. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2391. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2392. //清空key 值
  2393. redis.Set(keyTwoOne, "", time.Second)
  2394. defer redis.Close()
  2395. if updateErr != nil {
  2396. utils.ErrorLog("%v", updateErr)
  2397. }
  2398. c.ServeSuccessJSON(map[string]interface{}{
  2399. "prescription": prescription,
  2400. })
  2401. }
  2402. }
  2403. func (c *DialysisAPIController) Finish() {
  2404. id, _ := c.GetInt64("patient", 0)
  2405. recordDateStr := c.GetString("record_date")
  2406. nurseID, _ := c.GetInt64("nurse")
  2407. end_time := c.GetString("end_time")
  2408. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2409. internal_fistula := c.GetString("blood_access_internal_fistula")
  2410. catheter := c.GetString("catheter")
  2411. cruor := c.GetString("cruor")
  2412. mission := c.GetString("mission")
  2413. condenser := c.GetString("condenser")
  2414. if id <= 0 || nurseID <= 0 {
  2415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2416. return
  2417. }
  2418. adminUserInfo := c.GetMobileAdminUserInfo()
  2419. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2420. if patient.ID == 0 {
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2422. return
  2423. }
  2424. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2425. if getNurseErr != nil {
  2426. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. } else if nurse == nil {
  2430. c.ErrorLog("护士不存在")
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. if len(recordDateStr) == 0 {
  2435. recordDateStr = time.Now().Format("2006-01-02")
  2436. }
  2437. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2438. if parseDateErr != nil {
  2439. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2441. return
  2442. }
  2443. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2444. if parseEndDateErr != nil {
  2445. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. // 查询信息规挡的设置天数
  2450. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2451. if infor.ID > 0 && infor.WeekDay > 0 {
  2452. var cha_time int64
  2453. timeNowStr := time.Now().Format("2006-01-02")
  2454. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2455. //今日的日期减去设置的日期
  2456. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2457. if cha_time >= recordDate.Unix() {
  2458. //查询审核是否允许
  2459. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2460. //申请状态不允许的情况 拒绝修改
  2461. if infor.ApplicationStatus != 1 {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2463. return
  2464. }
  2465. }
  2466. }
  2467. //now := time.Now()
  2468. //year, month, day := now.Date()
  2469. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2470. //todayTimeStamp := today_time.Unix()
  2471. // 获取当天的第一条透析纪录
  2472. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2473. if getMonitorRecordsErr != nil {
  2474. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2476. return
  2477. }
  2478. // 获取当前的最后一条透析纪录
  2479. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2480. if getMonitorRecordsErr != nil {
  2481. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. return
  2484. }
  2485. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2486. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2487. if getAADErr != nil {
  2488. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2490. return
  2491. }
  2492. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2493. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2494. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2495. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2496. if assessmentAfterDislysis != nil {
  2497. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2498. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2499. } else {
  2500. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2501. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2502. tempassessmentAfterDislysis.Status = 1
  2503. tempassessmentAfterDislysis.PatientId = id
  2504. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2505. }
  2506. //长沙南雅
  2507. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2508. //获取最后一条透析处方数据
  2509. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2510. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2511. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2512. }
  2513. if dialysisOrder.Stage == 1 {
  2514. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2515. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2516. fmt.Println(value)
  2517. a, b := math.Modf(value)
  2518. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2519. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2520. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2521. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2522. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2523. }
  2524. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2525. //var num1 int64
  2526. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2527. //fmt.Println(num1)
  2528. //sub := float64(num1 / 3600)
  2529. //fmt.Println(sub)
  2530. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2531. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2532. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2533. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2534. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2535. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2536. if adminUserInfo.Org.Id != 10375 {
  2537. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2538. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2539. }
  2540. if adminUserInfo.Org.Id != 10445 {
  2541. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2542. }
  2543. //北方营口医院
  2544. if adminUserInfo.Org.Id == 10445 {
  2545. //获取最后一条透析处方数据
  2546. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2547. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2548. } else {
  2549. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2550. }
  2551. //新化博翔
  2552. if adminUserInfo.Org.Id == 10447 {
  2553. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2554. }
  2555. //阳春
  2556. if adminUserInfo.Org.Id == 10485 {
  2557. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2558. }
  2559. if adminUserInfo.Org.Id == 10551 {
  2560. //获取最后一条透析处方数据
  2561. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2563. }
  2564. if adminUserInfo.Org.Id == 10580 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2566. }
  2567. if adminUserInfo.Org.Id == 10612 {
  2568. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2569. }
  2570. //孝康
  2571. if adminUserInfo.Org.Id == 10693 {
  2572. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2573. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2574. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2576. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2577. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2578. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2579. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2580. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2581. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2582. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2583. }
  2584. if adminUserInfo.Org.Id == 10721 {
  2585. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2587. }
  2588. if adminUserInfo.Org.Id == 10697 {
  2589. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2590. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2591. lastWeightAfter.LastAfterWeight = floatAfeter
  2592. }
  2593. if adminUserInfo.Org.Id == 10624 {
  2594. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2595. }
  2596. }
  2597. 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 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 {
  2598. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2599. if adminUserInfo.Org.Id != 10702 {
  2600. if evaluation.SystolicBloodPressure == 0 {
  2601. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2602. if adminUserInfo.Org.Id == 10693 {
  2603. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2604. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2605. }
  2606. pre := models.PredialysisEvaluation{
  2607. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2608. }
  2609. fmt.Println("prew", pre)
  2610. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2613. redis := service.RedisClient()
  2614. redis.Set(key, "", time.Second)
  2615. redis.Set(keyOne, "", time.Second)
  2616. defer redis.Close()
  2617. fmt.Println(getNurseErr)
  2618. }
  2619. }
  2620. if adminUserInfo.Org.Id != 10702 {
  2621. if evaluation.DiastolicBloodPressure == 0 {
  2622. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2623. if adminUserInfo.Org.Id == 10693 {
  2624. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2625. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2626. }
  2627. pres := models.PredialysisEvaluation{
  2628. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2629. }
  2630. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2632. redis := service.RedisClient()
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2635. redis.Set(keyOne, "", time.Second)
  2636. defer redis.Close()
  2637. fmt.Println(getNurseErr)
  2638. }
  2639. }
  2640. if adminUserInfo.Org.Id != 10702 {
  2641. if evaluation.PulseFrequency == 0 {
  2642. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2643. if adminUserInfo.Org.Id == 10693 {
  2644. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2645. evaluation.PulseFrequency = pulseFrequency
  2646. }
  2647. press := models.PredialysisEvaluation{
  2648. PulseFrequency: evaluation.PulseFrequency,
  2649. }
  2650. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2652. redis := service.RedisClient()
  2653. redis.Set(key, "", time.Second)
  2654. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2655. redis.Set(keyOne, "", time.Second)
  2656. defer redis.Close()
  2657. fmt.Println(getNurseErr)
  2658. }
  2659. }
  2660. if evaluation.Temperature == 0 {
  2661. evaluation.Temperature = fmonitorRecords.Temperature
  2662. press := models.PredialysisEvaluation{
  2663. Temperature: evaluation.Temperature,
  2664. }
  2665. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2667. redis := service.RedisClient()
  2668. redis.Set(key, "", time.Second)
  2669. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2670. redis.Set(keyOne, "", time.Second)
  2671. defer redis.Close()
  2672. fmt.Println(getNurseErr)
  2673. }
  2674. }
  2675. if adminUserInfo.Org.Id == 9583 {
  2676. //获取透析处方的最后一条数据
  2677. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2678. if diaerr != nil {
  2679. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2681. return
  2682. }
  2683. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2684. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2685. }
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2697. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2698. }
  2699. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2700. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2701. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2702. }
  2703. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2704. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2705. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2708. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2709. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2710. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2711. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2712. }
  2713. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2714. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2715. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2716. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2717. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2718. }
  2719. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2720. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2721. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2722. }
  2723. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2724. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2725. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2726. }
  2727. if lastAssessmentAfterDislysis != nil {
  2728. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2729. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2730. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2731. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2732. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2733. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2734. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2735. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2736. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2737. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2738. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2739. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2740. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2741. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2742. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2743. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2744. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2745. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2746. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2747. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2748. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2749. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2750. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2751. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2752. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2753. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2754. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2755. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2756. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2757. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2758. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2759. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2760. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2761. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2762. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2763. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2764. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2765. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2766. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2767. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2768. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2769. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2770. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2771. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2772. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2773. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2774. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2775. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2776. if tempassessmentAfterDislysis.PatientId == 18695 {
  2777. tempassessmentAfterDislysis.ActualDisplacement = 0
  2778. }
  2779. if adminUserInfo.Org.Id != 10375 {
  2780. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2781. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2782. }
  2783. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2784. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2785. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2786. }
  2787. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2788. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2789. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2790. }
  2791. }
  2792. finish := models.XtDialysisFinish{
  2793. IsFinish: 1,
  2794. UserOrgId: adminUserInfo.Org.Id,
  2795. Status: 1,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: 0,
  2798. Module: 9,
  2799. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2800. Sourse: 1,
  2801. PatientId: tempassessmentAfterDislysis.PatientId,
  2802. }
  2803. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2804. if dialysisFinish.ID == 0 {
  2805. service.CreateDialysisFinish(finish)
  2806. }
  2807. //孝康
  2808. if adminUserInfo.Org.Id == 10693 {
  2809. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2810. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2811. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2812. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2813. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2814. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2815. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2816. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2817. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2818. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2819. }
  2820. if adminUserInfo.Org.Id == 10697 {
  2821. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2822. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2823. lastWeightAfter.LastAfterWeight = floatAfeter
  2824. }
  2825. if adminUserInfo.Org.Id == 10721 {
  2826. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2827. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2828. }
  2829. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2830. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2831. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2832. redis := service.RedisClient()
  2833. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2834. redis.Set(keyOne, "", time.Second)
  2835. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2836. redis.Set(keyTwo, "", time.Second)
  2837. defer redis.Close()
  2838. //清空key 值
  2839. redis.Set(key, "", time.Second)
  2840. if err != nil {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2842. return
  2843. }
  2844. if dialysisOrder == nil {
  2845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2846. return
  2847. }
  2848. if dialysisOrder.Stage == 2 {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2850. return
  2851. }
  2852. if dialysisOrder.Stage == 1 {
  2853. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2854. finish := models.XtDialysisFinish{
  2855. IsFinish: 1,
  2856. UserOrgId: adminUserInfo.Org.Id,
  2857. Status: 1,
  2858. Ctime: time.Now().Unix(),
  2859. Mtime: 0,
  2860. Module: 8,
  2861. RecordDate: recordDate.Unix(),
  2862. Sourse: 1,
  2863. PatientId: id,
  2864. }
  2865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2866. if dialysisFinish.ID == 0 {
  2867. service.CreateDialysisFinish(finish)
  2868. }
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis := service.RedisClient()
  2871. defer redis.Close()
  2872. //清空key 值
  2873. redis.Set(key, "", time.Second)
  2874. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2875. redis.Set(keyOne, "", time.Second)
  2876. //结束时候透析次数加1
  2877. service.UpdateSolutionByPatientId(id)
  2878. //下机完自动消毒,针对长沙南雅
  2879. if dialysisOrder.Stage == 1 {
  2880. 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 {
  2881. //根据床位号获取设备型号
  2882. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2883. //查询使用消毒最后一条消毒记录
  2884. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2885. fmt.Println("err", err)
  2886. if err == gorm.ErrRecordNotFound {
  2887. //查找排班
  2888. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2889. //查询改设备是否有消毒计划
  2890. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2891. //根据床位号获取设备id
  2892. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2893. //查询病人信息
  2894. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2895. var con = ""
  2896. if patients.IsInfectious == 0 {
  2897. con = ""
  2898. }
  2899. if patients.IsInfectious == 1 {
  2900. con = "无"
  2901. }
  2902. if patients.IsInfectious == 2 {
  2903. con = "有"
  2904. }
  2905. if errcode == nil {
  2906. var end_time int64
  2907. end_time = endDate.Unix() + plan.DisinfecTime*60
  2908. //新增消毒
  2909. information := models.DeviceInformation{
  2910. Date: dialysisOrder.DialysisDate,
  2911. Zone: dialysisOrder.ZoneId,
  2912. Class: dialysisOrder.SchedualType,
  2913. BedNumber: dialysisOrder.BedID,
  2914. PatientId: dialysisOrder.PatientId,
  2915. DialysisMode: scheduleByPatient.ModeId,
  2916. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2917. Disinfection: 1,
  2918. DialysisConcentration: 1,
  2919. DisinfectionStatus: 1,
  2920. Move: 1,
  2921. UserOrgId: dialysisOrder.UserOrgId,
  2922. DisinfectType: plan.Way,
  2923. DisinfectantType: plan.MachineDisinfectant,
  2924. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2925. Disinfectant: plan.Disinfectant,
  2926. Ctime: time.Now().Unix(),
  2927. Status: 1,
  2928. SignName: nurseID,
  2929. EquimentId: addmacher.ID,
  2930. DisinfectionResidue: 2,
  2931. Bed: addmacher.BedNumber,
  2932. StartTime: dialysisOrder.StartTime,
  2933. EndTime: dialysisOrder.EndTime,
  2934. Contagion: con,
  2935. WeightLoss: 0,
  2936. Hyperfiltratio: 0,
  2937. DialysisHour: "",
  2938. MachineRun: 1,
  2939. DisinfecStartime: endDate.Unix(),
  2940. DisinfecEndtime: end_time,
  2941. }
  2942. err := service.CreateInformationTwo(&information)
  2943. fmt.Println("报错", err)
  2944. }
  2945. }
  2946. }
  2947. }
  2948. dialysisOrder.Stage = 2
  2949. dialysisOrder.FinishNurse = nurseID
  2950. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2951. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2952. dialysisOrder.EndTime = endDate.Unix()
  2953. // 长沙南雅需求
  2954. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2955. //获取最后1条监测的数据
  2956. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2957. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2958. var accumulatedBloodVolume float64
  2959. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2960. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2961. fmt.Println(err)
  2962. // 查询未执行的医嘱
  2963. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2964. for _, item := range doctorAdvice {
  2965. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2966. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2967. redis := service.RedisClient()
  2968. //清空key 值
  2969. redis.Set(key, "", time.Second)
  2970. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2971. redis.Set(keyTwo, "", time.Second)
  2972. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2973. redis.Set(keyThree, "", time.Second)
  2974. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2975. theTime := toTime.Format("2006-01-02")
  2976. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2977. redis.Set(keyFour, "", time.Second)
  2978. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2979. redis.Set(keyFive, "", time.Second)
  2980. defer redis.Close()
  2981. }
  2982. }
  2983. go func() {
  2984. ssoDomain := beego.AppConfig.String("call_domain")
  2985. api := ssoDomain + "/index/downpatient"
  2986. values := make(url.Values)
  2987. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2988. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2989. values.Set("patient_id", strconv.FormatInt(id, 10))
  2990. http.PostForm(api, values)
  2991. }()
  2992. if err == nil {
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "dialysisOrder": dialysisOrder,
  2995. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2996. })
  2997. } else {
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2999. }
  3000. }
  3001. }
  3002. func (c *DialysisAPIController) GetAllZone() {
  3003. adminUserInfo := c.GetMobileAdminUserInfo()
  3004. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3005. if err == nil {
  3006. c.ServeSuccessJSON(map[string]interface{}{
  3007. "zone": zone,
  3008. })
  3009. }
  3010. }
  3011. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3012. adminUserInfo := c.GetMobileAdminUserInfo()
  3013. page, _ := c.GetInt64("page", 1)
  3014. limit, _ := c.GetInt64("limit", 10)
  3015. schedulType, _ := c.GetInt64("schedul_type", 0)
  3016. startTime, _ := c.GetInt64("schedul_time", 0)
  3017. partitionType, _ := c.GetInt64("partition_type", 0)
  3018. keywords := c.GetString("keywords")
  3019. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3020. if err == nil {
  3021. c.ServeSuccessJSON(map[string]interface{}{
  3022. "schedule": dialysisSchedule,
  3023. })
  3024. }
  3025. return
  3026. }
  3027. // /m/api/dialysis/start [post]
  3028. // @param patient_id:int
  3029. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3030. // @param nurse:int 上机护士
  3031. // @param bed:int 床位号
  3032. func (this *DialysisAPIController) StartDialysis() {
  3033. patientID, _ := this.GetInt64("patient_id")
  3034. recordDateStr := this.GetString("record_date")
  3035. nurseID, _ := this.GetInt64("start_nurse")
  3036. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3037. blood_drawing, _ := this.GetInt64("blood_drawing")
  3038. schedual_type, _ := this.GetInt64("schedual_type")
  3039. bedID, _ := this.GetInt64("bed")
  3040. start_time := this.GetString("start_time")
  3041. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3042. change_nurse, _ := this.GetInt64("change_nurse")
  3043. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3044. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3045. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3046. puncture_needle := this.GetString("puncture_needle")
  3047. puncture_way := this.GetString("puncture_way")
  3048. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3049. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3050. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3051. zone_id, _ := this.GetInt64("zone_id")
  3052. elecsign := this.GetString("url")
  3053. nuclein_date_str := this.GetString("nuclein_date_str")
  3054. schedule_remark := this.GetString("schedule_remark")
  3055. order_remark := this.GetString("order_remark")
  3056. catheter_operation := this.GetString("catheter_operation")
  3057. blood_flow_volume := this.GetString("blood_flow_volume")
  3058. dialysis_strainer := this.GetString("dialysis_strainer")
  3059. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3061. return
  3062. }
  3063. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3064. if parseStartDateErr != nil {
  3065. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. return
  3068. }
  3069. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3070. if parseErr != nil {
  3071. this.ErrorLog("时间解析失败:%v", parseErr)
  3072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3073. return
  3074. }
  3075. adminUserInfo := this.GetMobileAdminUserInfo()
  3076. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3077. if getPatientErr != nil {
  3078. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3080. return
  3081. } else if patient == nil {
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3083. return
  3084. }
  3085. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3086. if getNurseErr != nil {
  3087. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3089. return
  3090. } else if nurse == nil {
  3091. this.ErrorLog("护士不存在")
  3092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3093. return
  3094. }
  3095. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3096. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3097. if getDeviceNumberErr != nil {
  3098. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3100. return
  3101. } else if deviceNumber == nil {
  3102. this.ErrorLog("床位号不存在")
  3103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3107. if getRecordErr != nil {
  3108. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3110. return
  3111. } else if dialysisRecord != nil {
  3112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3113. return
  3114. }
  3115. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3116. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3117. timeLayout := "2006-01-02 15:04:05"
  3118. loc, _ := time.LoadLocation("Local")
  3119. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3120. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3121. schedulestartTime := theStartTime.Unix()
  3122. scheduleendTime := theEndTime.Unix()
  3123. var theNucleinDate int64
  3124. timeLayoutOne := "2006-01-02"
  3125. if len(nuclein_date_str) > 0 {
  3126. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3127. if err != nil {
  3128. utils.ErrorLog(err.Error())
  3129. }
  3130. theNucleinDate = theTime.Unix()
  3131. }
  3132. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3133. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3134. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3135. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3136. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3137. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3138. if record.ID == 0 {
  3139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3140. return
  3141. }
  3142. }
  3143. //查询该床位是否有人用了
  3144. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3145. if err == gorm.ErrRecordNotFound { //空床位
  3146. // 修改了床位逻辑
  3147. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3148. if daySchedule.ID > 0 {
  3149. daySchedule.PartitionId = deviceNumber.ZoneID
  3150. daySchedule.BedId = bedID
  3151. daySchedule.ScheduleType = schedual_type
  3152. daySchedule.UpdatedTime = time.Now().Unix()
  3153. xtSchedule := models.Schedule{
  3154. PartitionId: deviceNumber.ZoneID,
  3155. BedId: bedID,
  3156. ScheduleType: schedual_type,
  3157. UpdatedTime: time.Now().Unix(),
  3158. }
  3159. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3160. if err != nil {
  3161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3162. return
  3163. }
  3164. }
  3165. } else if err == nil {
  3166. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3167. if order.ID > 0 { //该机位被其他人占用了
  3168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3169. return
  3170. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3171. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3172. if daySchedule.ID > 0 {
  3173. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3174. if err != nil {
  3175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3176. return
  3177. }
  3178. }
  3179. }
  3180. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3182. return
  3183. }
  3184. //else if order.ID == 0 { //该床位没被占用
  3185. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3186. // if daySchedule.ID > 0 {
  3187. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3188. // //daySchedule.BedId = bedID
  3189. // //daySchedule.ScheduleType = schedual_type
  3190. // //daySchedule.UpdatedTime = time.Now().Unix()
  3191. // //err := service.UpdateSchedule(&daySchedule)
  3192. // xtSchedule := models.Schedule{
  3193. // PartitionId: deviceNumber.ZoneID,
  3194. // BedId: bedID,
  3195. // ScheduleType: schedual_type,
  3196. // UpdatedTime: time.Now().Unix(),
  3197. // }
  3198. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3199. // if err != nil {
  3200. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3201. // return
  3202. // }
  3203. // }
  3204. //}
  3205. //}
  3206. } else if err != nil {
  3207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3208. return
  3209. }
  3210. // 查询信息规挡的设置天数
  3211. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3212. if infor.ID > 0 && infor.WeekDay > 0 {
  3213. var cha_time int64
  3214. timeNowStr := time.Now().Format("2006-01-02")
  3215. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3216. //今日的日期减去设置的日期
  3217. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3218. if cha_time >= recordDate.Unix() {
  3219. //查询审核是否允许
  3220. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3221. //申请状态不允许的情况 拒绝修改
  3222. if infor.ApplicationStatus != 1 {
  3223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3224. return
  3225. }
  3226. }
  3227. }
  3228. dialysisRecord = &models.DialysisOrder{
  3229. DialysisDate: recordDate.Unix(),
  3230. UserOrgId: adminUserInfo.Org.Id,
  3231. PatientId: patientID,
  3232. Stage: 1,
  3233. BedID: bedID,
  3234. StartNurse: nurseID,
  3235. Status: 1,
  3236. StartTime: startDate.Unix(),
  3237. CreatedTime: time.Now().Unix(),
  3238. UpdatedTime: time.Now().Unix(),
  3239. PunctureNurse: puncture_nurse,
  3240. Creator: adminUserInfo.AdminUser.Id,
  3241. Modifier: adminUserInfo.AdminUser.Id,
  3242. SchedualType: schedual_type,
  3243. WashpipeNurse: washpipe_nurse,
  3244. ChangeNurse: change_nurse,
  3245. DifficultPunctureNurse: difficult_puncture_nurse,
  3246. NewFistulaNurse: new_fistula_nurse,
  3247. ZoneId: zone_id,
  3248. QualityNurseId: quality_nurse_id,
  3249. PunctureNeedle: puncture_needle,
  3250. PunctureWay: puncture_way,
  3251. DialysisIrrigation: dialysis_irrigation,
  3252. DialysisDialyszers: dialysis_dialyszers,
  3253. BloodAccessId: blood_access_id,
  3254. Url: elecsign,
  3255. NucleinDate: theNucleinDate,
  3256. ScheduleRemark: schedule_remark,
  3257. OrderRemark: order_remark,
  3258. CatheterOperation: catheter_operation,
  3259. BloodFlowVolume: blood_flow_volume,
  3260. BloodDrawing: blood_drawing,
  3261. DialysisStrainer: dialysis_strainer,
  3262. }
  3263. //查询该床位是否有人用了
  3264. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3265. if errorscode == gorm.ErrRecordNotFound {
  3266. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3267. finish := models.XtDialysisFinish{
  3268. IsFinish: 1,
  3269. UserOrgId: adminUserInfo.Org.Id,
  3270. Status: 1,
  3271. Ctime: time.Now().Unix(),
  3272. Mtime: 0,
  3273. Module: 6,
  3274. RecordDate: schedulestartTime,
  3275. Sourse: 1,
  3276. PatientId: patientID,
  3277. }
  3278. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3279. if dialysisFinish.ID == 0 {
  3280. service.CreateDialysisFinish(finish)
  3281. }
  3282. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3283. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3284. //统计该患者总次数
  3285. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3286. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3287. }
  3288. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3289. //统计该患者总次数
  3290. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3291. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3292. }
  3293. redis := service.RedisClient()
  3294. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3295. redis.Set(key, "", time.Second)
  3296. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3297. //清空key 值
  3298. redis.Set(keyOne, "", time.Second)
  3299. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3300. //清空key 值
  3301. redis.Set(keyTwo, "", time.Second)
  3302. if createErr != nil {
  3303. this.ErrorLog("上机失败:%v", createErr)
  3304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3305. return
  3306. }
  3307. }
  3308. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3309. var tempdispose string
  3310. // 只针对中能建
  3311. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3312. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3313. }
  3314. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3315. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3316. }
  3317. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3318. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3319. //}
  3320. var ultrafiltration_rate float64
  3321. var ultrafiltration_rate_one string
  3322. var replacement_rate float64
  3323. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3324. //后期预增脱水量
  3325. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3326. if prescription.ID > 0 {
  3327. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3328. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3329. 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
  3330. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3331. }
  3332. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 {
  3333. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3334. }
  3335. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3336. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3337. }
  3338. //针对医师汇
  3339. if adminUserInfo.Org.Id == 10121 {
  3340. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3341. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3342. }
  3343. //针对通道
  3344. if adminUserInfo.Org.Id == 10234 {
  3345. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3346. }
  3347. //针对监利大垸医院
  3348. if template.TemplateId == 41 {
  3349. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3350. }
  3351. //针对肇庆三鹤血液透析中心
  3352. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3353. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3354. }
  3355. if adminUserInfo.Org.Id == 10469 {
  3356. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3357. }
  3358. if adminUserInfo.Org.Id == 10667 {
  3359. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3360. }
  3361. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3362. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3363. }
  3364. // 只针对方济医院
  3365. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3366. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3367. ultrafiltration_rate = value
  3368. }
  3369. //针对
  3370. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3371. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3372. ultrafiltration_rate = ultrafiltration_rate / 1000
  3373. }
  3374. if adminUserInfo.Org.Id == 10551 {
  3375. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3376. ultrafiltration_rate = ultrafiltration_rate / 1000
  3377. }
  3378. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3379. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3380. ultrafiltration_rate = ultrafiltration_rate / 1000
  3381. }
  3382. if adminUserInfo.Org.Id == 10580 {
  3383. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3384. ultrafiltration_rate = ultrafiltration_rate / 1000
  3385. }
  3386. if adminUserInfo.Org.Id == 10629 {
  3387. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3388. ultrafiltration_rate = ultrafiltration_rate / 1000
  3389. }
  3390. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3392. ultrafiltration_rate = ultrafiltration_rate / 1000
  3393. }
  3394. if adminUserInfo.Org.Id == 10751 {
  3395. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3396. ultrafiltration_rate = ultrafiltration_rate / 1000
  3397. }
  3398. if adminUserInfo.Org.Id == 10667 {
  3399. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3400. ultrafiltration_rate = ultrafiltration_rate / 1000
  3401. }
  3402. if adminUserInfo.Org.Id == 10693 {
  3403. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3404. ultrafiltration_rate = ultrafiltration_rate
  3405. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3406. }
  3407. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3408. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3409. ultrafiltration_rate = ultrafiltration_rate
  3410. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3411. }
  3412. if adminUserInfo.Org.Id == 10206 {
  3413. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3414. ultrafiltration_rate = ultrafiltration_rate
  3415. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3416. }
  3417. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3418. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3419. ultrafiltration_rate = ultrafiltration_rate
  3420. }
  3421. if adminUserInfo.Org.Id == 10702 {
  3422. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3423. ultrafiltration_rate = ultrafiltration_rate / 1000
  3424. }
  3425. if adminUserInfo.Org.Id == 10752 {
  3426. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3427. ultrafiltration_rate = ultrafiltration_rate / 1000
  3428. }
  3429. if adminUserInfo.Org.Id == 10723 {
  3430. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3431. ultrafiltration_rate = ultrafiltration_rate / 1000
  3432. }
  3433. if adminUserInfo.Org.Id == 10721 {
  3434. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3435. ultrafiltration_rate = ultrafiltration_rate / 1000
  3436. }
  3437. if adminUserInfo.Org.Id == 10721 {
  3438. if prescription.ModeId == 2 {
  3439. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3440. if totalMin == 0 {
  3441. totalMin = 240
  3442. }
  3443. if prescription.ReplacementTotal == 0 {
  3444. prescription.ReplacementTotal = 15
  3445. }
  3446. //乘10 除10是为了保留一位小数
  3447. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3448. }
  3449. }
  3450. fmt.Println("hhhhhhhhhhhhhhhhhhhhhhhh", adminUserInfo.Org.Id)
  3451. if adminUserInfo.Org.Id == 10752 {
  3452. if prescription.ModeId == 2 {
  3453. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3454. if totalMin == 0 {
  3455. totalMin = 240
  3456. }
  3457. if prescription.ReplacementTotal == 0 {
  3458. prescription.ReplacementTotal = 15
  3459. }
  3460. //乘10 除10是为了保留一位小数
  3461. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3462. fmt.Println("hhhhhhhhhhhhhhhhhhhhh", replacement_rate)
  3463. }
  3464. }
  3465. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3466. if prescription.ModeId == 2 {
  3467. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3468. if totalMin == 0 {
  3469. totalMin = 240
  3470. }
  3471. if prescription.DisplaceLiquiValue == 0 {
  3472. prescription.ReplacementTotal = 32
  3473. }
  3474. //乘10 除10是为了保留一位小数
  3475. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3476. }
  3477. }
  3478. }
  3479. }
  3480. if adminUserInfo.Org.Id == 10172 {
  3481. if prescription.ID == 0 {
  3482. if prescription.ModeId == 2 {
  3483. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3484. if totalMin == 0 {
  3485. totalMin = 240
  3486. }
  3487. if prescription.ReplacementTotal == 0 {
  3488. prescription.ReplacementTotal = 15
  3489. }
  3490. //乘10 除10是为了保留一位小数
  3491. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3492. }
  3493. }
  3494. }
  3495. record := models.MonitoringRecord{
  3496. UserOrgId: adminUserInfo.Org.Id,
  3497. PatientId: patientID,
  3498. DialysisOrderId: dialysisRecord.ID,
  3499. MonitoringDate: schedulestartTime,
  3500. OperateTime: startDate.Unix(),
  3501. // MonitoringTime: recordTime,
  3502. MonitoringNurse: nurseID,
  3503. Dispose: tempdispose,
  3504. UltrafiltrationRate: ultrafiltration_rate,
  3505. UltrafiltrationVolume: 0,
  3506. Status: 1,
  3507. CreatedTime: time.Now().Unix(),
  3508. UpdatedTime: time.Now().Unix(),
  3509. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3510. ReplacementRate: replacement_rate,
  3511. }
  3512. //只针对广慈医院
  3513. 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 || adminUserInfo.Org.Id == 10742 {
  3514. // 查询病人是否有透前评估数据
  3515. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3516. //如果有数据就插入
  3517. if errcode == nil {
  3518. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3519. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3520. record.BreathingRate = befor.BreathingRate
  3521. record.PulseFrequency = befor.PulseFrequency
  3522. record.Temperature = befor.Temperature
  3523. }
  3524. }
  3525. //孝昌
  3526. if adminUserInfo.Org.Id == 10693 {
  3527. // 查询病人是否有透前评估数据
  3528. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3529. //如果有数据就插入
  3530. if errcode == nil {
  3531. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3532. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3533. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3534. record.BreathingRate = befor.BreathingRate
  3535. }
  3536. }
  3537. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3538. if newdialysisRecord.ID > 0 {
  3539. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3540. record.Temperature = 36.5
  3541. record.ArterialPressure = -100
  3542. record.DialysateTemperature = 36.5
  3543. record.Conductivity = 14
  3544. record.BreathingRate = "20"
  3545. record.VenousPressure = 80
  3546. record.TransmembranePressure = 60
  3547. record.Dispose = catheter_operation
  3548. }
  3549. //针对新化博翔
  3550. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3551. record.BloodOxygenSaturation = "99"
  3552. record.Conductivity = 14
  3553. record.DialysateTemperature = 36.5
  3554. record.BreathingRate = "20"
  3555. }
  3556. //针对兰溪人民医院的需求
  3557. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3558. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3559. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3560. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3561. record.Temperature = befor.Temperature
  3562. record.PulseFrequency = befor.PulseFrequency
  3563. record.BreathingRate = befor.BreathingRate
  3564. }
  3565. //针对乐山友谊医院的需求
  3566. if adminUserInfo.Org.Id == 10677 {
  3567. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3568. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3569. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3570. record.Temperature = befor.Temperature
  3571. record.PulseFrequency = befor.PulseFrequency
  3572. record.BreathingRate = befor.BreathingRate
  3573. }
  3574. //新化博翔
  3575. if adminUserInfo.Org.Id == 10447 {
  3576. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3577. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3578. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3579. record.BreathingRate = befor.BreathingRate
  3580. }
  3581. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3582. record.PulseFrequency = 80
  3583. record.Temperature = 36.5
  3584. }
  3585. //诊断灵山圣康
  3586. if adminUserInfo.Org.Id == 10375 {
  3587. record.Conductivity = 13.8
  3588. record.DialysateTemperature = 37
  3589. record.DialysateFlow = 500
  3590. record.BloodFlowVolume = 200
  3591. record.BreathingRate = "18"
  3592. record.SodiumConcentration = 140
  3593. }
  3594. //江成肾病医院
  3595. if adminUserInfo.Org.Id == 10517 {
  3596. record.SodiumConcentration = 138
  3597. record.DialysateTemperature = 36.5
  3598. }
  3599. //濉溪杏康血液透析中心
  3600. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3601. record.BloodFlowVolume = prescription.BloodFlowVolume
  3602. }
  3603. //胶州少海医院
  3604. if adminUserInfo.Org.Id == 10735 {
  3605. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3606. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3607. record.BreathingRate = befor.BreathingRate
  3608. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3609. record.Temperature = befor.Temperature
  3610. record.PulseFrequency = befor.PulseFrequency
  3611. }
  3612. if adminUserInfo.Org.Id != 10683 {
  3613. err = service.CreateMonitor(&record)
  3614. }
  3615. //记录日志
  3616. byterequest, _ := json.Marshal(record)
  3617. monitorRecordLog := models.XtMonitorRecordLog{
  3618. RecordDate: record.MonitoringDate,
  3619. PatientId: record.PatientId,
  3620. Module: 1,
  3621. AdminUserId: adminUserInfo.AdminUser.Id,
  3622. Ctime: time.Now().Unix(),
  3623. Mtime: 0,
  3624. Status: 1,
  3625. UserOrgId: record.UserOrgId,
  3626. ErrLog: string(byterequest),
  3627. Source: "执行上机时新增监测",
  3628. }
  3629. service.CreateMonitorRecordLog(monitorRecordLog)
  3630. finish := models.XtDialysisFinish{
  3631. IsFinish: 1,
  3632. UserOrgId: adminUserInfo.Org.Id,
  3633. Status: 1,
  3634. Ctime: time.Now().Unix(),
  3635. Mtime: 0,
  3636. Module: 7,
  3637. RecordDate: schedulestartTime,
  3638. Sourse: 1,
  3639. PatientId: patientID,
  3640. }
  3641. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3642. if dialysisFinish.ID == 0 {
  3643. service.CreateDialysisFinish(finish)
  3644. }
  3645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3646. redis := service.RedisClient()
  3647. //清空key 值
  3648. redis.Set(key, "", time.Second)
  3649. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3650. redis.Set(keyOne, "", time.Second)
  3651. defer redis.Close()
  3652. if err != nil {
  3653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3654. return
  3655. }
  3656. }
  3657. go func() {
  3658. ssoDomain := beego.AppConfig.String("call_domain")
  3659. api := ssoDomain + "/index/uppatient"
  3660. values := make(url.Values)
  3661. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3662. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3663. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3664. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3665. http.PostForm(api, values)
  3666. }()
  3667. this.ServeSuccessJSON(map[string]interface{}{
  3668. "dialysis_order": newdialysisRecord,
  3669. "monitor": record,
  3670. })
  3671. return
  3672. }
  3673. func (c *DialysisAPIController) PostSolution() {
  3674. id, _ := c.GetInt64("patient", 0)
  3675. recordDateStr := c.GetString("record_date")
  3676. if id <= 0 {
  3677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3678. return
  3679. }
  3680. adminUserInfo := c.GetMobileAdminUserInfo()
  3681. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3682. if patient.ID == 0 {
  3683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3684. return
  3685. }
  3686. if len(recordDateStr) == 0 {
  3687. recordDateStr = time.Now().Format("2006-01-02")
  3688. }
  3689. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3690. if parseDateErr != nil {
  3691. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3693. return
  3694. }
  3695. mode_id, _ := c.GetInt64("mode_id", 0)
  3696. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3697. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3698. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3699. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3700. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3701. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3702. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3703. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3704. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3705. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3706. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3707. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3708. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3709. kalium, _ := c.GetFloat("kalium", 0)
  3710. sodium, _ := c.GetFloat("sodium", 0)
  3711. calcium, _ := c.GetFloat("calcium", 0)
  3712. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3713. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3714. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3715. glucose, _ := c.GetFloat("glucose", 0)
  3716. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3717. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3718. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3719. conductivity, _ := c.GetFloat("conductivity", 0)
  3720. remark := c.GetString("remark")
  3721. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3722. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3723. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3724. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3725. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3726. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3727. special_medicine_other := c.GetString("special_medicine_other")
  3728. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3729. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3730. blood_access, _ := c.GetInt64("blood_access", 0)
  3731. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3732. body_fluid_other := c.GetString("body_fluid_other")
  3733. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3734. niprocart, _ := c.GetInt64("niprocart", 0)
  3735. jms, _ := c.GetInt64("jms", 0)
  3736. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3737. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3738. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3739. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3740. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3741. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3742. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3743. injector, _ := c.GetInt64("injector", 0)
  3744. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3745. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3746. safe_package, _ := c.GetInt64("package", 0)
  3747. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3748. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3749. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3750. blood := c.GetString("blood")
  3751. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3752. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3753. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3754. displace_speed := c.GetString("displace_speed")
  3755. illness, _ := c.GetInt64("illness")
  3756. amylaceum := c.GetString("amylaceum")
  3757. single_time := c.GetString("single_time")
  3758. single_water := c.GetString("single_water")
  3759. replacement_flow := c.GetString("replacement_flow")
  3760. plasma_separator := c.GetString("plasma_separator")
  3761. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3762. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3763. oxygen_flow := c.GetString("oxygen_flow")
  3764. oxygen_time := c.GetString("oxygen_time")
  3765. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3766. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3767. puncture_needle := c.GetString("puncture_needle")
  3768. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3769. epo := c.GetString("epo")
  3770. epo_count, _ := c.GetFloat("epo_count", 0)
  3771. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3772. pre_impulse := c.GetString("pre_impulse")
  3773. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3774. admin_user_id, _ := c.GetInt64("admin_user_id")
  3775. is_water := c.GetString("is_water")
  3776. add_amount, _ := c.GetFloat("add_amount")
  3777. reduce_amount, _ := c.GetFloat("reduce_amount")
  3778. prescribing_number, _ := c.GetFloat("prescribing_number")
  3779. treatment_remark := c.GetString("treatment_remark")
  3780. prescription_sodium := c.GetString("prescription_sodium")
  3781. start_sodium := c.GetString("start_sodium")
  3782. sodium_curve := c.GetString("sodium_curve")
  3783. var is_war int64
  3784. if is_water == "是" {
  3785. is_war = 1
  3786. }
  3787. if is_water == "否" {
  3788. is_war = 2
  3789. }
  3790. if is_water == "请选择" {
  3791. is_war = 0
  3792. }
  3793. drhy_water := c.GetString("drhy_water")
  3794. dry_water_hour := c.GetString("dry_water_hour")
  3795. water_machine := c.GetString("water_machine")
  3796. dialysis_remark := c.GetString("dialysis_remark")
  3797. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3798. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3799. prescription_water, _ := c.GetFloat("prescription_water")
  3800. dialysis_strainer := c.GetString("dialysis_strainer")
  3801. chaptalization := c.GetString("chaptalization")
  3802. washing_time := c.GetString("washing_time")
  3803. warsh_count := c.GetString("warsh_count")
  3804. blood_access_part_id := c.GetString("blood_access_part_id")
  3805. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3806. dialyzate := c.GetString("dialyzate")
  3807. first_super := c.GetString("first_super")
  3808. is_sequential := c.GetString("is_sequential")
  3809. var fisrt_sup int64
  3810. if first_super == "是" {
  3811. fisrt_sup = 1
  3812. }
  3813. if first_super == "否" {
  3814. fisrt_sup = 2
  3815. }
  3816. if first_super == "请选择" {
  3817. fisrt_sup = 0
  3818. }
  3819. var is_sequen int64
  3820. if is_sequential == "是" {
  3821. is_sequen = 1
  3822. }
  3823. if is_sequential == "否" {
  3824. is_sequen = 2
  3825. }
  3826. if is_sequential == "请选择" {
  3827. is_sequen = 0
  3828. }
  3829. conduct := c.GetString("conduct")
  3830. if mode_id > 0 {
  3831. var str string
  3832. //查找该机构用的是什么透析器
  3833. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3834. if filedConfig.ID > 0 {
  3835. str = dialyzerPerfusionApparatus
  3836. } else {
  3837. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3838. }
  3839. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3840. }
  3841. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3842. //
  3843. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3844. // if appRole.UserType == 3 {
  3845. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3846. // if getPermissionErr != nil {
  3847. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3848. // return
  3849. // } else if headNursePermission == nil {
  3850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3851. // return
  3852. // }
  3853. // }
  3854. //}
  3855. // 查询信息规挡的设置天数
  3856. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3857. if infor.ID > 0 && infor.WeekDay > 0 {
  3858. var cha_time int64
  3859. timeNowStr := time.Now().Format("2006-01-02")
  3860. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3861. //今日的日期减去设置的日期
  3862. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3863. if cha_time >= recordDate.Unix() {
  3864. //查询审核是否允许
  3865. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3866. //申请状态不允许的情况 拒绝修改
  3867. if infor.ApplicationStatus != 1 {
  3868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3869. return
  3870. }
  3871. }
  3872. }
  3873. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3874. var dialysis_dialyszers_id int64
  3875. var dialysis_strainer_id int64
  3876. var dialysis_irrigation_id int64
  3877. if len(goodList) > 0 {
  3878. for _, item := range goodList {
  3879. if item.SpecificationName == dialysis_dialyszers {
  3880. dialysis_dialyszers_id = item.ID
  3881. }
  3882. if item.SpecificationName == dialysis_irrigation {
  3883. dialysis_irrigation_id = item.ID
  3884. }
  3885. if item.SpecificationName == dialysis_strainer {
  3886. dialysis_strainer_id = item.ID
  3887. }
  3888. }
  3889. }
  3890. prescription := models.DialysisPrescription{
  3891. UserOrgId: adminUserInfo.Org.Id,
  3892. PatientId: id,
  3893. RecordDate: recordDate.Unix(),
  3894. ModeId: mode_id,
  3895. DialysisDuration: dialysis_duration,
  3896. Dialyzer: dialyzer,
  3897. PerfusionApparatus: perfusion_apparatus,
  3898. BloodFlowVolume: blood_flow_volume,
  3899. DewaterAmount: dewater_amount,
  3900. DisplaceLiqui: displace_liqui,
  3901. ReplacementWay: replacement_way,
  3902. Anticoagulant: anticoagulant,
  3903. AnticoagulantShouji: anticoagulant_shouji,
  3904. AnticoagulantWeichi: anticoagulant_weichi,
  3905. AnticoagulantZongliang: anticoagulant_zongliang,
  3906. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3907. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3908. Kalium: kalium,
  3909. Sodium: sodium,
  3910. Calcium: calcium,
  3911. Bicarbonate: bicarbonate,
  3912. Glucose: glucose,
  3913. // DryWeight: dry_weight,
  3914. DialysateFlow: dialysate_flow,
  3915. DialysateTemperature: dialysate_temperature,
  3916. Conductivity: conductivity,
  3917. Remark: remark,
  3918. Status: 1,
  3919. CreatedTime: time.Now().Unix(),
  3920. UpdatedTime: time.Now().Unix(),
  3921. DialysisDurationMinute: dialysisDurationMinute,
  3922. DialysisDurationHour: dialysisDurationHour,
  3923. TargetUltrafiltration: targetUltrafiltration,
  3924. DialysateFormulation: dialysateFormulation,
  3925. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3926. BodyFluid: body_fluid,
  3927. SpecialMedicine: special_medicine,
  3928. SpecialMedicineOther: special_medicine_other,
  3929. DisplaceLiquiPart: displace_liqui_part,
  3930. DisplaceLiquiValue: displace_liqui_value,
  3931. BloodAccess: blood_access,
  3932. Ultrafiltration: ultrafiltration,
  3933. BodyFluidOther: body_fluid_other,
  3934. ReplacementTotal: replacement_total,
  3935. Niprocart: niprocart,
  3936. Jms: jms,
  3937. FistulaNeedleSet: fistula_needle_set,
  3938. FistulaNeedleSet16: fistula_needle_set_16,
  3939. Hemoperfusion: hemoperfusion,
  3940. DialyserSterilised: dialyser_sterilised,
  3941. Filtryzer: filtryzer,
  3942. TargetKtv: target_ktv,
  3943. Dialyzers: dialyzers,
  3944. Injector: injector,
  3945. Bloodlines: bloodlines,
  3946. TubingHemodialysis: tubing_hemodialysis,
  3947. Package: safe_package,
  3948. ALiquid: a_liquid,
  3949. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3950. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3951. Blood: blood,
  3952. DialysisDialyszers: dialysis_dialyszers,
  3953. DialysisIrrigation: dialysis_irrigation,
  3954. AntioxidantCommodityName: antioxidant_commodity_name,
  3955. DisplaceSpeed: displace_speed,
  3956. Illness: illness,
  3957. Amylaceum: amylaceum,
  3958. SingleWater: single_water,
  3959. SingleTime: single_time,
  3960. ReplacementFlow: replacement_flow,
  3961. PlasmaSeparator: plasma_separator,
  3962. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3963. OxygenUptake: oxygen_uptake,
  3964. OxygenTime: oxygen_time,
  3965. OxygenFlow: oxygen_flow,
  3966. HemodialysisPipelines: hemodialysis_pipelines,
  3967. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3968. PunctureNeedle: puncture_needle,
  3969. PunctureNeedleCount: puncture_needle_count,
  3970. Epo: epo,
  3971. EpoCount: epo_count,
  3972. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3973. PreImpulse: impulse,
  3974. AdminUserId: admin_user_id,
  3975. IsWater: is_war,
  3976. DrhyWater: drhy_water,
  3977. DryWaterHour: dry_water_hour,
  3978. WaterMachine: water_machine,
  3979. AddAmount: add_amount,
  3980. ReduceAmount: reduce_amount,
  3981. DialysisRemark: dialysis_remark,
  3982. PrescribingNumber: prescribing_number,
  3983. PrescriptionSodium: prescription_sodium,
  3984. StartSodium: start_sodium,
  3985. SodiumCurve: sodium_curve,
  3986. TreatmentRemark: treatment_remark,
  3987. DialysisFluidFlow: dialysis_fluid_flow,
  3988. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3989. PrescriptionWater: prescription_water,
  3990. DialysisStrainer: dialysis_strainer,
  3991. Chaptalization: chaptalization,
  3992. WashingTime: washing_time,
  3993. WarshCount: warsh_count,
  3994. BloodAccessPartId: blood_access_part_id,
  3995. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3996. Dialyzate: dialyzate,
  3997. DialysisDialyszersId: dialysis_dialyszers_id,
  3998. DialysisIrrigationId: dialysis_irrigation_id,
  3999. DialysisStrainerId: dialysis_strainer_id,
  4000. FirstSuper: fisrt_sup,
  4001. IsSequential: is_sequen,
  4002. Conduct: conduct,
  4003. }
  4004. if adminUserInfo.Org.Id == 10721 {
  4005. if prescription.ModeId == 2 {
  4006. if prescription.ReplacementTotal == 0 {
  4007. prescription.ReplacementTotal = 15
  4008. }
  4009. }
  4010. }
  4011. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4012. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4013. //
  4014. if appRole.UserType == 2 || appRole.UserType == 1 {
  4015. prescription_doctor = adminUserInfo.AdminUser.Id
  4016. prescription.PrescriptionDoctor = prescription_doctor
  4017. }
  4018. if dialysisPrescription.ID == 0 { //新增
  4019. prescription.Creater = adminUserInfo.AdminUser.Id
  4020. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4021. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4022. }
  4023. } else { //修改
  4024. if dialysisPrescription.Creater == 0 {
  4025. prescription.Creater = adminUserInfo.AdminUser.Id
  4026. } else {
  4027. prescription.Creater = dialysisPrescription.Creater
  4028. if adminUserInfo.Org.Id == 9882 {
  4029. if appRole.UserType == 2 || appRole.UserType == 1 {
  4030. prescription.Creater = adminUserInfo.AdminUser.Id
  4031. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4032. }
  4033. }
  4034. }
  4035. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4036. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4037. }
  4038. //if/**/
  4039. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4040. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4041. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4042. // if getPermissionErr != nil {
  4043. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4044. // return
  4045. // } else if headNursePermission == nil {
  4046. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4047. // return
  4048. // }
  4049. //}
  4050. //prescription.Creater = dialysisPrescription.Creater
  4051. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4052. prescription.Modifier = adminUserInfo.AdminUser.Id
  4053. prescription.ID = dialysisPrescription.ID
  4054. }
  4055. solution := models.DialysisSolution{
  4056. RegistrarsId: adminUserInfo.AdminUser.Id,
  4057. UserOrgId: adminUserInfo.Org.Id,
  4058. Doctor: prescription_doctor,
  4059. PatientId: id,
  4060. ModeId: mode_id,
  4061. DialysisDuration: dialysis_duration,
  4062. PerfusionApparatus: perfusion_apparatus,
  4063. BloodFlowVolume: blood_flow_volume,
  4064. Dewater: dewater_amount,
  4065. DisplaceLiqui: displace_liqui,
  4066. ReplacementWay: replacement_way,
  4067. Anticoagulant: anticoagulant,
  4068. AnticoagulantShouji: anticoagulant_shouji,
  4069. AnticoagulantWeichi: anticoagulant_weichi,
  4070. AnticoagulantZongliang: anticoagulant_zongliang,
  4071. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4072. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4073. Kalium: kalium,
  4074. Sodium: sodium,
  4075. Calcium: calcium,
  4076. Bicarbonate: bicarbonate,
  4077. Glucose: glucose,
  4078. // DryWeight: dry_weight,
  4079. DialysateFlow: dialysate_flow,
  4080. DialysateTemperature: dialysate_temperature,
  4081. Conductivity: conductivity,
  4082. Remark: remark,
  4083. Status: 1,
  4084. CreatedTime: time.Now().Unix(),
  4085. UpdatedTime: time.Now().Unix(),
  4086. DialysisDurationMinute: dialysisDurationMinute,
  4087. DialysisDurationHour: dialysisDurationHour,
  4088. TargetUltrafiltration: targetUltrafiltration,
  4089. DialysateFormulation: dialysateFormulation,
  4090. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4091. BodyFluid: body_fluid,
  4092. SpecialMedicine: special_medicine,
  4093. SpecialMedicineOther: special_medicine_other,
  4094. DisplaceLiquiPart: displace_liqui_part,
  4095. DisplaceLiquiValue: displace_liqui_value,
  4096. BloodAccess: blood_access,
  4097. Ultrafiltration: ultrafiltration,
  4098. BodyFluidOther: body_fluid_other,
  4099. ReplacementTotal: replacement_total,
  4100. TargetKtv: target_ktv,
  4101. DialysisDialyszers: dialysis_dialyszers,
  4102. DialysisIrrigation: dialysis_irrigation,
  4103. HemodialysisPipelines: hemodialysis_pipelines,
  4104. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4105. PunctureNeedle: puncture_needle,
  4106. PunctureNeedleCount: puncture_needle_count,
  4107. Epo: epo,
  4108. EpoCount: epo_count,
  4109. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4110. PreImpulse: impulse,
  4111. SolutionStatus: 1,
  4112. DialysisRemark: dialysis_remark,
  4113. PrescribingNumber: prescribing_number,
  4114. PrescriptionSodium: prescription_sodium,
  4115. StartSodium: start_sodium,
  4116. SodiumCurve: sodium_curve,
  4117. TreatmentRemark: treatment_remark,
  4118. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4119. DialysisFluidFlow: dialysis_fluid_flow,
  4120. PrescriptionWater: prescription_water,
  4121. DialysisStrainer: dialysis_strainer,
  4122. Chaptalization: chaptalization,
  4123. WashingTime: washing_time,
  4124. WarshCount: warsh_count,
  4125. BloodAccessPartId: blood_access_part_id,
  4126. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4127. Dialyzate: dialyzate,
  4128. DialysisDialyszersId: dialysis_dialyszers_id,
  4129. DialysisIrrigationId: dialysis_irrigation_id,
  4130. DialysisStrainerId: dialysis_strainer_id,
  4131. FirstSuper: fisrt_sup,
  4132. IsSequential: is_sequen,
  4133. Conduct: conduct,
  4134. }
  4135. //针对河间咸的
  4136. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4137. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4138. solution.DisplaceLiquiPart = 0
  4139. solution.DisplaceLiquiValue = 0
  4140. }
  4141. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4142. prescription.DisplaceLiquiPart = 0
  4143. prescription.DisplaceLiquiValue = 0
  4144. }
  4145. }
  4146. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4147. if solution.PrescribingNumber == 0 {
  4148. solution.PrescribingNumber = 1
  4149. }
  4150. if prescription.PrescribingNumber == 0 {
  4151. prescription.PrescribingNumber = 1
  4152. }
  4153. if solution.PrescribingNumber == 0 && id == 14682 {
  4154. solution.PrescribingNumber = 2
  4155. }
  4156. if solution.PrescribingNumber == 0 && id == 18560 {
  4157. solution.PrescribingNumber = 2
  4158. }
  4159. if prescription.PrescribingNumber == 0 && id == 14682 {
  4160. prescription.PrescribingNumber = 2
  4161. }
  4162. if prescription.PrescribingNumber == 0 && id == 18560 {
  4163. prescription.PrescribingNumber = 2
  4164. }
  4165. }
  4166. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4167. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4168. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4169. if len(monitorList) > 0 {
  4170. var ultrafiltration_rate float64
  4171. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4172. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4173. var replacement_rate float64
  4174. //乘10 除10是为了保留一位小数
  4175. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4176. var firstOpeateTime = monitorList[0].OperateTime
  4177. for _, item := range monitorList {
  4178. //超滤率
  4179. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4180. //置换率
  4181. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4182. //超滤量
  4183. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4184. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4185. //置换量
  4186. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4187. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4188. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4189. }
  4190. }
  4191. }
  4192. //记录日志
  4193. byterequest, _ := json.Marshal(prescription)
  4194. prescriptionLog := models.XtDialysisPrescriptionLog{
  4195. UserOrgId: prescription.UserOrgId,
  4196. Ctime: time.Now().Unix(),
  4197. Mtime: 0,
  4198. ErrLog: string(byterequest),
  4199. AdminUserId: adminUserInfo.AdminUser.Id,
  4200. RecordDate: prescription.RecordDate,
  4201. PatientId: prescription.PatientId,
  4202. Source: "手机端新增长期处方",
  4203. Status: 1,
  4204. }
  4205. service.CreatePrescriptionLog(prescriptionLog)
  4206. finish := models.XtDialysisFinish{
  4207. IsFinish: 1,
  4208. UserOrgId: adminUserInfo.Org.Id,
  4209. Status: 1,
  4210. Ctime: time.Now().Unix(),
  4211. Mtime: 0,
  4212. Module: 1,
  4213. RecordDate: recordDate.Unix(),
  4214. Sourse: 1,
  4215. PatientId: id,
  4216. }
  4217. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4218. if dialysisFinish.ID == 0 {
  4219. service.CreateDialysisFinish(finish)
  4220. }
  4221. //获取最新1条
  4222. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4223. //更新状态
  4224. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4225. //长沙南雅医院,自动生成抗凝剂的临时处方
  4226. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4227. if prescribing_number == 0 {
  4228. prescribing_number = 1
  4229. }
  4230. advice := models.DoctorAdvice{
  4231. UserOrgId: adminUserInfo.Org.Id,
  4232. PatientId: id,
  4233. GroupNo: 0,
  4234. AdviceType: 2,
  4235. RecordDate: recordDate.Unix(),
  4236. AdviceDate: recordDate.Unix(),
  4237. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4238. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4239. AdviceDesc: "",
  4240. ReminderDate: 0,
  4241. SingleDose: prescription.AnticoagulantZongliang,
  4242. SingleDoseUnit: "iu",
  4243. DrugSpec: 0,
  4244. DrugSpecUnit: "",
  4245. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4246. PrescribingNumberUnit: "支",
  4247. DeliveryWay: "静脉注射",
  4248. ExecutionFrequency: "上机前",
  4249. AdviceDoctor: 0,
  4250. Status: 1,
  4251. CreatedTime: time.Now().Unix(),
  4252. UpdatedTime: time.Now().Unix(),
  4253. IsPrescription: 1,
  4254. ExecutionState: 2,
  4255. StopState: 2,
  4256. IsSettle: 2,
  4257. }
  4258. // 查询排班信息
  4259. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4260. if schedulePatient.ID > 0 {
  4261. if schedulePatient.ScheduleType == 1 {
  4262. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4263. }
  4264. if schedulePatient.ScheduleType == 2 {
  4265. advice.StartTime = recordDate.Unix() + 9*60*60
  4266. }
  4267. }
  4268. // 抗凝剂名称
  4269. switch anticoagulant {
  4270. case 1:
  4271. advice.AdviceName = "无肝素"
  4272. break
  4273. case 2:
  4274. advice.AdviceName = "普通肝素"
  4275. break
  4276. case 3:
  4277. advice.AdviceName = "低分子肝素"
  4278. break
  4279. case 4:
  4280. advice.AdviceName = "阿加曲班"
  4281. break
  4282. case 5:
  4283. advice.AdviceName = "枸橼酸钠"
  4284. break
  4285. case 6:
  4286. advice.AdviceName = "低分子肝素钙"
  4287. break
  4288. case 7:
  4289. advice.AdviceName = "低分子肝素钠"
  4290. break
  4291. case 8:
  4292. advice.AdviceName = "依诺肝素"
  4293. break
  4294. case 9:
  4295. advice.AdviceName = "达肝素"
  4296. break
  4297. case 10:
  4298. advice.AdviceName = "体外抗凝"
  4299. break
  4300. case 11:
  4301. advice.AdviceName = "那曲肝素"
  4302. break
  4303. case 12:
  4304. advice.AdviceName = "无抗凝剂"
  4305. break
  4306. }
  4307. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4308. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4309. advice.AdviceDoctor = appRole.AdminUserId
  4310. }
  4311. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4312. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4313. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4314. advice.AdviceName = "低分子肝素钠注射液"
  4315. // 修改患者临时医嘱里的抗凝剂医嘱
  4316. advice.ID = advicePrescription.ID
  4317. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4318. } else {
  4319. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4320. advice.AdviceName = "低分子肝素钠注射液"
  4321. service.CreateDoctorAdvice(&advice)
  4322. }
  4323. }
  4324. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4325. redis := service.RedisClient()
  4326. defer redis.Close()
  4327. //清空key 值
  4328. redis.Set(key, "", time.Second)
  4329. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4330. redis.Set(keyOne, "", time.Second)
  4331. }
  4332. //获取key,清空redis
  4333. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4334. redis := service.RedisClient()
  4335. defer redis.Close()
  4336. //清空key 值
  4337. redis.Set(key, "", time.Second)
  4338. //清空长期医嘱的key
  4339. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4340. redis.Set(soulution_key, "", time.Second)
  4341. //查询最近透析准备表里是否存在 透析器 灌流器
  4342. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4343. redis.Set(keyOne, "", time.Second)
  4344. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4345. redis.Set(keyTwo, "", time.Second)
  4346. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4347. redis.Set(keyThree, "", time.Second)
  4348. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4349. redis.Set(keyFour, "", time.Second)
  4350. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4351. //
  4352. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4353. //
  4354. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4355. //if len(mation)>0{
  4356. // for _, item := range splitStr {
  4357. // for _,it := range mation{
  4358. // if(item == it.SpecificationName){
  4359. //
  4360. // //查询最近一次的透析器
  4361. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4362. //
  4363. // if errcode == gorm.ErrRecordNotFound{
  4364. // //插入数据
  4365. // prepare := models.DialysisBeforePrepare{
  4366. // UserOrgId: adminUserInfo.Org.Id,
  4367. // PatientId: id,
  4368. // RecordDate: recordDate.Unix(),
  4369. // GoodTypeId: it.GoodTypeId,
  4370. // GoodId: it.ID,
  4371. // Count: 1,
  4372. // Ctime: time.Now().Unix(),
  4373. // Creater: adminUserInfo.AdminUser.Id,
  4374. // Status:1,
  4375. //
  4376. // }
  4377. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4378. // fmt.Println("",errcode)
  4379. // }
  4380. // }
  4381. // }
  4382. //
  4383. // }
  4384. //
  4385. // for _, item := range splitIrrigation {
  4386. // for _,it := range mation{
  4387. // if(item == it.SpecificationName){
  4388. // //查询最近一次的透析器
  4389. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4390. // if errcode == gorm.ErrRecordNotFound{
  4391. // //插入数据
  4392. // prepare := models.DialysisBeforePrepare{
  4393. // UserOrgId: adminUserInfo.Org.Id,
  4394. // PatientId: id,
  4395. // RecordDate: recordDate.Unix(),
  4396. // GoodTypeId: it.GoodTypeId,
  4397. // GoodId: it.ID,
  4398. // Count: 1,
  4399. // Ctime: time.Now().Unix(),
  4400. // Creater: adminUserInfo.AdminUser.Id,
  4401. // Status:1,
  4402. //
  4403. // }
  4404. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4405. // fmt.Println(errcode)
  4406. // }
  4407. // }
  4408. // }
  4409. // }
  4410. //}
  4411. c.ServeSuccessJSON(map[string]interface{}{
  4412. "solution": &solution,
  4413. "prescription": &prescription,
  4414. })
  4415. }
  4416. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4417. patient, _ := c.GetInt64("patient", 0)
  4418. adminUserInfo := c.GetMobileAdminUserInfo()
  4419. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4420. c.ServeSuccessJSON(map[string]interface{}{
  4421. "receiveTreatmentAsses": receiveTreatmentAsses,
  4422. })
  4423. }
  4424. func (this *DialysisAPIController) PostSignInfo() {
  4425. patientID, _ := this.GetInt64("patient_id")
  4426. recordDateStr := this.GetString("date")
  4427. if patientID <= 0 {
  4428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4429. return
  4430. }
  4431. if len(recordDateStr) == 0 {
  4432. recordDateStr = time.Now().Format("2006-01-02")
  4433. }
  4434. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4435. if parseDateErr != nil {
  4436. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4438. return
  4439. }
  4440. adminInfo := this.GetMobileAdminUserInfo()
  4441. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4442. if err != nil {
  4443. this.ErrorLog("签名失败:%v", err)
  4444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4445. return
  4446. }
  4447. this.ServeSuccessJSON(map[string]interface{}{
  4448. "doctor_id": adminInfo.AdminUser.Id,
  4449. })
  4450. }
  4451. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4452. patientID, _ := this.GetInt64("patient_id")
  4453. adminInfo := this.GetMobileAdminUserInfo()
  4454. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4455. this.ServeSuccessJSON(map[string]interface{}{
  4456. "monitor": record,
  4457. })
  4458. }
  4459. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4460. thisTime := time.Now()
  4461. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4462. timeLayout := "2006-01-02 15:04:05"
  4463. loc, _ := time.LoadLocation("Local")
  4464. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4465. theAssessmentDateTime := theStartTime.Unix()
  4466. patientID, _ := this.GetInt64("patient_id")
  4467. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4468. adminInfo := this.GetMobileAdminUserInfo()
  4469. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4470. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4471. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4472. var ultrafiltration_rate float64
  4473. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4474. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4475. fmt.Println(evaluation)
  4476. fmt.Println("prescription.ID", prescription.ID)
  4477. if prescription.ID > 0 {
  4478. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4479. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4480. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4481. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4482. record.UltrafiltrationRate = ultrafiltration_rate
  4483. }
  4484. //重庆塘坝卫生院
  4485. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 {
  4486. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4487. record.UltrafiltrationRate = ultrafiltration_rate
  4488. }
  4489. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4490. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4491. record.UltrafiltrationRate = ultrafiltration_rate
  4492. }
  4493. if adminInfo.Org.Id == 10510 {
  4494. record.UltrafiltrationRate = 0
  4495. }
  4496. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4497. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4498. record.UltrafiltrationRate = ultrafiltration_rate
  4499. }
  4500. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4501. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4502. record.UltrafiltrationRate = ultrafiltration_rate
  4503. }
  4504. // 只针对方济医院
  4505. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4506. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4507. ultrafiltration_rate = value
  4508. record.UltrafiltrationRate = ultrafiltration_rate
  4509. }
  4510. if template.TemplateId == 41 || template.TemplateId == 47 {
  4511. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4512. record.UltrafiltrationRate = ultrafiltration_rate
  4513. }
  4514. if template.TemplateId == 43 {
  4515. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4516. record.UltrafiltrationRate = ultrafiltration_rate
  4517. }
  4518. if template.TemplateId == 46 || template.TemplateId == 54 {
  4519. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4520. record.UltrafiltrationRate = ultrafiltration_rate
  4521. }
  4522. 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 {
  4523. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4524. record.UltrafiltrationRate = ultrafiltration_rate
  4525. }
  4526. if adminInfo.Org.Id == 10469 {
  4527. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4528. record.UltrafiltrationRate = ultrafiltration_rate
  4529. }
  4530. if adminInfo.Org.Id == 10667 {
  4531. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4532. record.UltrafiltrationRate = ultrafiltration_rate
  4533. }
  4534. if adminInfo.Org.Id == 10471 {
  4535. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4536. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4537. }
  4538. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4539. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4540. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4541. }
  4542. if adminInfo.Org.Id == 10751 {
  4543. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4544. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4545. }
  4546. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4547. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4548. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4549. }
  4550. if adminInfo.Org.Id == 10721 {
  4551. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4552. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4553. }
  4554. if adminInfo.Org.Id == 10752 {
  4555. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4556. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4557. }
  4558. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4559. record.UltrafiltrationRate = 0
  4560. }
  4561. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4562. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4563. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4564. }
  4565. if adminInfo.Org.Id == 10206 {
  4566. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4567. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4568. }
  4569. //if template.TemplateId == 47 {
  4570. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4571. // record.UltrafiltrationRate = ultrafiltration_rate
  4572. //}
  4573. }
  4574. }
  4575. // record.UltrafiltrationRate = ultrafiltration_rate
  4576. record.UltrafiltrationVolume = 0
  4577. 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
  4578. if ultrafiltration_rate > 0 {
  4579. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4580. record.UltrafiltrationVolume = value
  4581. }
  4582. }
  4583. 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
  4584. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4585. if adminInfo.Org.Id != 10735 {
  4586. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4587. record.UltrafiltrationVolume = ultrafiltration_volume
  4588. }
  4589. //胶州少海医院
  4590. if adminInfo.Org.Id == 10735 {
  4591. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4592. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4593. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4594. if lastMonitorRecordList.ID > 0 {
  4595. record.UltrafiltrationRate = ultrafiltration_rate_one
  4596. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4597. record.UltrafiltrationVolume = ultrafiltration_volume
  4598. } else {
  4599. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4600. record.UltrafiltrationVolume = ultrafiltration_volume
  4601. }
  4602. }
  4603. }
  4604. }
  4605. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4606. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4607. record.UltrafiltrationVolume = ultrafiltration_volume
  4608. }
  4609. //长沙南雅
  4610. 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 {
  4611. if ultrafiltration_rate > 0 {
  4612. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4613. record.UltrafiltrationVolume = ultrafiltration_volume
  4614. }
  4615. }
  4616. if adminInfo.Org.Id == 10471 {
  4617. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4618. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4619. }
  4620. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4621. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4622. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4623. }
  4624. if adminInfo.Org.Id == 10751 {
  4625. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4626. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4627. }
  4628. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4629. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4630. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4631. }
  4632. //长沙南雅累计血容量自动计算
  4633. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4634. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4635. //}
  4636. if template.TemplateId == 47 || template.TemplateId == 54 {
  4637. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4638. }
  4639. if adminInfo.Org.Id == 10510 {
  4640. record.UltrafiltrationVolume = 0
  4641. }
  4642. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 {
  4643. if ultrafiltration_rate > 0 {
  4644. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4645. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4646. }
  4647. }
  4648. //古镇乐生
  4649. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4650. if ultrafiltration_rate > 0 {
  4651. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4652. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4653. }
  4654. }
  4655. if adminInfo.Org.Id == 10206 {
  4656. if ultrafiltration_rate > 0 {
  4657. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4658. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4659. }
  4660. }
  4661. if adminInfo.Org.Id == 10721 {
  4662. var replacement_rate float64
  4663. var displacement_quantity float64
  4664. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4665. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4666. record.ReplacementRate = replacement_rate
  4667. fmt.Println("hhhhhhhhhhhhhhhhhh", record.ReplacementRate)
  4668. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4669. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4670. record.DisplacementQuantity = displacement_quantity
  4671. }
  4672. if adminInfo.Org.Id == 10752 {
  4673. var replacement_rate float64
  4674. var displacement_quantity float64
  4675. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4676. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4677. record.ReplacementRate = replacement_rate
  4678. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4679. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4680. record.DisplacementQuantity = displacement_quantity
  4681. }
  4682. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4683. var replacement_rate float64
  4684. var displacement_quantity float64
  4685. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4686. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4687. record.ReplacementRate = replacement_rate
  4688. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4689. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4690. record.DisplacementQuantity = displacement_quantity
  4691. }
  4692. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4693. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4694. record.UltrafiltrationVolume = ultrafiltration_volume
  4695. }
  4696. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4697. var replacement_rate float64
  4698. var displacement_quantity float64
  4699. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4700. if totalMin == 0 {
  4701. totalMin = 240
  4702. }
  4703. if prescription.DisplaceLiquiValue == 0 {
  4704. prescription.ReplacementTotal = 32
  4705. }
  4706. //乘10 除10是为了保留一位小数
  4707. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4708. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4709. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4710. record.DisplacementQuantity = displacement_quantity
  4711. }
  4712. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4713. this.ServeSuccessJSON(map[string]interface{}{
  4714. "monitor": record,
  4715. "lastMonitorRecordList": lastMonitorRecordList,
  4716. })
  4717. }
  4718. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4719. record_id, _ := this.GetInt64("id")
  4720. nurseID, _ := this.GetInt64("start_nurse")
  4721. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4722. bedID, _ := this.GetInt64("bed")
  4723. start_time := this.GetString("start_time")
  4724. schedual_type, _ := this.GetInt64("schedual_type")
  4725. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4726. change_nurse, _ := this.GetInt64("change_nurse")
  4727. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4728. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4729. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4730. patient_id, _ := this.GetInt64("patient_id")
  4731. record_date, _ := this.GetInt64("record_date")
  4732. puncture_needle := this.GetString("puncture_needle")
  4733. puncture_way := this.GetString("puncture_way")
  4734. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4735. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4736. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4737. nuclein_date_str := this.GetString("nuclein_date_str")
  4738. order_remark := this.GetString("order_remark")
  4739. schedule_remark := this.GetString("schedule_remark")
  4740. catheter_operation := this.GetString("catheter_operation")
  4741. blood_flow_volume := this.GetString("blood_flow_volume")
  4742. blood_drawing, _ := this.GetInt64("blood_drawing")
  4743. dialysis_strainer := this.GetString("dialysis_strainer")
  4744. if record_id == 0 {
  4745. this.ErrorLog("id:%v", record_id)
  4746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4747. return
  4748. }
  4749. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4750. if parseStartDateErr != nil {
  4751. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4753. return
  4754. }
  4755. adminUserInfo := this.GetMobileAdminUserInfo()
  4756. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4757. if getNurseErr != nil {
  4758. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4760. return
  4761. } else if nurse == nil {
  4762. this.ErrorLog("护士不存在")
  4763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4764. return
  4765. }
  4766. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4767. //if getNurseErr != nil {
  4768. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4769. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4770. // return
  4771. //} else if nurse == nil {
  4772. // this.ErrorLog("护士不存在")
  4773. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4774. // return
  4775. //}
  4776. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4777. if getDeviceNumberErr != nil {
  4778. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4780. return
  4781. } else if deviceNumber == nil {
  4782. this.ErrorLog("床位号不存在")
  4783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4784. return
  4785. }
  4786. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4787. //
  4788. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4789. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4790. // if getPermissionErr != nil {
  4791. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4792. // return
  4793. // } else if headNursePermission == nil {
  4794. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4795. // return
  4796. // }
  4797. //}
  4798. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4799. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4800. timeLayout := "2006-01-02 15:04:05"
  4801. loc, _ := time.LoadLocation("Local")
  4802. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4803. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4804. schedulestartTime := theStartTime.Unix()
  4805. scheduleendTime := theEndTime.Unix()
  4806. var theNucleinDate int64
  4807. timeLayoutOne := "2006-01-02"
  4808. if len(nuclein_date_str) > 0 {
  4809. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4810. if err != nil {
  4811. utils.ErrorLog(err.Error())
  4812. }
  4813. theNucleinDate = theTime.Unix()
  4814. }
  4815. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4816. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4817. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4818. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4819. if err == gorm.ErrRecordNotFound { //空床位
  4820. // 修改了床位逻辑
  4821. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4822. if daySchedule.ID > 0 {
  4823. //daySchedule.BedId = bedID
  4824. //daySchedule.PartitionId = deviceNumber.ZoneID
  4825. //daySchedule.ScheduleType = schedual_type
  4826. //daySchedule.UpdatedTime = time.Now().Unix()
  4827. //err := service.UpdateSchedule(&daySchedule)
  4828. xtSchedule := models.Schedule{
  4829. PartitionId: deviceNumber.ZoneID,
  4830. BedId: bedID,
  4831. ScheduleType: schedual_type,
  4832. UpdatedTime: time.Now().Unix(),
  4833. }
  4834. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4835. if err != nil {
  4836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4837. return
  4838. }
  4839. }
  4840. } else if err == nil {
  4841. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4842. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4843. if daySchedule.ID > 0 {
  4844. //daySchedule.BedId = bedID
  4845. //daySchedule.PartitionId = deviceNumber.ZoneID
  4846. //
  4847. //daySchedule.ScheduleType = schedual_type
  4848. //daySchedule.UpdatedTime = time.Now().Unix()
  4849. //err := service.UpdateSchedule(&daySchedule)
  4850. xtSchedule := models.Schedule{
  4851. PartitionId: deviceNumber.ZoneID,
  4852. BedId: bedID,
  4853. ScheduleType: schedual_type,
  4854. UpdatedTime: time.Now().Unix(),
  4855. }
  4856. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4857. if err != nil {
  4858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4859. return
  4860. }
  4861. }
  4862. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4864. return
  4865. }
  4866. } else if err != nil {
  4867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4868. return
  4869. }
  4870. }
  4871. dialysisRecord := &models.DialysisOrder{
  4872. ID: record_id,
  4873. UserOrgId: adminUserInfo.Org.Id,
  4874. BedID: bedID,
  4875. StartNurse: nurseID,
  4876. StartTime: startDate.Unix(),
  4877. PunctureNurse: puncture_nurse,
  4878. Creator: adminUserInfo.AdminUser.Id,
  4879. Modifier: adminUserInfo.AdminUser.Id,
  4880. WashpipeNurse: washpipe_nurse,
  4881. SchedualType: schedual_type,
  4882. ChangeNurse: change_nurse,
  4883. DifficultPunctureNurse: difficult_puncture_nurse,
  4884. NewFistulaNurse: new_fistula_nurse,
  4885. QualityNurseId: quality_nurse_id,
  4886. PunctureNeedle: puncture_needle,
  4887. PunctureWay: puncture_way,
  4888. DialysisDialyszers: dialysis_dialyszers,
  4889. DialysisIrrigation: dialysis_irrigation,
  4890. BloodAccessId: blood_access_id,
  4891. NucleinDate: theNucleinDate,
  4892. OrderRemark: order_remark,
  4893. ScheduleRemark: schedule_remark,
  4894. CatheterOperation: catheter_operation,
  4895. BloodFlowVolume: blood_flow_volume,
  4896. BloodDrawing: blood_drawing,
  4897. DialysisStrainer: dialysis_strainer,
  4898. }
  4899. //修改床位号需要重新消毒
  4900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4901. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4902. //查询第一条监测
  4903. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4904. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4905. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4906. redis := service.RedisClient()
  4907. //清空key 值
  4908. redis.Set(key, "", time.Second)
  4909. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4910. redis.Set(keyOne, "", time.Second)
  4911. defer redis.Close()
  4912. }
  4913. // 查询信息规挡的设置天数
  4914. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4915. if infor.ID > 0 && infor.WeekDay > 0 {
  4916. var cha_time int64
  4917. timeNowStr := time.Now().Format("2006-01-02")
  4918. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4919. //今日的日期减去设置的日期
  4920. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4921. if cha_time >= record_date {
  4922. //查询审核是否允许
  4923. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4924. //申请状态不允许的情况 拒绝修改
  4925. if infor.ApplicationStatus != 1 {
  4926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4927. return
  4928. }
  4929. }
  4930. }
  4931. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4932. //修改床位后重新生成消毒计划
  4933. if adminUserInfo.Org.Id == 10340 {
  4934. //根据床位号获取设备型号
  4935. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4936. //查询使用消毒最后一条消毒记录
  4937. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4938. fmt.Println("err", err)
  4939. if err == gorm.ErrRecordNotFound {
  4940. //查找排班
  4941. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4942. //查询改设备是否有消毒计划
  4943. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4944. //根据床位号获取设备id
  4945. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4946. //查询病人信息
  4947. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4948. var con = ""
  4949. if patients.IsInfectious == 0 {
  4950. con = ""
  4951. }
  4952. if patients.IsInfectious == 1 {
  4953. con = "无"
  4954. }
  4955. if patients.IsInfectious == 2 {
  4956. con = "有"
  4957. }
  4958. if errcode == nil {
  4959. var end_time int64
  4960. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4961. //新增消毒
  4962. information := models.DeviceInformation{
  4963. Date: dialysisRecord.DialysisDate,
  4964. Zone: dialysisRecord.ZoneId,
  4965. Class: dialysisRecord.SchedualType,
  4966. BedNumber: dialysisRecord.BedID,
  4967. PatientId: dialysisRecord.PatientId,
  4968. DialysisMode: scheduleByPatient.ModeId,
  4969. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4970. Disinfection: 1,
  4971. DialysisConcentration: 1,
  4972. DisinfectionStatus: 1,
  4973. Move: 1,
  4974. UserOrgId: dialysisRecord.UserOrgId,
  4975. DisinfectType: plan.Way,
  4976. DisinfectantType: plan.MachineDisinfectant,
  4977. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4978. Disinfectant: plan.Disinfectant,
  4979. Ctime: time.Now().Unix(),
  4980. Status: 1,
  4981. SignName: nurseID,
  4982. EquimentId: addmacher.ID,
  4983. DisinfectionResidue: 2,
  4984. Bed: addmacher.BedNumber,
  4985. StartTime: dialysisRecord.StartTime,
  4986. EndTime: dialysisRecord.EndTime,
  4987. Contagion: con,
  4988. WeightLoss: 0,
  4989. Hyperfiltratio: 0,
  4990. DialysisHour: "",
  4991. MachineRun: 1,
  4992. DisinfecStartime: dialysisRecord.EndTime,
  4993. DisinfecEndtime: end_time,
  4994. }
  4995. err := service.CreateInformationTwo(&information)
  4996. fmt.Println("报错", err)
  4997. }
  4998. }
  4999. }
  5000. order, _ := service.GetLastPatientOrder(record_id)
  5001. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5002. redis := service.RedisClient()
  5003. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5004. redis.Set(key, "", time.Second)
  5005. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5006. //清空key 值
  5007. redis.Set(keyOne, "", time.Second)
  5008. scheduleDateStartOne := startDate.Format("2006-01-02")
  5009. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5010. redis.Set(keyTwo, "", time.Second)
  5011. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5012. redis.Set(keyThree, "", time.Second)
  5013. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5014. redis.Set(keyFour, "", time.Second)
  5015. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5016. redis.Set(keyFive, "", time.Second)
  5017. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5018. redis.Set(keySix, "", time.Second)
  5019. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5020. redis.Set(keySeven, "", time.Second)
  5021. if updateErr != nil {
  5022. this.ErrorLog("修改上机失败:%v", updateErr)
  5023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5024. return
  5025. }
  5026. if updateErr == nil {
  5027. if tempDialysisRecord.Stage == 2 {
  5028. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5029. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5030. fmt.Println(value)
  5031. a, b := math.Modf(value)
  5032. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5033. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5034. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5035. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5036. redis := service.RedisClient()
  5037. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5038. redis.Set(key, "", time.Second)
  5039. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5040. redis.Set(keyOne, "", time.Second)
  5041. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5042. //清空key 值
  5043. redis.Set(keySix, "", time.Second)
  5044. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5045. redis.Set(keySeven, "", time.Second)
  5046. redis.Close()
  5047. if updateAssessmentErr != nil {
  5048. utils.ErrorLog("%v", updateAssessmentErr)
  5049. }
  5050. }
  5051. }
  5052. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5053. this.ServeSuccessJSON(map[string]interface{}{
  5054. "dialysis_order": dialysisRecords,
  5055. })
  5056. }
  5057. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5058. record_id, _ := c.GetInt64("id")
  5059. nurseID, _ := c.GetInt64("nurse")
  5060. end_time := c.GetString("end_time")
  5061. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5062. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5063. catheter := c.GetString("catheter")
  5064. cruor := c.GetString("cruor")
  5065. mission := c.GetString("mission")
  5066. condenser := c.GetString("condenser")
  5067. if record_id <= 0 || nurseID <= 0 {
  5068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5069. return
  5070. }
  5071. adminUserInfo := c.GetMobileAdminUserInfo()
  5072. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5073. if getNurseErr != nil {
  5074. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5076. return
  5077. } else if nurse == nil {
  5078. c.ErrorLog("护士不存在")
  5079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5080. return
  5081. }
  5082. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5083. if parseEndDateErr != nil {
  5084. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5086. return
  5087. }
  5088. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5089. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5090. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5091. // if getPermissionErr != nil {
  5092. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5093. // return
  5094. // } else if headNursePermission == nil {
  5095. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5096. // return
  5097. // }
  5098. //}
  5099. // 查询信息规挡的设置天数
  5100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5101. if infor.ID > 0 {
  5102. var cha_time int64
  5103. timeNowStr := time.Now().Format("2006-01-02")
  5104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5105. //今日的日期减去设置的日期
  5106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5107. if cha_time >= tempDialysisRecords.DialysisDate {
  5108. //查询审核是否允许
  5109. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5110. //申请状态不允许的情况 拒绝修改
  5111. if infor.ApplicationStatus != 1 {
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5113. return
  5114. }
  5115. }
  5116. }
  5117. dialysisRecord := &models.DialysisOrder{
  5118. ID: record_id,
  5119. UserOrgId: adminUserInfo.Org.Id,
  5120. EndTime: endDate.Unix(),
  5121. FinishNurse: nurseID,
  5122. FinishModifier: adminUserInfo.AdminUser.Id,
  5123. PuncturePointHaematoma: puncture_point_haematoma,
  5124. BloodAccessInternalFistula: blood_access_internal_fistula,
  5125. Catheter: catheter,
  5126. Cruor: cruor,
  5127. Mission: mission,
  5128. Condenser: condenser,
  5129. }
  5130. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5131. redis := service.RedisClient()
  5132. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5133. //清空key 值
  5134. redis.Set(key, "", time.Second)
  5135. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5136. //清空key 值
  5137. redis.Set(keyOne, "", time.Second)
  5138. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5139. redis.Set(keySeven, "", time.Second)
  5140. redis.Close()
  5141. if updateErr != nil {
  5142. c.ErrorLog("修改下机失败:%v", updateErr)
  5143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5144. return
  5145. }
  5146. if updateErr == nil {
  5147. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5148. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5149. a, b := math.Modf(value)
  5150. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5151. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5152. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5153. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5154. redis := service.RedisClient()
  5155. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5156. redis.Set(keyTen, "", time.Second)
  5157. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5158. redis.Set(keyTwo, "", time.Second)
  5159. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5160. redis.Set(key, "", time.Second)
  5161. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5162. redis.Set(keyThree, "", time.Second)
  5163. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5164. redis.Set(keySeven, "", time.Second)
  5165. defer redis.Close()
  5166. if updateAssessmentErr != nil {
  5167. utils.ErrorLog("%v", updateAssessmentErr)
  5168. }
  5169. }
  5170. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5171. c.ServeSuccessJSON(map[string]interface{}{
  5172. "dialysis_order": dialysisRecords,
  5173. })
  5174. }
  5175. func (c *DialysisAPIController) GetLongAdvice() {
  5176. patient_id, _ := c.GetInt64("id")
  5177. adminUserInfo := c.GetMobileAdminUserInfo()
  5178. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5179. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5180. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5181. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5182. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5183. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5184. c.ServeSuccessJSON(map[string]interface{}{
  5185. "status": "1",
  5186. })
  5187. return
  5188. } else { //开启推送提醒
  5189. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5190. var advice_three []*models.DoctorAdvice
  5191. recordDateStr := time.Now().Format("2006-01-02")
  5192. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5193. nowtime := recordDate.Unix()
  5194. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5195. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5196. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5197. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5198. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5199. for _, advice := range advices {
  5200. if advice.FrequencyType == 3 {
  5201. t := time.Now()
  5202. week := int(t.Weekday())
  5203. fmt.Println(t.Weekday())
  5204. fmt.Println(week)
  5205. switch week {
  5206. case 1:
  5207. if strings.Index(advice.WeekDay, "周一") == -1 {
  5208. advice_three = append(advice_three, advice)
  5209. }
  5210. break
  5211. case 2:
  5212. if strings.Index(advice.WeekDay, "周二") == -1 {
  5213. advice_three = append(advice_three, advice)
  5214. }
  5215. break
  5216. case 3:
  5217. if strings.Index(advice.WeekDay, "周三") == -1 {
  5218. advice_three = append(advice_three, advice)
  5219. }
  5220. break
  5221. case 4:
  5222. if strings.Index(advice.WeekDay, "周四") == -1 {
  5223. advice_three = append(advice_three, advice)
  5224. }
  5225. break
  5226. case 5:
  5227. if strings.Index(advice.WeekDay, "周五") == -1 {
  5228. advice_three = append(advice_three, advice)
  5229. }
  5230. break
  5231. case 6:
  5232. if strings.Index(advice.WeekDay, "周六") == -1 {
  5233. advice_three = append(advice_three, advice)
  5234. }
  5235. break
  5236. case 0:
  5237. if strings.Index(advice.WeekDay, "周日") == -1 {
  5238. advice_three = append(advice_three, advice)
  5239. }
  5240. break
  5241. }
  5242. }
  5243. }
  5244. for _, advice := range advices_two {
  5245. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5246. now := p.Unix()
  5247. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5248. dayStr2 := "-" + dayStr
  5249. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5250. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5251. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5252. for _, ad := range advices {
  5253. advice_three = append(advice_three, ad)
  5254. }
  5255. }
  5256. if err == nil {
  5257. c.ServeSuccessJSON(map[string]interface{}{
  5258. "status": "2",
  5259. "advices": advices,
  5260. "advices_two": RemoveRepeatedElement(advice_three),
  5261. "is_open_remind": config.IsOpenRemind,
  5262. "his_config_open": hisConfig.IsOpen,
  5263. "is_advice_open": is_advice_open.IsAdviceOpen,
  5264. "prescription_open": prescription_open.IsOpen,
  5265. })
  5266. }
  5267. }
  5268. }
  5269. func (c *DialysisAPIController) GetLongAdviceOne() {
  5270. patient_id, _ := c.GetInt64("id")
  5271. startTime := c.GetString("schedule_date")
  5272. timeLayout := "2006-01-02"
  5273. loc, _ := time.LoadLocation("Local")
  5274. var theStartTime int64
  5275. if len(startTime) > 0 {
  5276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5277. if err != nil {
  5278. utils.ErrorLog(err.Error())
  5279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5280. return
  5281. }
  5282. theStartTime = theTime.Unix()
  5283. }
  5284. adminUserInfo := c.GetMobileAdminUserInfo()
  5285. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5286. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5287. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5288. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5289. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5290. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5291. c.ServeSuccessJSON(map[string]interface{}{
  5292. "status": "1",
  5293. })
  5294. return
  5295. } else { //开启推送提醒
  5296. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5297. var advice_three []*models.DoctorAdvice
  5298. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5299. fmt.Println("theStartTime-----------------------", theStartTime)
  5300. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5301. for _, advice := range advices {
  5302. if advice.FrequencyType == 3 {
  5303. t := time.Now()
  5304. week := int(t.Weekday())
  5305. fmt.Println(t.Weekday())
  5306. fmt.Println(week)
  5307. switch week {
  5308. case 1:
  5309. if strings.Index(advice.WeekDay, "周一") == -1 {
  5310. advice_three = append(advice_three, advice)
  5311. }
  5312. break
  5313. case 2:
  5314. if strings.Index(advice.WeekDay, "周二") == -1 {
  5315. advice_three = append(advice_three, advice)
  5316. }
  5317. break
  5318. case 3:
  5319. if strings.Index(advice.WeekDay, "周三") == -1 {
  5320. advice_three = append(advice_three, advice)
  5321. }
  5322. break
  5323. case 4:
  5324. if strings.Index(advice.WeekDay, "周四") == -1 {
  5325. advice_three = append(advice_three, advice)
  5326. }
  5327. break
  5328. case 5:
  5329. if strings.Index(advice.WeekDay, "周五") == -1 {
  5330. advice_three = append(advice_three, advice)
  5331. }
  5332. break
  5333. case 6:
  5334. if strings.Index(advice.WeekDay, "周六") == -1 {
  5335. advice_three = append(advice_three, advice)
  5336. }
  5337. break
  5338. case 0:
  5339. if strings.Index(advice.WeekDay, "周日") == -1 {
  5340. advice_three = append(advice_three, advice)
  5341. }
  5342. break
  5343. }
  5344. }
  5345. }
  5346. for _, advice := range advices_two {
  5347. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5348. now := p.Unix()
  5349. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5350. dayStr2 := "-" + dayStr
  5351. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5352. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5353. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5354. fmt.Println("advices-==---------------", advices)
  5355. for _, ad := range advices {
  5356. advice_three = append(advice_three, ad)
  5357. }
  5358. }
  5359. if err == nil {
  5360. c.ServeSuccessJSON(map[string]interface{}{
  5361. "status": "2",
  5362. "advices": advices,
  5363. "advices_two": RemoveRepeatedElement(advice_three),
  5364. "is_open_remind": config.IsOpenRemind,
  5365. "his_config_open": hisConfig.IsOpen,
  5366. "is_advice_open": is_advice_open.IsAdviceOpen,
  5367. "prescription_open": prescription_open.IsOpen,
  5368. })
  5369. }
  5370. }
  5371. }
  5372. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5373. newArr = make([]*models.DoctorAdvice, 0)
  5374. for i := 0; i < len(arr); i++ {
  5375. repeat := false
  5376. for j := i + 1; j < len(arr); j++ {
  5377. if arr[i].ID == arr[j].ID {
  5378. repeat = true
  5379. break
  5380. }
  5381. }
  5382. if !repeat {
  5383. newArr = append(newArr, arr[i])
  5384. }
  5385. }
  5386. return
  5387. }
  5388. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5389. patient, _ := c.GetInt64("id", 0)
  5390. groupNo, _ := c.GetInt64("groupno", 0)
  5391. if patient <= 0 {
  5392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5393. return
  5394. }
  5395. adminUserInfo := c.GetMobileAdminUserInfo()
  5396. dataBody := make(map[string]interface{}, 0)
  5397. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5398. if err != nil {
  5399. utils.ErrorLog(err.Error())
  5400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5401. return
  5402. }
  5403. utils.ErrorLog("%v", dataBody)
  5404. timeLayout := "2006-01-02 15:04"
  5405. loc, _ := time.LoadLocation("Local")
  5406. timeLayout2 := "2006-01-02"
  5407. loc2, _ := time.LoadLocation("Local")
  5408. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5409. utils.ErrorLog("advice_type")
  5410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5411. return
  5412. }
  5413. adviceType := int64(2)
  5414. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5415. utils.ErrorLog("advice_date")
  5416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. adviceDate, _ := dataBody["advice_date"].(string)
  5420. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5421. AdviceDate := theTime.Unix()
  5422. RecordDate := theTime.Unix()
  5423. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5424. utils.ErrorLog("start_time")
  5425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5426. return
  5427. }
  5428. startTime, _ := dataBody["start_time"].(string)
  5429. if len(startTime) == 0 {
  5430. utils.ErrorLog("len(start_time) == 0")
  5431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5432. return
  5433. }
  5434. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5435. if err != nil {
  5436. utils.ErrorLog(err.Error())
  5437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5438. return
  5439. }
  5440. StartTime := theTime.Unix()
  5441. Remark := ""
  5442. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5443. remark, _ := dataBody["remark"].(string)
  5444. Remark = remark
  5445. }
  5446. var advices []*models.GroupAdvice
  5447. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5448. utils.ErrorLog("advices")
  5449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5450. return
  5451. }
  5452. adviceNames := dataBody["advices"].([]interface{})
  5453. for _, adviceNameMap := range adviceNames {
  5454. adviceNameM := adviceNameMap.(map[string]interface{})
  5455. var advice models.GroupAdvice
  5456. advice.Remark = Remark
  5457. advice.AdviceType = adviceType
  5458. advice.StartTime = StartTime
  5459. advice.AdviceDate = AdviceDate
  5460. advice.RecordDate = RecordDate
  5461. advice.Status = 1
  5462. advice.CreatedTime = time.Now().Unix()
  5463. advice.UpdatedTime = time.Now().Unix()
  5464. advice.StopState = 2
  5465. advice.ExecutionState = 2
  5466. advice.UserOrgId = adminUserInfo.Org.Id
  5467. advice.PatientId = patient
  5468. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5469. advice.IsSettle = 2
  5470. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5471. utils.ErrorLog("advice_name")
  5472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5473. return
  5474. }
  5475. adviceName, _ := adviceNameM["advice_name"].(string)
  5476. if len(adviceName) == 0 {
  5477. utils.ErrorLog("len(advice_name) == 0")
  5478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. return
  5480. }
  5481. advice.AdviceName = adviceName
  5482. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5483. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5484. advice.DrugSpec = drugSpec
  5485. }
  5486. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5487. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5488. advice.AdviceDesc = adviceDesc
  5489. }
  5490. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5491. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5492. advice.DrugSpecUnit = drugSpecUnit
  5493. }
  5494. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5495. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5496. // advice.SingleDose = singleDose
  5497. //}
  5498. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5499. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5500. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5501. }
  5502. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5503. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5504. advice.SingleDoseUnit = singleDoseUnit
  5505. }
  5506. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5507. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5508. // advice.PrescribingNumber = prescribingNumber
  5509. //}
  5510. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5511. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5512. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5513. }
  5514. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5515. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5516. advice.PrescribingNumberUnit = prescribingNumberUnit
  5517. }
  5518. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5519. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5520. advice.DeliveryWay = deliveryWay
  5521. }
  5522. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5523. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5524. advice.ExecutionFrequency = executionFrequency
  5525. }
  5526. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5527. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5528. advice.FrequencyType = frequency_type
  5529. }
  5530. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5531. day_count := int64(adviceNameM["day_count"].(float64))
  5532. advice.DayCount = day_count
  5533. }
  5534. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5535. week_day, _ := adviceNameM["week_day"].(string)
  5536. advice.WeekDay = week_day
  5537. }
  5538. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5539. way := int64(adviceNameM["way"].(float64))
  5540. advice.Way = way
  5541. }
  5542. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5543. drug_id := int64(adviceNameM["drug_id"].(float64))
  5544. advice.DrugId = drug_id
  5545. }
  5546. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5547. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5548. advice.DrugNameId = drug_name_id
  5549. }
  5550. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5551. remark, _ := adviceNameM["remark"].(string)
  5552. advice.Remark = remark
  5553. }
  5554. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5555. groupno := int64(adviceNameM["groupno"].(float64))
  5556. advice.GroupNo = groupno
  5557. }
  5558. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5559. template_id, _ := adviceNameM["template_id"].(string)
  5560. advice.TemplateId = template_id
  5561. }
  5562. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5563. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5564. advice.ExecutionFrequency = executionFrequency
  5565. }
  5566. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5567. children := adviceNameM["child"].([]interface{})
  5568. if len(children) > 0 {
  5569. for _, childrenMap := range children {
  5570. childMap := childrenMap.(map[string]interface{})
  5571. var child models.GroupAdvice
  5572. child.Remark = Remark
  5573. child.AdviceType = adviceType
  5574. child.StartTime = StartTime
  5575. child.AdviceDate = AdviceDate
  5576. child.RecordDate = RecordDate
  5577. child.Status = 1
  5578. child.CreatedTime = time.Now().Unix()
  5579. child.UpdatedTime = time.Now().Unix()
  5580. child.StopState = 2
  5581. child.ExecutionState = 2
  5582. child.UserOrgId = adminUserInfo.Org.Id
  5583. child.PatientId = patient
  5584. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5585. child.IsSettle = 1
  5586. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5587. utils.ErrorLog("child advice_name")
  5588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5589. return
  5590. }
  5591. childAdviceName, _ := childMap["advice_name"].(string)
  5592. if len(childAdviceName) == 0 {
  5593. utils.ErrorLog("len(child advice_name) == 0")
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5595. return
  5596. }
  5597. child.AdviceName = childAdviceName
  5598. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5599. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5600. child.AdviceDesc = childAdviceDesc
  5601. }
  5602. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5603. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5604. child.DrugSpec = childDrugSpec
  5605. }
  5606. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5607. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5608. child.DrugSpecUnit = childDrugSpecUnit
  5609. }
  5610. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5611. child.SingleDose = childMap["single_dose"].(float64)
  5612. }
  5613. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5614. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5615. child.SingleDoseUnit = childSingleDoseUnit
  5616. }
  5617. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5618. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5619. }
  5620. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5621. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5622. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5623. }
  5624. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5625. groupno := int64(childMap["groupno"].(float64))
  5626. advice.GroupNo = groupno
  5627. }
  5628. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5629. remark, _ := childMap["remark"].(string)
  5630. child.Remark = remark
  5631. }
  5632. child.DeliveryWay = advice.DeliveryWay
  5633. child.ExecutionFrequency = advice.ExecutionFrequency
  5634. advice.Children = append(advice.Children, &child)
  5635. }
  5636. }
  5637. }
  5638. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5639. if temp_advice.ID == 0 {
  5640. advices = append(advices, &advice)
  5641. }
  5642. }
  5643. if len(advices) > 0 {
  5644. finish := models.XtDialysisFinish{
  5645. IsFinish: 1,
  5646. UserOrgId: adminUserInfo.Org.Id,
  5647. Status: 1,
  5648. Ctime: time.Now().Unix(),
  5649. Mtime: 0,
  5650. Module: 4,
  5651. RecordDate: AdviceDate,
  5652. Sourse: 1,
  5653. PatientId: patient,
  5654. }
  5655. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5656. if dialysisFinish.ID == 0 {
  5657. service.CreateDialysisFinish(finish)
  5658. }
  5659. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5660. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5661. for _, item := range advices {
  5662. byterequest, _ := json.Marshal(item)
  5663. adviceLog := models.XtDoctorAdviceLog{
  5664. UserOrgId: adminUserInfo.Org.Id,
  5665. PatientId: patient,
  5666. AdminUserId: adminUserInfo.AdminUser.Id,
  5667. Module: 1,
  5668. ErrLog: string(byterequest),
  5669. Status: 1,
  5670. Ctime: time.Now().Unix(),
  5671. Mtime: 0,
  5672. Source: "手机端医嘱推送",
  5673. RecordDate: item.AdviceDate,
  5674. }
  5675. service.CreateDoctorAdviceLog(adviceLog)
  5676. }
  5677. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5678. redis := service.RedisClient()
  5679. //清空key 值
  5680. redis.Set(key, "", time.Second)
  5681. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5682. redis.Set(keyOne, "", time.Second)
  5683. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5684. defer redis.Close()
  5685. redis.Set(keyThree, "", time.Second)
  5686. if err != nil {
  5687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5688. return
  5689. }
  5690. c.ServeSuccessJSON(map[string]interface{}{
  5691. "msg": "ok",
  5692. "advices": list,
  5693. })
  5694. } else {
  5695. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5696. for _, item := range advices {
  5697. byterequest, _ := json.Marshal(item)
  5698. adviceLog := models.XtDoctorAdviceLog{
  5699. UserOrgId: adminUserInfo.Org.Id,
  5700. PatientId: patient,
  5701. AdminUserId: adminUserInfo.AdminUser.Id,
  5702. Module: 1,
  5703. ErrLog: string(byterequest),
  5704. Status: 1,
  5705. Ctime: time.Now().Unix(),
  5706. Mtime: 0,
  5707. Source: "手机端医嘱推送",
  5708. RecordDate: item.AdviceDate,
  5709. }
  5710. service.CreateDoctorAdviceLog(adviceLog)
  5711. }
  5712. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5713. redis := service.RedisClient()
  5714. //清空key 值
  5715. redis.Set(key, "", time.Second)
  5716. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5717. redis.Set(keyOne, "", time.Second)
  5718. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5719. defer redis.Close()
  5720. redis.Set(keyThree, "", time.Second)
  5721. if err != nil {
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5723. return
  5724. }
  5725. c.ServeSuccessJSON(map[string]interface{}{
  5726. "msg": "ok",
  5727. "advices": list,
  5728. })
  5729. }
  5730. } else {
  5731. c.ServeSuccessJSON(map[string]interface{}{
  5732. "msg": "ok",
  5733. })
  5734. }
  5735. return
  5736. }
  5737. func (c *DialysisAPIController) UploadDryWeight() {
  5738. patient_id, _ := c.GetInt64("id")
  5739. dry_weight, _ := c.GetFloat("dry_weight")
  5740. doctor_id, _ := c.GetInt64("doctor_id")
  5741. remark := c.GetString("remark")
  5742. adminUserInfo := c.GetMobileAdminUserInfo()
  5743. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5744. if err == gorm.ErrRecordNotFound {
  5745. dryWeight := &models.SgjPatientDryweight{
  5746. PatientId: patient_id,
  5747. DryWeight: dry_weight,
  5748. Remakes: remark,
  5749. Ctime: time.Now().Unix(),
  5750. Mtime: time.Now().Unix(),
  5751. Creator: doctor_id,
  5752. Status: 1,
  5753. UserOrgId: adminUserInfo.Org.Id,
  5754. AdjustedValue: "/",
  5755. UserId: adminUserInfo.AdminUser.Id,
  5756. }
  5757. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5758. redis := service.RedisClient()
  5759. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5760. redis.Set(keyOne, "", time.Second)
  5761. loc, _ := time.LoadLocation("Local")
  5762. nowTime := time.Now()
  5763. nowDay := nowTime.Format("2006-01-02")
  5764. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5765. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5766. redis.Set(key, "", time.Second)
  5767. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5768. redis.Set(keyTwo, "", time.Second)
  5769. redis.Close()
  5770. if createErr == nil {
  5771. c.ServeSuccessJSON(map[string]interface{}{
  5772. "msg": "提交成功",
  5773. "weight": dryWeight,
  5774. })
  5775. }
  5776. } else {
  5777. dryWeight := &models.SgjPatientDryweight{
  5778. PatientId: patient_id,
  5779. DryWeight: dry_weight,
  5780. Remakes: remark,
  5781. Ctime: time.Now().Unix(),
  5782. Mtime: time.Now().Unix(),
  5783. Creator: doctor_id,
  5784. Status: 1,
  5785. UserOrgId: adminUserInfo.Org.Id,
  5786. AdjustedValue: "/",
  5787. UserId: adminUserInfo.AdminUser.Id,
  5788. }
  5789. var value float64
  5790. value = dry_weight - weightAdjust.DryWeight
  5791. if value < 0 {
  5792. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5793. } else if value == 0 {
  5794. dryWeight.AdjustedValue = "/"
  5795. } else if value > 0 {
  5796. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5797. }
  5798. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5799. //康桥
  5800. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5801. timeNowStr := time.Now().Format("2006-01-02")
  5802. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5803. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5804. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5805. if beforAssesment.ID > 0 {
  5806. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5807. var dewater_amount float64
  5808. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5809. if adminUserInfo.Org.Id != 10702 {
  5810. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5811. }
  5812. if adminUserInfo.Org.Id == 10702 {
  5813. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  5814. }
  5815. //获取key,清空redis
  5816. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5817. redis := service.RedisClient()
  5818. //清空key 值
  5819. redis.Set(key, "", time.Second)
  5820. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5821. //清空key 值
  5822. redis.Set(keyOne, "", time.Second)
  5823. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5824. //清空key 值
  5825. redis.Set(keyTwo, "", time.Second)
  5826. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5827. redis.Set(keySix, "", time.Second)
  5828. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5829. redis.Set(keySeven, "", time.Second)
  5830. }
  5831. }
  5832. redis := service.RedisClient()
  5833. loc, _ := time.LoadLocation("Local")
  5834. nowTime := time.Now()
  5835. nowDay := nowTime.Format("2006-01-02")
  5836. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5837. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5838. redis.Set(keyOne, "", time.Second)
  5839. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5840. redis.Set(key, "", time.Second)
  5841. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5842. redis.Set(keyTwo, "", time.Second)
  5843. redis.Close()
  5844. if createErr == nil {
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "msg": "提交成功",
  5847. "weight": dryWeight,
  5848. })
  5849. }
  5850. }
  5851. }
  5852. func (c *DialysisAPIController) GetSolution() {
  5853. patient_id, _ := c.GetInt64("patient_id")
  5854. mode_id, _ := c.GetInt64("mode_id")
  5855. adminUserInfo := c.GetMobileAdminUserInfo()
  5856. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5857. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5858. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5859. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5860. if err != nil {
  5861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5862. return
  5863. }
  5864. c.ServeSuccessJSON(map[string]interface{}{
  5865. "solution": solution,
  5866. "prescription": prescription,
  5867. "system_prescription": system_prescription,
  5868. "dialysisPrescription": dialysisPrescription,
  5869. })
  5870. }
  5871. func (c *DialysisAPIController) GetSchedule() {
  5872. schedual_type, _ := c.GetInt64("schedual_type")
  5873. adminUserInfo := c.GetMobileAdminUserInfo()
  5874. scheduleTime, _ := c.GetInt64("record_date")
  5875. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5876. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5877. c.ServeSuccessJSON(map[string]interface{}{
  5878. "number": deviceNumber,
  5879. "list": list,
  5880. })
  5881. }
  5882. func (c *DialysisAPIController) GetPatientId() {
  5883. id, _ := c.GetInt64("id")
  5884. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5885. patientId, _ := service.GetPatientId(id)
  5886. //获取该患者的所有传染病
  5887. list, _ := service.GetPatientInfectious(id)
  5888. c.ServeSuccessJSON(map[string]interface{}{
  5889. "patient": patientId,
  5890. "infectioulist": list,
  5891. })
  5892. }
  5893. func (this *DialysisAPIController) GetDialysisSchedule() {
  5894. schedualDate := this.GetString("date")
  5895. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5896. if parseDateErr != nil {
  5897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5898. return
  5899. }
  5900. adminInfo := this.GetMobileAdminUserInfo()
  5901. orgID := adminInfo.Org.Id
  5902. redis := service.RedisClient()
  5903. defer redis.Close()
  5904. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5905. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5906. if len(scheduals) > 0 {
  5907. //缓存数据
  5908. scheduals_json, err := json.Marshal(scheduals)
  5909. if err == nil {
  5910. redis.Set(key, scheduals_json, time.Second*30)
  5911. }
  5912. }
  5913. this.ServeSuccessJSON(map[string]interface{}{
  5914. "scheduals": scheduals,
  5915. })
  5916. }
  5917. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5918. change_type, _ := this.GetInt64("type", 0)
  5919. record_date := this.GetString("record_time")
  5920. patient_id, _ := this.GetInt64("patient_id", 0)
  5921. timeLayout := "2006-01-02"
  5922. loc, _ := time.LoadLocation("Local")
  5923. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5924. record_time := theAdviceRecordTime.Unix()
  5925. adminUserInfo := this.GetMobileAdminUserInfo()
  5926. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5927. if err == nil {
  5928. if len(advices) == 0 {
  5929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5930. return
  5931. } else {
  5932. this.ServeSuccessJSON(map[string]interface{}{
  5933. "advices": advices,
  5934. "schedule": sch,
  5935. })
  5936. return
  5937. }
  5938. } else {
  5939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5940. return
  5941. }
  5942. }
  5943. func (c *DialysisAPIController) CreateConsumables() {
  5944. record_date := c.GetString("record_time")
  5945. patient_id, _ := c.GetInt64("patient_id", 0)
  5946. active, _ := c.GetInt64("active")
  5947. adminUser := c.GetMobileAdminUserInfo()
  5948. timeLayout := "2006-01-02"
  5949. loc, _ := time.LoadLocation("Local")
  5950. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5951. record_time := theRecordTime.Unix()
  5952. // 查询信息规挡的设置天数
  5953. orgid := c.GetMobileAdminUserInfo().Org.Id
  5954. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5955. if infor.ID > 0 {
  5956. var cha_time int64
  5957. timeNowStr := time.Now().Format("2006-01-02")
  5958. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5959. //今日的日期减去设置的日期
  5960. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5961. if cha_time >= record_time {
  5962. //查询审核是否允许
  5963. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5964. //申请状态不允许的情况 拒绝修改
  5965. if infor.ApplicationStatus != 1 {
  5966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5967. return
  5968. }
  5969. }
  5970. }
  5971. dataBody := make(map[string]interface{}, 0)
  5972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5973. if err != nil {
  5974. utils.ErrorLog(err.Error())
  5975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5976. return
  5977. }
  5978. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5979. var beforePrepares []*models.DialysisBeforePrepareGoods
  5980. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5981. var dialysisBefor []*models.DialysisBeforePrepare
  5982. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5983. goods, _ := dataBody["goods"].([]interface{})
  5984. if len(goods) > 0 {
  5985. for _, item := range goods {
  5986. items := item.(map[string]interface{})
  5987. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5988. utils.ErrorLog("good_id")
  5989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5990. return
  5991. }
  5992. good_id := int64(items["good_id"].(float64))
  5993. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5994. utils.ErrorLog("good_type_id")
  5995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5996. return
  5997. }
  5998. good_type_id := int64(items["good_type_id"].(float64))
  5999. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6000. utils.ErrorLog("count")
  6001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6002. return
  6003. }
  6004. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6005. commdity_code := items["commdity_code"].(string)
  6006. fmt.Println("commdity", commdity_code)
  6007. prepareGoods := &models.DialysisBeforePrepareGoods{
  6008. GoodTypeId: good_type_id,
  6009. GoodId: good_id,
  6010. Count: count,
  6011. StorehouseId: houseConfig.StorehouseOutInfo,
  6012. }
  6013. beforePrepares = append(beforePrepares, prepareGoods)
  6014. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6015. GoodTypeId: good_type_id,
  6016. GoodId: good_id,
  6017. Count: count,
  6018. StorehouseId: houseConfig.StorehouseOutInfo,
  6019. }
  6020. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6021. prepare := &models.DialysisBeforePrepare{
  6022. GoodTypeId: good_type_id,
  6023. GoodId: good_id,
  6024. Count: count,
  6025. PatientId: patient_id,
  6026. RecordDate: record_time,
  6027. UserOrgId: adminUser.Org.Id,
  6028. Status: 1,
  6029. Ctime: time.Now().Unix(),
  6030. Creater: adminUser.AdminUser.Id,
  6031. CommdityCode: commdity_code,
  6032. StorehouseId: houseConfig.StorehouseOutInfo,
  6033. }
  6034. dialysisBefor = append(dialysisBefor, prepare)
  6035. }
  6036. }
  6037. //查询是否有库存
  6038. for _, item := range dialysisBefor {
  6039. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6040. if err == gorm.ErrRecordNotFound {
  6041. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6042. c.ServeSuccessJSON(map[string]interface{}{
  6043. "message": "1",
  6044. "good_name": goodObj.GoodName,
  6045. "specification_name": goodObj.SpecificationName,
  6046. })
  6047. return
  6048. }
  6049. if err != nil {
  6050. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6051. c.ServeSuccessJSON(map[string]interface{}{
  6052. "message": "1",
  6053. "good_name": goodObj.GoodName,
  6054. "specification_name": goodObj.SpecificationName,
  6055. })
  6056. return
  6057. }
  6058. }
  6059. fmt.Println("active-----------------------", active)
  6060. fmt.Println("len(goods)-----------------------", len(goods))
  6061. //新增
  6062. if active == 1 && len(goods) > 0 {
  6063. for _, item := range dialysisBefor {
  6064. dialyPrepareOne := models.DialysisBeforePrepare{
  6065. GoodTypeId: item.GoodTypeId,
  6066. GoodId: item.GoodId,
  6067. PatientId: item.PatientId,
  6068. RecordDate: item.RecordDate,
  6069. UserOrgId: item.UserOrgId,
  6070. Count: item.Count,
  6071. Ctime: time.Now().Unix(),
  6072. Creater: item.Creater,
  6073. CommdityCode: item.CommdityCode,
  6074. Status: 1,
  6075. StorehouseId: houseConfig.StorehouseOutInfo,
  6076. }
  6077. //先清除再插入
  6078. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6079. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6080. //查询默认仓库
  6081. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6082. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6083. var total_count int64
  6084. for _, it := range stockList {
  6085. total_count += it.StockCount
  6086. }
  6087. //基础库插入数据
  6088. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6089. //更新库存
  6090. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6091. var flush_count int64
  6092. for _, it := range goodList {
  6093. flush_count += it.StockCount
  6094. }
  6095. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6096. }
  6097. if err == nil {
  6098. c.ServeSuccessJSON(map[string]interface{}{
  6099. "msg": "保存成功",
  6100. "message": "2",
  6101. })
  6102. return
  6103. } else {
  6104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6105. return
  6106. }
  6107. }
  6108. if len(beforePrepares) > 0 && active == 2 {
  6109. for _, item := range beforePrepares {
  6110. //1.查看该患者该耗材型号最后一次出库数量
  6111. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6112. //判断当前出库数量和最后一次出库数量的大小
  6113. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6114. if item.Count <= goodInfo.Count {
  6115. //退库
  6116. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6117. //查询今日出库数据
  6118. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6119. for _, it := range list {
  6120. prepare := models.DialysisBeforePrepare{
  6121. UserOrgId: it.OrgId,
  6122. PatientId: patient_id,
  6123. RecordDate: it.RecordTime,
  6124. GoodId: it.GoodId,
  6125. GoodTypeId: it.GoodTypeId,
  6126. Count: it.Count,
  6127. Ctime: time.Now().Unix(),
  6128. Creater: adminUser.AdminUser.Id,
  6129. Status: 1,
  6130. StorehouseId: houseConfig.StorehouseOutInfo,
  6131. }
  6132. //删除准备表数据
  6133. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6134. service.CreateDialysisBeforePrepareOne(&prepare)
  6135. }
  6136. }
  6137. var last_total int64
  6138. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6139. if item.Count >= goodInfo.Count {
  6140. //查询当前批次当前耗材最后一条出库数据
  6141. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6142. //计算当前出库和最后一次出库数据相差数据
  6143. last_total = item.Count - lastOutInfo.Count
  6144. //查询该批次剩余库存
  6145. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6146. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6147. if lastInfo.StockCount >= last_total {
  6148. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6149. //查询今日出库数据
  6150. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6151. for _, it := range list {
  6152. prepare := models.DialysisBeforePrepare{
  6153. UserOrgId: it.OrgId,
  6154. PatientId: patient_id,
  6155. RecordDate: it.RecordTime,
  6156. GoodId: it.GoodId,
  6157. GoodTypeId: it.GoodTypeId,
  6158. Count: it.Count,
  6159. Ctime: time.Now().Unix(),
  6160. Creater: adminUser.AdminUser.Id,
  6161. Status: 1,
  6162. StorehouseId: houseConfig.StorehouseOutInfo,
  6163. }
  6164. //删除准备表数据
  6165. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6166. service.CreateDialysisBeforePrepareOne(&prepare)
  6167. //查询默认仓库
  6168. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6169. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6170. var total_count int64
  6171. for _, it := range stockList {
  6172. total_count += it.StockCount
  6173. }
  6174. //基础库插入数据
  6175. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6176. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6177. var flush_count int64
  6178. for _, it := range goodList {
  6179. flush_count += it.StockCount
  6180. }
  6181. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6182. }
  6183. }
  6184. //如果库存不够,则出库到下一个批次
  6185. if lastInfo.StockCount < last_total {
  6186. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6187. //查询今日出库数据
  6188. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6189. for _, it := range list {
  6190. prepare := models.DialysisBeforePrepare{
  6191. UserOrgId: it.OrgId,
  6192. PatientId: patient_id,
  6193. RecordDate: it.RecordTime,
  6194. GoodId: it.GoodId,
  6195. GoodTypeId: it.GoodTypeId,
  6196. Count: it.Count,
  6197. Ctime: time.Now().Unix(),
  6198. Creater: adminUser.AdminUser.Id,
  6199. Status: 1,
  6200. StorehouseId: houseConfig.StorehouseOutInfo,
  6201. }
  6202. //删除准备表数据
  6203. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6204. service.CreateDialysisBeforePrepareOne(&prepare)
  6205. //查询默认仓库
  6206. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6207. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6208. var total_count int64
  6209. for _, it := range stockList {
  6210. total_count += it.StockCount
  6211. }
  6212. //基础库插入数据
  6213. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6214. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6215. var flush_count int64
  6216. for _, it := range goodList {
  6217. flush_count += it.StockCount
  6218. }
  6219. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6220. }
  6221. if err != nil {
  6222. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6223. c.ServeSuccessJSON(map[string]interface{}{
  6224. "message": "1",
  6225. "good_name": goodObj.GoodName,
  6226. "specification_name": goodObj.SpecificationName,
  6227. })
  6228. return
  6229. }
  6230. }
  6231. }
  6232. if err != nil {
  6233. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6234. c.ServeSuccessJSON(map[string]interface{}{
  6235. "message": "1",
  6236. "good_name": goodObj.GoodName,
  6237. "specification_name": goodObj.SpecificationName,
  6238. })
  6239. return
  6240. }
  6241. }
  6242. }
  6243. }
  6244. var errs error
  6245. if errs == nil {
  6246. c.ServeSuccessJSON(map[string]interface{}{
  6247. "msg": "提交成功",
  6248. "message": "2",
  6249. "good_name": "",
  6250. "specification_name": "",
  6251. })
  6252. return
  6253. } else {
  6254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6255. return
  6256. }
  6257. }
  6258. func (c *DialysisAPIController) CreateStockOutInfo() {
  6259. patient_id, _ := c.GetInt64("patient_id", 0)
  6260. record_date := c.GetString("record_time")
  6261. if patient_id <= 0 {
  6262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6263. return
  6264. }
  6265. adminInfo := c.GetMobileAdminUserInfo()
  6266. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6267. timeLayout := "2006-01-02"
  6268. loc, _ := time.LoadLocation("Local")
  6269. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6270. record_time := theRecordTime.Unix()
  6271. // 查询信息规挡的设置天数
  6272. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6273. if infor.ID > 0 && infor.WeekDay > 0 {
  6274. var cha_time int64
  6275. timeNowStr := time.Now().Format("2006-01-02")
  6276. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6277. //今日的日期减去设置的日期
  6278. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6279. if cha_time >= record_time {
  6280. //查询审核是否允许
  6281. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6282. //申请状态不允许的情况 拒绝修改
  6283. if infor.ApplicationStatus != 1 {
  6284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6285. return
  6286. }
  6287. }
  6288. }
  6289. //创建步骤表
  6290. finish := models.XtDialysisFinish{
  6291. IsFinish: 1,
  6292. UserOrgId: adminInfo.Org.Id,
  6293. Status: 1,
  6294. Ctime: time.Now().Unix(),
  6295. Mtime: 0,
  6296. Module: 11,
  6297. RecordDate: record_time,
  6298. Sourse: 1,
  6299. PatientId: patient_id,
  6300. }
  6301. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6302. if dialysisFinish.ID == 0 {
  6303. service.CreateDialysisFinish(finish)
  6304. }
  6305. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6306. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6307. //去重
  6308. consumables = RemoveRepeatedGood(consumables)
  6309. if adminInfo.Org.Id == 9919 {
  6310. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6311. //查询是否有库存
  6312. for _, item := range consumables {
  6313. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6314. if item.Count > warehouse.Count {
  6315. goodErrcode := models.XtGoodErrcode{
  6316. UserOrgId: item.UserOrgId,
  6317. Errcode: "自动出库库存不足",
  6318. GoodId: item.GoodId,
  6319. Status: 1,
  6320. Ctime: time.Now().Unix(),
  6321. Mtime: 0,
  6322. Count: 0,
  6323. StockCount: 0,
  6324. Creater: creator,
  6325. BatchNumberId: warehouse.ID,
  6326. WarehouseOutId: 0,
  6327. }
  6328. service.CreateGoodErrcode(goodErrcode)
  6329. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6330. c.ServeSuccessJSON(map[string]interface{}{
  6331. "message": "1",
  6332. "good_name": goodObj.GoodName,
  6333. "specification_name": goodObj.SpecificationName,
  6334. })
  6335. return
  6336. }
  6337. }
  6338. //查询是否有出库单
  6339. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6340. if err == gorm.ErrRecordNotFound {
  6341. //没有记录,则创建出库单
  6342. timeStr := time.Now().Format("2006-01-02")
  6343. timeArr := strings.Split(timeStr, "-")
  6344. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6345. total = total + 1
  6346. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6347. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6348. number = number + total
  6349. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6350. creater := adminInfo.AdminUser.Id
  6351. warehouseOut := models.WarehouseOut{
  6352. WarehouseOutOrderNumber: warehousing_out_order,
  6353. OperationTime: time.Now().Unix(),
  6354. OrgId: adminInfo.Org.Id,
  6355. Creater: creater,
  6356. Ctime: time.Now().Unix(),
  6357. Status: 1,
  6358. WarehouseOutTime: record_time,
  6359. Dealer: 0,
  6360. Manufacturer: 0,
  6361. Type: 1,
  6362. IsSys: 1,
  6363. StorehouseId: houseConfig.StorehouseOutInfo,
  6364. IsCheck: 1,
  6365. }
  6366. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6367. if err != nil {
  6368. goodErrcode := models.XtGoodErrcode{
  6369. UserOrgId: adminInfo.Org.Id,
  6370. Errcode: "创建出库单失败",
  6371. GoodId: 0,
  6372. Status: 1,
  6373. Ctime: time.Now().Unix(),
  6374. Mtime: 0,
  6375. Count: 0,
  6376. StockCount: 0,
  6377. Creater: creator,
  6378. BatchNumberId: 0,
  6379. WarehouseOutId: 0,
  6380. }
  6381. service.CreateGoodErrcode(goodErrcode)
  6382. utils.TraceLog("创建出库单失败 err = %v", err)
  6383. } else {
  6384. for _, item := range consumables {
  6385. //出库
  6386. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6387. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6388. if err == nil {
  6389. goodErrcode := models.XtGoodErrcode{
  6390. UserOrgId: adminInfo.Org.Id,
  6391. Errcode: "自动出库接口报错",
  6392. GoodId: 0,
  6393. Status: 1,
  6394. Ctime: time.Now().Unix(),
  6395. Mtime: 0,
  6396. Count: 0,
  6397. StockCount: 0,
  6398. Creater: creator,
  6399. BatchNumberId: 0,
  6400. WarehouseOutId: 0,
  6401. }
  6402. service.CreateGoodErrcode(goodErrcode)
  6403. utils.TraceLog("创建出库单失败 err = %v", err)
  6404. }
  6405. //查询
  6406. //出库数量相加
  6407. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6408. if errs != nil {
  6409. goodErrcode := models.XtGoodErrcode{
  6410. UserOrgId: item.UserOrgId,
  6411. Errcode: "创建剩余库存字段报错",
  6412. GoodId: item.GoodId,
  6413. Status: 1,
  6414. Ctime: time.Now().Unix(),
  6415. Mtime: 0,
  6416. Count: 0,
  6417. StockCount: 0,
  6418. Creater: creater,
  6419. BatchNumberId: 0,
  6420. WarehouseOutId: 0,
  6421. }
  6422. service.CreateGoodErrcode(goodErrcode)
  6423. }
  6424. }
  6425. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6426. if len(list) == 0 {
  6427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6428. return
  6429. }
  6430. for _, item := range list {
  6431. prepare := models.DialysisBeforePrepare{
  6432. UserOrgId: adminInfo.Org.Id,
  6433. PatientId: patient_id,
  6434. RecordDate: record_time,
  6435. GoodId: item.GoodId,
  6436. GoodTypeId: item.GoodTypeId,
  6437. Count: item.Count,
  6438. Creater: adminInfo.AdminUser.Id,
  6439. Status: 1,
  6440. Ctime: time.Now().Unix(),
  6441. StorehouseId: houseConfig.StorehouseOutInfo,
  6442. }
  6443. //清空准备表数据
  6444. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6445. if err != nil {
  6446. goodErrcode := models.XtGoodErrcode{
  6447. UserOrgId: item.OrgId,
  6448. Errcode: "自动出库清空准备表数据报错",
  6449. GoodId: item.GoodId,
  6450. Status: 1,
  6451. Ctime: time.Now().Unix(),
  6452. Mtime: 0,
  6453. Count: 0,
  6454. StockCount: 0,
  6455. Creater: creater,
  6456. BatchNumberId: 0,
  6457. WarehouseOutId: 0,
  6458. }
  6459. service.CreateGoodErrcode(goodErrcode)
  6460. }
  6461. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6462. if errs != nil {
  6463. goodErrcode := models.XtGoodErrcode{
  6464. UserOrgId: item.OrgId,
  6465. Errcode: "自动出库创建准备表数据报错",
  6466. GoodId: item.GoodId,
  6467. Status: 1,
  6468. Ctime: time.Now().Unix(),
  6469. Mtime: 0,
  6470. Count: 0,
  6471. StockCount: 0,
  6472. Creater: creater,
  6473. BatchNumberId: 0,
  6474. WarehouseOutId: 0,
  6475. }
  6476. service.CreateGoodErrcode(goodErrcode)
  6477. }
  6478. //查询默认仓库
  6479. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6480. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6481. var total_count int64
  6482. for _, it := range stockList {
  6483. total_count += it.StockCount
  6484. }
  6485. //基础库插入数据
  6486. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6487. if errcodes != nil {
  6488. goodErrcode := models.XtGoodErrcode{
  6489. UserOrgId: item.OrgId,
  6490. Errcode: "自动出库基础库插入数据",
  6491. GoodId: item.GoodId,
  6492. Status: 1,
  6493. Ctime: time.Now().Unix(),
  6494. Mtime: 0,
  6495. Count: 0,
  6496. StockCount: 0,
  6497. Creater: creater,
  6498. BatchNumberId: 0,
  6499. WarehouseOutId: 0,
  6500. }
  6501. service.CreateGoodErrcode(goodErrcode)
  6502. }
  6503. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6504. var flush_count int64
  6505. for _, it := range goodList {
  6506. flush_count += it.StockCount
  6507. }
  6508. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6509. if errsss != nil {
  6510. goodErrcode := models.XtGoodErrcode{
  6511. UserOrgId: item.OrgId,
  6512. Errcode: "自动出库剩余库存更新数据",
  6513. GoodId: item.GoodId,
  6514. Status: 1,
  6515. Ctime: time.Now().Unix(),
  6516. Mtime: 0,
  6517. Count: 0,
  6518. StockCount: 0,
  6519. Creater: creater,
  6520. BatchNumberId: 0,
  6521. WarehouseOutId: 0,
  6522. }
  6523. service.CreateGoodErrcode(goodErrcode)
  6524. }
  6525. }
  6526. }
  6527. //
  6528. } else if err == nil {
  6529. for _, item := range consumables {
  6530. //出库
  6531. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6532. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6533. if err != nil {
  6534. goodErrcode := models.XtGoodErrcode{
  6535. UserOrgId: adminInfo.Org.Id,
  6536. Errcode: "自动出库接口报错",
  6537. GoodId: 0,
  6538. Status: 1,
  6539. Ctime: time.Now().Unix(),
  6540. Mtime: 0,
  6541. Count: 0,
  6542. StockCount: 0,
  6543. Creater: creator,
  6544. BatchNumberId: 0,
  6545. WarehouseOutId: 0,
  6546. }
  6547. service.CreateGoodErrcode(goodErrcode)
  6548. }
  6549. //出库数量相加
  6550. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6551. if errss != nil {
  6552. goodErrcode := models.XtGoodErrcode{
  6553. UserOrgId: item.UserOrgId,
  6554. Errcode: "创建剩余库存字段报错",
  6555. GoodId: item.GoodId,
  6556. Status: 1,
  6557. Ctime: time.Now().Unix(),
  6558. Mtime: time.Now().Unix(),
  6559. Count: 0,
  6560. StockCount: 0,
  6561. Creater: item.Creater,
  6562. BatchNumberId: 0,
  6563. WarehouseOutId: 0,
  6564. }
  6565. service.CreateGoodErrcode(goodErrcode)
  6566. }
  6567. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6568. if len(list) == 0 {
  6569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6570. return
  6571. }
  6572. for _, item := range list {
  6573. prepare := models.DialysisBeforePrepare{
  6574. UserOrgId: adminInfo.Org.Id,
  6575. PatientId: patient_id,
  6576. RecordDate: record_time,
  6577. GoodId: item.GoodId,
  6578. GoodTypeId: item.GoodTypeId,
  6579. Count: item.Count,
  6580. Creater: adminInfo.AdminUser.Id,
  6581. Status: 1,
  6582. Ctime: time.Now().Unix(),
  6583. StorehouseId: houseConfig.StorehouseOutInfo,
  6584. }
  6585. //清空准备表数据
  6586. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6587. if errs != nil {
  6588. goodErrcode := models.XtGoodErrcode{
  6589. UserOrgId: adminInfo.Org.Id,
  6590. Errcode: "自动出库清空准备表数据报错",
  6591. GoodId: 0,
  6592. Status: 1,
  6593. Ctime: time.Now().Unix(),
  6594. Mtime: 0,
  6595. Count: 0,
  6596. StockCount: 0,
  6597. Creater: creator,
  6598. BatchNumberId: 0,
  6599. WarehouseOutId: 0,
  6600. }
  6601. service.CreateGoodErrcode(goodErrcode)
  6602. }
  6603. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6604. if errcodes != nil {
  6605. goodErrcode := models.XtGoodErrcode{
  6606. UserOrgId: adminInfo.Org.Id,
  6607. Errcode: "自动出库创建准备表数据报错",
  6608. GoodId: 0,
  6609. Status: 1,
  6610. Ctime: time.Now().Unix(),
  6611. Mtime: 0,
  6612. Count: 0,
  6613. StockCount: 0,
  6614. Creater: creator,
  6615. BatchNumberId: 0,
  6616. WarehouseOutId: 0,
  6617. }
  6618. service.CreateGoodErrcode(goodErrcode)
  6619. }
  6620. //查询默认仓库
  6621. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6622. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6623. var total_count int64
  6624. for _, it := range stockList {
  6625. total_count += it.StockCount
  6626. }
  6627. //基础库插入数据
  6628. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6629. if errcodes != nil {
  6630. goodErrcode := models.XtGoodErrcode{
  6631. UserOrgId: adminInfo.Org.Id,
  6632. Errcode: "自动出库基础库插入数据报错",
  6633. GoodId: 0,
  6634. Status: 1,
  6635. Ctime: time.Now().Unix(),
  6636. Mtime: 0,
  6637. Count: 0,
  6638. StockCount: 0,
  6639. Creater: creator,
  6640. BatchNumberId: 0,
  6641. WarehouseOutId: 0,
  6642. }
  6643. service.CreateGoodErrcode(goodErrcode)
  6644. }
  6645. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6646. var flush_count int64
  6647. for _, it := range goodList {
  6648. flush_count += it.StockCount
  6649. }
  6650. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6651. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6652. if errss != nil {
  6653. goodErrcode := models.XtGoodErrcode{
  6654. UserOrgId: item.OrgId,
  6655. Errcode: "自动出库剩余库存更新数据",
  6656. GoodId: item.GoodId,
  6657. Status: 1,
  6658. Ctime: time.Now().Unix(),
  6659. Mtime: 0,
  6660. Count: 0,
  6661. StockCount: 0,
  6662. Creater: creater,
  6663. BatchNumberId: 0,
  6664. WarehouseOutId: 0,
  6665. }
  6666. service.CreateGoodErrcode(goodErrcode)
  6667. }
  6668. }
  6669. }
  6670. }
  6671. c.ServeSuccessJSON(map[string]interface{}{
  6672. "msg": "提交成功",
  6673. "message": "2",
  6674. "good_name": "",
  6675. "specification_name": "",
  6676. })
  6677. return
  6678. }
  6679. if record.IsOpen == 1 {
  6680. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6681. //查询是否有库存
  6682. for _, item := range consumables {
  6683. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6684. if item.Count > warehouse.Count {
  6685. goodErrcode := models.XtGoodErrcode{
  6686. UserOrgId: item.UserOrgId,
  6687. Errcode: "自动出库库存不足",
  6688. GoodId: item.GoodId,
  6689. Status: 1,
  6690. Ctime: time.Now().Unix(),
  6691. Mtime: 0,
  6692. Count: 0,
  6693. StockCount: 0,
  6694. Creater: creator,
  6695. BatchNumberId: warehouse.ID,
  6696. WarehouseOutId: 0,
  6697. }
  6698. service.CreateGoodErrcode(goodErrcode)
  6699. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6700. c.ServeSuccessJSON(map[string]interface{}{
  6701. "message": "1",
  6702. "good_name": goodObj.GoodName,
  6703. "specification_name": goodObj.SpecificationName,
  6704. })
  6705. return
  6706. }
  6707. }
  6708. //查询是否有出库单
  6709. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6710. if err == gorm.ErrRecordNotFound {
  6711. //没有记录,则创建出库单
  6712. timeStr := time.Now().Format("2006-01-02")
  6713. timeArr := strings.Split(timeStr, "-")
  6714. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6715. total = total + 1
  6716. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6717. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6718. number = number + total
  6719. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6720. creater := adminInfo.AdminUser.Id
  6721. warehouseOut := models.WarehouseOut{
  6722. WarehouseOutOrderNumber: warehousing_out_order,
  6723. OperationTime: time.Now().Unix(),
  6724. OrgId: adminInfo.Org.Id,
  6725. Creater: creater,
  6726. Ctime: time.Now().Unix(),
  6727. Status: 1,
  6728. WarehouseOutTime: record_time,
  6729. Dealer: 0,
  6730. Manufacturer: 0,
  6731. Type: 1,
  6732. IsSys: 1,
  6733. StorehouseId: houseConfig.StorehouseOutInfo,
  6734. IsCheck: 1,
  6735. }
  6736. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6737. if err != nil {
  6738. goodErrcode := models.XtGoodErrcode{
  6739. UserOrgId: adminInfo.Org.Id,
  6740. Errcode: "创建出库单失败",
  6741. GoodId: 0,
  6742. Status: 1,
  6743. Ctime: time.Now().Unix(),
  6744. Mtime: 0,
  6745. Count: 0,
  6746. StockCount: 0,
  6747. Creater: creator,
  6748. BatchNumberId: 0,
  6749. WarehouseOutId: 0,
  6750. }
  6751. service.CreateGoodErrcode(goodErrcode)
  6752. utils.TraceLog("创建出库单失败 err = %v", err)
  6753. } else {
  6754. for _, item := range consumables {
  6755. //出库
  6756. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6757. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6758. if err == nil {
  6759. goodErrcode := models.XtGoodErrcode{
  6760. UserOrgId: adminInfo.Org.Id,
  6761. Errcode: "自动出库接口报错",
  6762. GoodId: 0,
  6763. Status: 1,
  6764. Ctime: time.Now().Unix(),
  6765. Mtime: 0,
  6766. Count: 0,
  6767. StockCount: 0,
  6768. Creater: creator,
  6769. BatchNumberId: 0,
  6770. WarehouseOutId: 0,
  6771. }
  6772. service.CreateGoodErrcode(goodErrcode)
  6773. utils.TraceLog("创建出库单失败 err = %v", err)
  6774. }
  6775. //查询
  6776. //出库数量相加
  6777. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6778. if errs != nil {
  6779. goodErrcode := models.XtGoodErrcode{
  6780. UserOrgId: item.UserOrgId,
  6781. Errcode: "创建剩余库存字段报错",
  6782. GoodId: item.GoodId,
  6783. Status: 1,
  6784. Ctime: time.Now().Unix(),
  6785. Mtime: 0,
  6786. Count: 0,
  6787. StockCount: 0,
  6788. Creater: creater,
  6789. BatchNumberId: 0,
  6790. WarehouseOutId: 0,
  6791. }
  6792. service.CreateGoodErrcode(goodErrcode)
  6793. }
  6794. }
  6795. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6796. if len(list) == 0 {
  6797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6798. return
  6799. }
  6800. for _, item := range list {
  6801. prepare := models.DialysisBeforePrepare{
  6802. UserOrgId: adminInfo.Org.Id,
  6803. PatientId: patient_id,
  6804. RecordDate: record_time,
  6805. GoodId: item.GoodId,
  6806. GoodTypeId: item.GoodTypeId,
  6807. Count: item.Count,
  6808. Creater: adminInfo.AdminUser.Id,
  6809. Status: 1,
  6810. Ctime: time.Now().Unix(),
  6811. StorehouseId: houseConfig.StorehouseOutInfo,
  6812. }
  6813. //清空准备表数据
  6814. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6815. if err != nil {
  6816. goodErrcode := models.XtGoodErrcode{
  6817. UserOrgId: item.OrgId,
  6818. Errcode: "自动出库清空准备表数据报错",
  6819. GoodId: item.GoodId,
  6820. Status: 1,
  6821. Ctime: time.Now().Unix(),
  6822. Mtime: 0,
  6823. Count: 0,
  6824. StockCount: 0,
  6825. Creater: creater,
  6826. BatchNumberId: 0,
  6827. WarehouseOutId: 0,
  6828. }
  6829. service.CreateGoodErrcode(goodErrcode)
  6830. }
  6831. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6832. if errs != nil {
  6833. goodErrcode := models.XtGoodErrcode{
  6834. UserOrgId: item.OrgId,
  6835. Errcode: "自动出库创建准备表数据报错",
  6836. GoodId: item.GoodId,
  6837. Status: 1,
  6838. Ctime: time.Now().Unix(),
  6839. Mtime: 0,
  6840. Count: 0,
  6841. StockCount: 0,
  6842. Creater: creater,
  6843. BatchNumberId: 0,
  6844. WarehouseOutId: 0,
  6845. }
  6846. service.CreateGoodErrcode(goodErrcode)
  6847. }
  6848. //查询默认仓库
  6849. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6850. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6851. var total_count int64
  6852. for _, it := range stockList {
  6853. total_count += it.StockCount
  6854. }
  6855. //基础库插入数据
  6856. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6857. if errcodes != nil {
  6858. goodErrcode := models.XtGoodErrcode{
  6859. UserOrgId: item.OrgId,
  6860. Errcode: "自动出库基础库插入数据",
  6861. GoodId: item.GoodId,
  6862. Status: 1,
  6863. Ctime: time.Now().Unix(),
  6864. Mtime: 0,
  6865. Count: 0,
  6866. StockCount: 0,
  6867. Creater: creater,
  6868. BatchNumberId: 0,
  6869. WarehouseOutId: 0,
  6870. }
  6871. service.CreateGoodErrcode(goodErrcode)
  6872. }
  6873. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6874. var flush_count int64
  6875. for _, it := range goodList {
  6876. flush_count += it.StockCount
  6877. }
  6878. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6879. if errsss != nil {
  6880. goodErrcode := models.XtGoodErrcode{
  6881. UserOrgId: item.OrgId,
  6882. Errcode: "自动出库剩余库存更新数据",
  6883. GoodId: item.GoodId,
  6884. Status: 1,
  6885. Ctime: time.Now().Unix(),
  6886. Mtime: 0,
  6887. Count: 0,
  6888. StockCount: 0,
  6889. Creater: creater,
  6890. BatchNumberId: 0,
  6891. WarehouseOutId: 0,
  6892. }
  6893. service.CreateGoodErrcode(goodErrcode)
  6894. }
  6895. }
  6896. }
  6897. //
  6898. } else if err == nil {
  6899. for _, item := range consumables {
  6900. //出库
  6901. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6902. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6903. if err != nil {
  6904. goodErrcode := models.XtGoodErrcode{
  6905. UserOrgId: adminInfo.Org.Id,
  6906. Errcode: "自动出库接口报错",
  6907. GoodId: 0,
  6908. Status: 1,
  6909. Ctime: time.Now().Unix(),
  6910. Mtime: 0,
  6911. Count: 0,
  6912. StockCount: 0,
  6913. Creater: creator,
  6914. BatchNumberId: 0,
  6915. WarehouseOutId: 0,
  6916. }
  6917. service.CreateGoodErrcode(goodErrcode)
  6918. }
  6919. //出库数量相加
  6920. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6921. if errss != nil {
  6922. goodErrcode := models.XtGoodErrcode{
  6923. UserOrgId: item.UserOrgId,
  6924. Errcode: "创建剩余库存字段报错",
  6925. GoodId: item.GoodId,
  6926. Status: 1,
  6927. Ctime: time.Now().Unix(),
  6928. Mtime: time.Now().Unix(),
  6929. Count: 0,
  6930. StockCount: 0,
  6931. Creater: item.Creater,
  6932. BatchNumberId: 0,
  6933. WarehouseOutId: 0,
  6934. }
  6935. service.CreateGoodErrcode(goodErrcode)
  6936. }
  6937. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6938. if len(list) == 0 {
  6939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6940. return
  6941. }
  6942. for _, item := range list {
  6943. prepare := models.DialysisBeforePrepare{
  6944. UserOrgId: adminInfo.Org.Id,
  6945. PatientId: patient_id,
  6946. RecordDate: record_time,
  6947. GoodId: item.GoodId,
  6948. GoodTypeId: item.GoodTypeId,
  6949. Count: item.Count,
  6950. Creater: adminInfo.AdminUser.Id,
  6951. Status: 1,
  6952. Ctime: time.Now().Unix(),
  6953. StorehouseId: houseConfig.StorehouseOutInfo,
  6954. }
  6955. //清空准备表数据
  6956. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6957. if errs != nil {
  6958. goodErrcode := models.XtGoodErrcode{
  6959. UserOrgId: adminInfo.Org.Id,
  6960. Errcode: "自动出库清空准备表数据报错",
  6961. GoodId: 0,
  6962. Status: 1,
  6963. Ctime: time.Now().Unix(),
  6964. Mtime: 0,
  6965. Count: 0,
  6966. StockCount: 0,
  6967. Creater: creator,
  6968. BatchNumberId: 0,
  6969. WarehouseOutId: 0,
  6970. }
  6971. service.CreateGoodErrcode(goodErrcode)
  6972. }
  6973. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6974. if errcodes != nil {
  6975. goodErrcode := models.XtGoodErrcode{
  6976. UserOrgId: adminInfo.Org.Id,
  6977. Errcode: "自动出库创建准备表数据报错",
  6978. GoodId: 0,
  6979. Status: 1,
  6980. Ctime: time.Now().Unix(),
  6981. Mtime: 0,
  6982. Count: 0,
  6983. StockCount: 0,
  6984. Creater: creator,
  6985. BatchNumberId: 0,
  6986. WarehouseOutId: 0,
  6987. }
  6988. service.CreateGoodErrcode(goodErrcode)
  6989. }
  6990. //查询默认仓库
  6991. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6992. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6993. var total_count int64
  6994. for _, it := range stockList {
  6995. total_count += it.StockCount
  6996. }
  6997. //基础库插入数据
  6998. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6999. if errcodes != nil {
  7000. goodErrcode := models.XtGoodErrcode{
  7001. UserOrgId: adminInfo.Org.Id,
  7002. Errcode: "自动出库基础库插入数据报错",
  7003. GoodId: 0,
  7004. Status: 1,
  7005. Ctime: time.Now().Unix(),
  7006. Mtime: 0,
  7007. Count: 0,
  7008. StockCount: 0,
  7009. Creater: creator,
  7010. BatchNumberId: 0,
  7011. WarehouseOutId: 0,
  7012. }
  7013. service.CreateGoodErrcode(goodErrcode)
  7014. }
  7015. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7016. var flush_count int64
  7017. for _, it := range goodList {
  7018. flush_count += it.StockCount
  7019. }
  7020. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7021. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7022. if errss != nil {
  7023. goodErrcode := models.XtGoodErrcode{
  7024. UserOrgId: item.OrgId,
  7025. Errcode: "自动出库剩余库存更新数据",
  7026. GoodId: item.GoodId,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Count: 0,
  7031. StockCount: 0,
  7032. Creater: creater,
  7033. BatchNumberId: 0,
  7034. WarehouseOutId: 0,
  7035. }
  7036. service.CreateGoodErrcode(goodErrcode)
  7037. }
  7038. }
  7039. }
  7040. }
  7041. c.ServeSuccessJSON(map[string]interface{}{
  7042. "msg": "提交成功",
  7043. "message": "2",
  7044. "good_name": "",
  7045. "specification_name": "",
  7046. })
  7047. return
  7048. } else {
  7049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7050. return
  7051. }
  7052. }
  7053. func (c *DialysisAPIController) EditConsumables() {
  7054. patient_id, _ := c.GetInt64("patient_id", 0)
  7055. record_date := c.GetString("record_time")
  7056. if patient_id <= 0 {
  7057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7058. return
  7059. }
  7060. adminInfo := c.GetMobileAdminUserInfo()
  7061. timeLayout := "2006-01-02"
  7062. loc, _ := time.LoadLocation("Local")
  7063. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7064. record_time := theRecordTime.Unix()
  7065. // 查询信息规挡的设置天数
  7066. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7067. if infor.ID > 0 && infor.WeekDay > 0 {
  7068. var cha_time int64
  7069. timeNowStr := time.Now().Format("2006-01-02")
  7070. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7071. //今日的日期减去设置的日期
  7072. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7073. if cha_time >= record_time {
  7074. //查询审核是否允许
  7075. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7076. //申请状态不允许的情况 拒绝修改
  7077. if infor.ApplicationStatus != 1 {
  7078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7079. return
  7080. }
  7081. }
  7082. }
  7083. dataBody := make(map[string]interface{}, 0)
  7084. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7085. if err != nil {
  7086. utils.ErrorLog(err.Error())
  7087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7088. return
  7089. }
  7090. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7091. var beforePrepares []*models.DialysisBeforePrepareGoods
  7092. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7093. var cancelbefor []*models.DialysisBeforePrepareGoods
  7094. var outbefor []*models.DialysisBeforePrepareGoods
  7095. //判断是否开启自动出库
  7096. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7097. if record.IsOpen == 1 {
  7098. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7099. goods, _ := dataBody["goods"].([]interface{})
  7100. if len(goods) > 0 {
  7101. for _, item := range goods {
  7102. items := item.(map[string]interface{})
  7103. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7104. utils.ErrorLog("good_id")
  7105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7106. return
  7107. }
  7108. good_id := int64(items["good_id"].(float64))
  7109. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7110. utils.ErrorLog("good_type_id")
  7111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7112. return
  7113. }
  7114. good_type_id := int64(items["good_type_id"].(float64))
  7115. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7116. utils.ErrorLog("count")
  7117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7118. return
  7119. }
  7120. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7121. commdity_code := items["commdity_code"].(string)
  7122. fmt.Println(commdity_code)
  7123. prepareGoods := &models.DialysisBeforePrepareGoods{
  7124. GoodTypeId: good_type_id,
  7125. GoodId: good_id,
  7126. Count: count,
  7127. StorehouseId: houseConfig.StorehouseOutInfo,
  7128. }
  7129. beforePrepares = append(beforePrepares, prepareGoods)
  7130. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7131. GoodTypeId: good_type_id,
  7132. GoodId: good_id,
  7133. Count: count,
  7134. StorehouseId: houseConfig.StorehouseOutInfo,
  7135. }
  7136. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7137. }
  7138. for _, item := range beforePrepares {
  7139. //1.查看该患者该耗材型号最后一次出库数量
  7140. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7141. //判断当前出库数量和最后一次出库数量的大小
  7142. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7143. if item.Count < goodInfo.Count {
  7144. cancelbefor = append(cancelbefor, item)
  7145. }
  7146. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7147. if item.Count > goodInfo.Count {
  7148. outbefor = append(outbefor, item)
  7149. }
  7150. //处理编辑耗材新增不了的问题
  7151. if goodInfo.Count == item.Count {
  7152. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7153. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7154. }
  7155. }
  7156. if len(cancelbefor) > 0 {
  7157. //退库
  7158. for _, item := range cancelbefor {
  7159. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7160. creater := adminInfo.AdminUser.Id
  7161. //查询该患者当天已经出库的耗材信息
  7162. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7163. var delete_count int64 = 0
  7164. delete_count = warehouseOutInfos.Count - item.Count
  7165. //增加库存数量
  7166. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7167. //减少实际出库库存数量
  7168. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7169. // 删除出库完成后,要增加对应批次的库存数量
  7170. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7171. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7172. //更新剩余库存
  7173. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7174. var flush_count int64
  7175. for _, it := range goodListOne {
  7176. flush_count += it.StockCount
  7177. }
  7178. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7179. //查询剩余库存
  7180. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7181. var sum_count int64
  7182. for _, item := range goodList {
  7183. sum_count += item.StockCount
  7184. }
  7185. // 在出库记录表里记录退库详情
  7186. warehouseOutInfo := &models.WarehouseOutInfo{
  7187. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7188. WarehouseOutId: warehouseOut.ID,
  7189. Status: 1,
  7190. Ctime: time.Now().Unix(),
  7191. OrgId: adminInfo.Org.Id,
  7192. Type: 1,
  7193. IsSys: 1,
  7194. SysRecordTime: record_time,
  7195. GoodTypeId: item.GoodTypeId,
  7196. GoodId: item.GoodId,
  7197. PatientId: patient_id,
  7198. ConsumableType: 2,
  7199. StorehouseId: houseConfig.StorehouseOutInfo,
  7200. IsCheck: 1,
  7201. OverCount: sum_count,
  7202. }
  7203. warehouseOutInfo.Count = item.Count
  7204. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7205. warehouseOutInfo.Price = stockInInfo.Price
  7206. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7207. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7208. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7209. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7210. warehouseOutInfo.Number = warehouseOutInfos.Number
  7211. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7212. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7213. //查找当天是否存在出库记录
  7214. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7215. if errcod == gorm.ErrRecordNotFound {
  7216. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7217. //插入详情明细表
  7218. stockFlow := models.VmStockFlow{
  7219. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7220. WarehouseOutId: warehouseOut.ID,
  7221. GoodId: item.GoodId,
  7222. Number: warehouseOutInfos.Number,
  7223. ProductDate: stockInInfo.ProductDate,
  7224. ExpireDate: stockInInfo.ExpiryDate,
  7225. Count: item.Count,
  7226. Price: stockInInfo.Price,
  7227. Status: 1,
  7228. Ctime: record_time,
  7229. UserOrgId: adminInfo.Org.Id,
  7230. Manufacturer: stockInInfo.Manufacturer,
  7231. Dealer: stockInInfo.Dealer,
  7232. LicenseNumber: stockInInfo.LicenseNumber,
  7233. IsEdit: 2,
  7234. Creator: creater,
  7235. SystemTime: record_time,
  7236. ConsumableType: 3,
  7237. WarehousingDetailId: 0,
  7238. IsSys: 1,
  7239. UpdateCreator: creater,
  7240. PatientId: patient_id,
  7241. StorehouseId: houseConfig.StorehouseOutInfo,
  7242. }
  7243. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7244. if errflow == gorm.ErrRecordNotFound {
  7245. //创建流水表
  7246. err := service.CreateStockFlowOne(stockFlow)
  7247. fmt.Println("err", err)
  7248. } else if errflow == nil {
  7249. //插入详情明细表
  7250. stockFlow := models.VmStockFlow{
  7251. ID: exsit.ID,
  7252. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7253. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7254. WarehouseOutId: warehouseOut.ID,
  7255. GoodId: item.GoodId,
  7256. Number: warehouseOutInfos.Number,
  7257. ProductDate: stockInInfo.ProductDate,
  7258. ExpireDate: stockInInfo.ExpiryDate,
  7259. Count: exsit.Count - delete_count,
  7260. Price: stockInInfo.Price,
  7261. Status: 1,
  7262. Ctime: record_time,
  7263. UserOrgId: adminInfo.Org.Id,
  7264. Manufacturer: stockInInfo.Manufacturer,
  7265. Dealer: stockInInfo.Dealer,
  7266. LicenseNumber: stockInInfo.LicenseNumber,
  7267. IsEdit: 2,
  7268. Creator: creater,
  7269. SystemTime: record_time,
  7270. ConsumableType: 3,
  7271. WarehousingDetailId: 0,
  7272. IsSys: 1,
  7273. UpdateCreator: creater,
  7274. PatientId: patient_id,
  7275. StorehouseId: houseConfig.StorehouseOutInfo,
  7276. }
  7277. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7278. }
  7279. } else if errcod == nil {
  7280. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7281. //查询剩余库存
  7282. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7283. var sum_count int64
  7284. for _, item := range goodList {
  7285. sum_count += item.StockCount
  7286. }
  7287. //创建退库单,生成退库数据
  7288. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7289. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7290. operation_time := time.Now().Unix()
  7291. creater := adminInfo.AdminUser.Id
  7292. //创建退库单
  7293. timeStr := time.Now().Format("2006-01-02")
  7294. timeArr := strings.Split(timeStr, "-")
  7295. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7296. total = total + 1
  7297. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7298. cancelStock := models.CancelStock{
  7299. OrderNumber: orderNumber,
  7300. OperaTime: operation_time,
  7301. OrgId: adminInfo.Org.Id,
  7302. Creater: creater,
  7303. Ctime: time.Now().Unix(),
  7304. Status: 1,
  7305. ReturnTime: record_time,
  7306. Type: 1,
  7307. StorehouseId: houseConfig.StorehouseOutInfo,
  7308. IsCheck: 1,
  7309. }
  7310. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7311. if msgerrkonde == gorm.ErrRecordNotFound {
  7312. service.AddSigleCancelStock(&cancelStock)
  7313. }
  7314. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7315. //查询是否有出库
  7316. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7317. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7318. deaerler, _ := service.GetDealerById(info.Dealer)
  7319. if info.ID > 0 {
  7320. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7321. cancelStockInfo := models.CancelStockInfo{
  7322. GoodId: item.GoodId,
  7323. CancelStockId: cancel.ID,
  7324. GoodTypeId: good.GoodTypeId,
  7325. Count: delete_count,
  7326. Price: info.Price,
  7327. Total: 0,
  7328. ProductDate: info.ProductDate,
  7329. ExpiryDate: info.ExpiryDate,
  7330. Ctime: time.Now().Unix(),
  7331. Status: 1,
  7332. OrgId: adminInfo.Org.Id,
  7333. OrderNumber: cancel.OrderNumber,
  7334. Type: 0,
  7335. Dealer: deaerler.DealerName,
  7336. Manufacturer: manufacturer.ManufacturerName,
  7337. Number: info.Number,
  7338. RegisterAccount: "",
  7339. Remark: "",
  7340. WarehouseInfoId: info.WarehouseInfotId,
  7341. PatientId: info.PatientId,
  7342. RecordDate: info.SysRecordTime,
  7343. StorehouseId: houseConfig.StorehouseOutInfo,
  7344. IsCheck: 1,
  7345. }
  7346. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7347. //退库数量增加
  7348. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7349. //查询剩余库存
  7350. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7351. var over_count int64
  7352. for _, it := range goodList {
  7353. over_count += it.StockCount
  7354. }
  7355. flow := models.VmStockFlow{
  7356. WarehousingId: info.WarehouseInfotId,
  7357. GoodId: item.GoodId,
  7358. Number: info.Number,
  7359. LicenseNumber: info.LicenseNumber,
  7360. Count: delete_count,
  7361. UserOrgId: adminInfo.Org.Id,
  7362. PatientId: patient_id,
  7363. SystemTime: info.SysRecordTime,
  7364. ConsumableType: 7,
  7365. IsSys: 0,
  7366. WarehousingOrder: "",
  7367. WarehouseOutId: info.WarehouseOutId,
  7368. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7369. IsEdit: 0,
  7370. CancelStockId: cancel.ID,
  7371. CancelOrderNumber: cancel.OrderNumber,
  7372. Manufacturer: manufacturer.ID,
  7373. Dealer: 0,
  7374. Creator: adminInfo.AdminUser.Id,
  7375. UpdateCreator: 0,
  7376. Status: 1,
  7377. Ctime: record_time,
  7378. Mtime: 0,
  7379. Price: info.Price,
  7380. WarehousingDetailId: info.WarehouseInfotId,
  7381. WarehouseOutDetailId: info.ID,
  7382. CancelOutDetailId: cancelInfo.ID,
  7383. ProductDate: info.ProductDate,
  7384. ExpireDate: info.ExpiryDate,
  7385. StorehouseId: houseConfig.StorehouseOutInfo,
  7386. OverCount: over_count,
  7387. }
  7388. service.CreateStockFlowOne(flow)
  7389. }
  7390. }
  7391. //更改自动出库的表格
  7392. details := models.BloodAutomaticReduceDetail{
  7393. WarehouseOutId: warehouseOutInfo.ID,
  7394. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7395. PatientId: patient_id,
  7396. Ctime: time.Now().Unix(),
  7397. Mtime: time.Now().Unix(),
  7398. Status: 1,
  7399. RecordTime: record_time,
  7400. OrgId: adminInfo.Org.Id,
  7401. GoodId: item.GoodId,
  7402. GoodTypeId: item.GoodTypeId,
  7403. Count: item.Count,
  7404. StorehouseId: houseConfig.StorehouseOutInfo,
  7405. }
  7406. //查询当天耗材是否已经存在数据
  7407. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7408. if errcode == gorm.ErrRecordNotFound {
  7409. service.CreateAutoReduceRecord(&details)
  7410. } else if errcode == nil {
  7411. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7412. service.CreateAutoReduceRecord(&details)
  7413. }
  7414. //查询默认仓库
  7415. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7416. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7417. var total_count int64
  7418. for _, it := range stockList {
  7419. total_count += it.StockCount
  7420. }
  7421. //基础库插入数据
  7422. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7423. }
  7424. }
  7425. if len(outbefor) > 0 {
  7426. //出库
  7427. for _, item := range outbefor {
  7428. var last_total int64
  7429. //1.查看该患者该耗材型号最后一次出库数量
  7430. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7431. //计算当前出库和最后一次出库数据相差数据
  7432. last_total = item.Count - goodInfoOne.Count
  7433. //查询该耗材的总库存
  7434. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7435. // 如果库存差大于剩余库存则提示库存不足
  7436. if last_total > wareinfo.StockCount {
  7437. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7438. c.ServeSuccessJSON(map[string]interface{}{
  7439. "message": "1",
  7440. "good_name": goodObj.GoodName,
  7441. "specification_name": goodObj.SpecificationName,
  7442. })
  7443. return
  7444. } else {
  7445. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7446. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7447. if err == gorm.ErrRecordNotFound {
  7448. //没有记录,则创建出库单
  7449. timeStr := time.Now().Format("2006-01-02")
  7450. timeArr := strings.Split(timeStr, "-")
  7451. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7452. total = total + 1
  7453. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7454. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7455. number = number + total
  7456. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7457. warehouseOut := models.WarehouseOut{
  7458. WarehouseOutOrderNumber: warehousing_out_order,
  7459. OperationTime: time.Now().Unix(),
  7460. OrgId: adminInfo.Org.Id,
  7461. Creater: adminInfo.AdminUser.Id,
  7462. Ctime: time.Now().Unix(),
  7463. Status: 1,
  7464. WarehouseOutTime: record_time,
  7465. Dealer: 0,
  7466. Manufacturer: 0,
  7467. Type: 1,
  7468. IsSys: 1,
  7469. StorehouseId: houseConfig.StorehouseOutInfo,
  7470. IsCheck: 1,
  7471. }
  7472. service.AddSigleWarehouseOutOne(&warehouseOut)
  7473. }
  7474. //出库
  7475. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7476. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7477. //1.查看该患者该耗材型号最后一次出库数量
  7478. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7479. prepare := models.DialysisBeforePrepare{
  7480. UserOrgId: adminInfo.Org.Id,
  7481. PatientId: patient_id,
  7482. RecordDate: record_time,
  7483. GoodId: item.GoodId,
  7484. GoodTypeId: item.GoodTypeId,
  7485. Count: item.Count - goodInfoTwo.Count,
  7486. Ctime: time.Now().Unix(),
  7487. Mtime: 0,
  7488. Creater: adminInfo.AdminUser.Id,
  7489. Modifier: adminInfo.AdminUser.Id,
  7490. Status: 1,
  7491. CommdityCode: "",
  7492. NewCount: 0,
  7493. ProjectId: 0,
  7494. StorehouseId: houseConfig.StorehouseOutInfo,
  7495. }
  7496. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7497. //增加出库数量
  7498. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7499. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7500. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7501. var total_count int64
  7502. for _, it := range stockList {
  7503. total_count += it.StockCount
  7504. }
  7505. //基础库插入数据
  7506. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7507. //剩余库存
  7508. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7509. var flush_count int64
  7510. for _, it := range goodList {
  7511. flush_count += it.StockCount
  7512. }
  7513. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7514. }
  7515. }
  7516. }
  7517. //查询今日出库数据
  7518. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7519. for _, it := range list {
  7520. prepare := models.DialysisBeforePrepare{
  7521. UserOrgId: it.OrgId,
  7522. PatientId: patient_id,
  7523. RecordDate: it.RecordTime,
  7524. GoodId: it.GoodId,
  7525. GoodTypeId: it.GoodTypeId,
  7526. Count: it.Count,
  7527. Ctime: time.Now().Unix(),
  7528. Creater: adminInfo.AdminUser.Id,
  7529. Status: 1,
  7530. StorehouseId: houseConfig.StorehouseOutInfo,
  7531. ProjectId: it.ProjectId,
  7532. }
  7533. //删除准备表数据
  7534. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7535. service.CreateDialysisBeforePrepareOne(&prepare)
  7536. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7537. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7538. var total_count int64
  7539. for _, it := range stockList {
  7540. total_count += it.StockCount
  7541. }
  7542. //基础库插入数据
  7543. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7544. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7545. var flush_count int64
  7546. for _, it := range goodList {
  7547. flush_count += it.StockCount
  7548. }
  7549. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7550. }
  7551. }
  7552. }
  7553. //更新自动出库的地方
  7554. var errs error
  7555. if errs == nil {
  7556. c.ServeSuccessJSON(map[string]interface{}{
  7557. "msg": "修改成功",
  7558. "message": "2",
  7559. "good_name": "",
  7560. "specification_name": "",
  7561. })
  7562. return
  7563. } else {
  7564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7565. return
  7566. }
  7567. }
  7568. }
  7569. func (c *DialysisAPIController) GetDialysisGoods() {
  7570. schedualDate := c.GetString("schedule_date")
  7571. schedule_type, _ := c.GetInt64("schedule_type")
  7572. partition_id, _ := c.GetInt64("partition_id")
  7573. page, _ := c.GetInt("page")
  7574. patient_id, _ := c.GetInt64("patient_id")
  7575. schedualEndDate := int64(0)
  7576. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7577. if parseDateErr != nil && len(schedualDate) != 0 {
  7578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7579. return
  7580. }
  7581. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7582. if parseDateErr != nil && len(schedualDate) != 0 {
  7583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7584. return
  7585. }
  7586. schedualEndDate = endDate.Unix()
  7587. adminUser := c.GetMobileAdminUserInfo()
  7588. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7589. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7590. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7591. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7592. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7593. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7594. //获取当天该病人的透析处方
  7595. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7596. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7597. if err == gorm.ErrRecordNotFound {
  7598. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7599. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7600. if patient_id != 0 {
  7601. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7602. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7603. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7604. //获取患者总的出库数据
  7605. item.LastAutomaticReduceDetail = goodUser
  7606. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7607. item.Project = project
  7608. for _, it := range item.AutomaticReduceDetail {
  7609. var total int64
  7610. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7611. for _, its := range auto {
  7612. total += its.Count
  7613. }
  7614. it.Count = total
  7615. }
  7616. }
  7617. }
  7618. c.ServeSuccessJSON(map[string]interface{}{
  7619. "dialysis_goods": dialysisGoods,
  7620. "good_type": goodTypes,
  7621. "total": total,
  7622. "prescribe": prescribe,
  7623. "good_info": good_info,
  7624. "warehouseOutList": warehouseOutList,
  7625. "config": config,
  7626. "outConfig": outConfig,
  7627. "settleConfig": settleConfig,
  7628. })
  7629. return
  7630. } else if err == nil {
  7631. //获取当天排班的每个患者的库存使用情况
  7632. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7633. //获取患者总的出库数据
  7634. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7635. if patient_id != 0 {
  7636. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7637. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7638. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7639. item.Project = project
  7640. item.LastAutomaticReduceDetail = goodUser
  7641. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7642. for _, it := range item.AutomaticReduceDetail {
  7643. var total int64
  7644. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7645. for _, its := range auto {
  7646. total += its.Count
  7647. }
  7648. it.Count = total
  7649. }
  7650. }
  7651. }
  7652. if err == nil {
  7653. c.ServeSuccessJSON(map[string]interface{}{
  7654. "dialysis_goods": dialysisGoods,
  7655. "good_type": goodTypes,
  7656. "total": total,
  7657. "prescribe": prescribe,
  7658. "good_info": good_info,
  7659. "project": project,
  7660. "warehouseOutList": warehouseOutList,
  7661. "config": config,
  7662. "outConfig": outConfig,
  7663. "settleConfig": settleConfig,
  7664. })
  7665. return
  7666. } else {
  7667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7668. return
  7669. }
  7670. } else if err != nil {
  7671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7672. return
  7673. }
  7674. }
  7675. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7676. start_time := c.GetString("start_time")
  7677. end_time := c.GetString("end_time")
  7678. timeLayout := "2006-01-02"
  7679. loc, _ := time.LoadLocation("Local")
  7680. var theStartTime int64
  7681. if len(start_time) > 0 {
  7682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7683. if err != nil {
  7684. utils.ErrorLog(err.Error())
  7685. }
  7686. theStartTime = theTime.Unix()
  7687. }
  7688. var theEndtTime int64
  7689. if len(end_time) > 0 {
  7690. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7691. if err != nil {
  7692. utils.ErrorLog(err.Error())
  7693. }
  7694. theEndtTime = theTime.Unix()
  7695. }
  7696. adminUser := c.GetMobileAdminUserInfo()
  7697. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7698. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7699. if err == nil {
  7700. c.ServeSuccessJSON(map[string]interface{}{
  7701. "stock_out": outInfo,
  7702. "stockCount": stockCount,
  7703. })
  7704. return
  7705. } else {
  7706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7707. return
  7708. }
  7709. }
  7710. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7711. patient_id, _ := c.GetInt64("patient_id", 0)
  7712. record_time := c.GetString("record_time")
  7713. adminUser := c.GetMobileAdminUserInfo()
  7714. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7715. if parseDateErr != nil && len(record_time) != 0 {
  7716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7717. return
  7718. }
  7719. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7720. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7721. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7722. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7723. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7724. //获取今日患者的透析处方参数
  7725. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7726. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7727. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7728. c.ServeSuccessJSON(map[string]interface{}{
  7729. "good_type": goodTypes,
  7730. "good_user": goodUser,
  7731. "good_info": good_info,
  7732. "last_good_user": lastGoodUserDetial,
  7733. "project": project,
  7734. "prescription": prescribe,
  7735. "outInfo": outInfo,
  7736. "configs": configs,
  7737. })
  7738. return
  7739. }
  7740. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7741. patient_id, _ := c.GetInt64("patient_id", 0)
  7742. record_date := c.GetString("record_time")
  7743. timeLayout := "2006-01-02"
  7744. loc, _ := time.LoadLocation("Local")
  7745. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7746. record_time := theRecordTime.Unix()
  7747. adminInfo := c.GetMobileAdminUserInfo()
  7748. dataBody := make(map[string]interface{}, 0)
  7749. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7750. if err != nil {
  7751. utils.ErrorLog(err.Error())
  7752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7753. return
  7754. }
  7755. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7756. var beforePrepares []*models.DialysisBeforePrepareGoods
  7757. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7758. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7759. goods, _ := dataBody["goods"].([]interface{})
  7760. if len(goods) > 0 {
  7761. for _, item := range goods {
  7762. items := item.(map[string]interface{})
  7763. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7764. utils.ErrorLog("good_id")
  7765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7766. return
  7767. }
  7768. good_id := int64(items["good_id"].(float64))
  7769. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7770. utils.ErrorLog("good_type_id")
  7771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7772. return
  7773. }
  7774. good_type_id := int64(items["good_type_id"].(float64))
  7775. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7776. utils.ErrorLog("count")
  7777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7778. return
  7779. }
  7780. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7781. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7782. utils.ErrorLog("project_id")
  7783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7784. return
  7785. }
  7786. project_id := int64(items["project_id"].(float64))
  7787. new_count := int64(items["new_count"].(float64))
  7788. old_count := int64(items["old_count"].(float64))
  7789. prepare := &models.DialysisBeforePrepareGoods{
  7790. GoodId: good_id,
  7791. GoodTypeId: good_type_id,
  7792. Count: count,
  7793. ProjectId: project_id,
  7794. StorehouseId: houseConfig.StorehouseOutInfo,
  7795. NewCount: new_count,
  7796. OldCount: old_count,
  7797. }
  7798. beforePrepares = append(beforePrepares, prepare)
  7799. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7800. GoodId: good_id,
  7801. GoodTypeId: good_type_id,
  7802. Count: count,
  7803. ProjectId: project_id,
  7804. StorehouseId: houseConfig.StorehouseOutInfo,
  7805. NewCount: new_count,
  7806. OldCount: old_count,
  7807. }
  7808. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7809. }
  7810. }
  7811. }
  7812. //查询是否有库存
  7813. for _, item := range beforePrepares {
  7814. if item.NewCount > 0 {
  7815. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7816. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7817. if item.Count > warehouse.Count {
  7818. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7819. c.ServeSuccessJSON(map[string]interface{}{
  7820. "message": "1",
  7821. "good_name": goodObj.GoodName,
  7822. "specification_name": goodObj.SpecificationName,
  7823. })
  7824. return
  7825. }
  7826. }
  7827. }
  7828. // 查询信息规挡的设置天数
  7829. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7830. if infor.ID > 0 && infor.WeekDay > 0 {
  7831. var cha_time int64
  7832. timeNowStr := time.Now().Format("2006-01-02")
  7833. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7834. //今日的日期减去设置的日期
  7835. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7836. if cha_time >= record_time {
  7837. //查询审核是否允许
  7838. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7839. //申请状态不允许的情况 拒绝修改
  7840. if infor.ApplicationStatus != 1 {
  7841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7842. return
  7843. }
  7844. }
  7845. }
  7846. //出库逻辑
  7847. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7848. if err != nil {
  7849. utils.ErrorLog(err.Error())
  7850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7851. return
  7852. }
  7853. finish := models.XtDialysisFinish{
  7854. IsFinish: 1,
  7855. UserOrgId: adminInfo.Org.Id,
  7856. Status: 1,
  7857. Ctime: time.Now().Unix(),
  7858. Mtime: 0,
  7859. Module: 11,
  7860. RecordDate: record_time,
  7861. Sourse: 1,
  7862. PatientId: patient_id,
  7863. }
  7864. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7865. if dialysisFinish.ID == 0 {
  7866. service.CreateDialysisFinish(finish)
  7867. }
  7868. //查询当天出库的数据
  7869. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7870. for _, item := range list {
  7871. prepare := models.DialysisBeforePrepare{
  7872. UserOrgId: item.OrgId,
  7873. PatientId: item.PatientId,
  7874. RecordDate: item.RecordTime,
  7875. GoodId: item.GoodId,
  7876. GoodTypeId: item.GoodTypeId,
  7877. Count: item.Count,
  7878. Creater: adminInfo.AdminUser.Id,
  7879. Status: 1,
  7880. Ctime: time.Now().Unix(),
  7881. ProjectId: item.ProjectId,
  7882. StorehouseId: houseConfig.StorehouseOutInfo,
  7883. }
  7884. //清空准备表的数据
  7885. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7886. //插入准备表数据
  7887. service.CreateDialysisBeforePrepareOne(&prepare)
  7888. //查询默认仓库
  7889. //查询默认仓库
  7890. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7891. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7892. var total_count int64
  7893. for _, it := range stockList {
  7894. total_count += it.StockCount
  7895. }
  7896. //基础库插入数据
  7897. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7898. ////更新剩余库存
  7899. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7900. var flush_count int64
  7901. for _, it := range goodList {
  7902. flush_count += it.StockCount
  7903. }
  7904. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7905. if errs != nil {
  7906. goodErrcode := models.XtGoodErrcode{
  7907. UserOrgId: item.OrgId,
  7908. Errcode: "手动出库更新剩余出库失败",
  7909. GoodId: item.GoodId,
  7910. Status: 1,
  7911. Ctime: time.Now().Unix(),
  7912. Mtime: 0,
  7913. Count: 0,
  7914. StockCount: 0,
  7915. Creater: adminInfo.AdminUser.Id,
  7916. BatchNumberId: 0,
  7917. WarehouseOutId: 0,
  7918. }
  7919. service.CreateGoodErrcode(goodErrcode)
  7920. }
  7921. }
  7922. //更新自动出库的地方
  7923. var errs error
  7924. if errs == nil {
  7925. c.ServeSuccessJSON(map[string]interface{}{
  7926. "msg": "修改成功",
  7927. "message": "2",
  7928. "good_name": "",
  7929. "specification_name": "",
  7930. })
  7931. return
  7932. } else {
  7933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7934. return
  7935. }
  7936. }
  7937. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7938. newArr = make([]*models.DialysisBeforePrepare, 0)
  7939. for i := 0; i < len(arr); i++ {
  7940. repeat := false
  7941. for j := i + 1; j < len(arr); j++ {
  7942. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7943. repeat = true
  7944. break
  7945. }
  7946. }
  7947. if !repeat {
  7948. newArr = append(newArr, arr[i])
  7949. }
  7950. }
  7951. return
  7952. }
  7953. func (c *DialysisAPIController) GetAllDrug() {
  7954. patient_id, _ := c.GetInt64("patient_id", 0)
  7955. adminInfo := c.GetMobileAdminUserInfo()
  7956. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7957. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7958. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7959. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7960. c.ServeSuccessJSON(map[string]interface{}{
  7961. "base_drug_config": drugStockConfig,
  7962. "private_drug_config": privateDrugConfig,
  7963. "base_drug_list": drugList,
  7964. "private_drug_list": privateDrugList,
  7965. })
  7966. }
  7967. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7968. newArr = make([]*models.DialysisBeforePrepare, 0)
  7969. for i := 0; i < len(arr); i++ {
  7970. repeat := false
  7971. for j := i + 1; j < len(arr); j++ {
  7972. if arr[i].GoodId == arr[j].GoodId {
  7973. repeat = true
  7974. break
  7975. }
  7976. }
  7977. if !repeat {
  7978. newArr = append(newArr, arr[i])
  7979. }
  7980. }
  7981. return
  7982. }
  7983. func (c *DialysisAPIController) GetDepartment() {
  7984. adminInfo := c.GetMobileAdminUserInfo()
  7985. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7986. if err == nil {
  7987. c.ServeSuccessJSON(map[string]interface{}{
  7988. "departments": departments,
  7989. })
  7990. } else {
  7991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7992. return
  7993. }
  7994. }
  7995. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7996. types, _ := c.GetInt("type", 0)
  7997. start_time := c.GetString("start_time")
  7998. end_time := c.GetString("end_time")
  7999. orgId := c.GetMobileAdminUserInfo().Org.Id
  8000. timeLayout := "2006-01-02"
  8001. loc, _ := time.LoadLocation("Local")
  8002. var startTime int64
  8003. if len(start_time) > 0 {
  8004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8005. if err != nil {
  8006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8007. return
  8008. }
  8009. startTime = theTime.Unix()
  8010. }
  8011. var endTime int64
  8012. if len(end_time) > 0 {
  8013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8014. if err != nil {
  8015. utils.ErrorLog(err.Error())
  8016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8017. return
  8018. }
  8019. endTime = theTime.Unix()
  8020. }
  8021. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8022. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8023. if err != nil {
  8024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8025. } else {
  8026. c.ServeSuccessJSON(map[string]interface{}{
  8027. "list": list,
  8028. "type": types,
  8029. "stockTotal": stockTotal,
  8030. })
  8031. }
  8032. }
  8033. func (c *DialysisAPIController) GetPrescriptionList() {
  8034. start_time := c.GetString("start_time")
  8035. end_time := c.GetString("end_time")
  8036. schedule_type, _ := c.GetInt64("schedule_type")
  8037. partion_id, _ := c.GetInt64("partion_id")
  8038. orgId := c.GetMobileAdminUserInfo().Org.Id
  8039. timeLayout := "2006-01-02"
  8040. loc, _ := time.LoadLocation("Local")
  8041. var startTime int64
  8042. if len(start_time) > 0 {
  8043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8044. if err != nil {
  8045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8046. return
  8047. }
  8048. startTime = theTime.Unix()
  8049. }
  8050. var endTime int64
  8051. if len(end_time) > 0 {
  8052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8053. if err != nil {
  8054. utils.ErrorLog(err.Error())
  8055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8056. return
  8057. }
  8058. endTime = theTime.Unix()
  8059. }
  8060. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8061. fmt.Println("schedulelist22222222", schedulelist)
  8062. c.ServeSuccessJSON(map[string]interface{}{
  8063. "list": schedulelist,
  8064. })
  8065. return
  8066. }
  8067. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8068. ids := c.GetString("ids")
  8069. //patient_id, _ := c.GetInt64("patient_id")
  8070. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8071. idArray := strings.Split(ids, ",")
  8072. err := service.BatchDeleteMonitor(idArray)
  8073. fmt.Print("err", err)
  8074. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8075. //redis := service.RedisClient()
  8076. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8077. //redis.Set(key, "", time.Second)
  8078. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8079. //redis.Set(keyOne, "", time.Second)
  8080. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8081. //redis.Close()
  8082. c.ServeSuccessJSON(map[string]interface{}{
  8083. "msg": "批量删除成功",
  8084. })
  8085. return
  8086. }
  8087. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8088. id, _ := c.GetInt64("id")
  8089. timeLayout := "2006-01-02"
  8090. loc, _ := time.LoadLocation("Local")
  8091. //start_time := time.Now().Format("2006-01-02")
  8092. start_time := c.GetString("start_time")
  8093. end_time := c.GetString("end_time")
  8094. var startdateunix int64
  8095. if len(start_time) > 0 {
  8096. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8097. if err != nil {
  8098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8099. return
  8100. }
  8101. startdateunix = theTime.Unix()
  8102. }
  8103. var enddateunix int64
  8104. if len(end_time) > 0 {
  8105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8106. if err != nil {
  8107. utils.ErrorLog(err.Error())
  8108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8109. return
  8110. }
  8111. enddateunix = theTime.Unix()
  8112. }
  8113. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8114. //nowTime := time.Now()
  8115. //endTime := nowTime.AddDate(-30, 0, 0)
  8116. //endTimes := endTime.Format("2006-01-02")
  8117. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8118. org_id := c.GetMobileAdminUserInfo().Org.Id
  8119. //if org_id == 10579 {
  8120. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8121. // c.ServeSuccessJSON(map[string]interface{}{
  8122. // "list": list,
  8123. // })
  8124. // return
  8125. //} else {
  8126. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8127. // c.ServeSuccessJSON(map[string]interface{}{
  8128. // "list": list,
  8129. // })
  8130. // return
  8131. //}
  8132. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8133. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8134. c.ServeSuccessJSON(map[string]interface{}{
  8135. "list": list,
  8136. })
  8137. return
  8138. } else {
  8139. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8140. c.ServeSuccessJSON(map[string]interface{}{
  8141. "list": list,
  8142. })
  8143. }
  8144. return
  8145. }
  8146. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8147. dataBody := make(map[string]interface{}, 0)
  8148. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8149. ids := c.GetString("ids")
  8150. idArray := strings.Split(ids, ",")
  8151. origin, _ := c.GetInt64("origin")
  8152. if origin == 1 {
  8153. err = service.BatchDeleteAdvice(idArray)
  8154. fmt.Print("err", err)
  8155. c.ServeSuccessJSON(map[string]interface{}{
  8156. "msg": "批量删除成功",
  8157. })
  8158. return
  8159. }
  8160. if origin == 2 {
  8161. service.BatchDeleteHisAdvice(idArray)
  8162. }
  8163. }
  8164. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8165. good_id, _ := c.GetInt64("good_id")
  8166. count, _ := c.GetInt64("count")
  8167. record_time, _ := c.GetInt64("record_time")
  8168. patient_id, _ := c.GetInt64("patient_id")
  8169. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8170. c.ServeSuccessJSON(map[string]interface{}{
  8171. "detail": detail,
  8172. })
  8173. return
  8174. }
  8175. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8176. good_id, _ := c.GetInt64("good_id")
  8177. record_time, _ := c.GetInt64("record_time")
  8178. patient_id, _ := c.GetInt64("patient_id")
  8179. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8180. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8181. fmt.Print("err", err)
  8182. c.ServeSuccessJSON(map[string]interface{}{
  8183. "msg": "批量删除成功",
  8184. })
  8185. return
  8186. }
  8187. func (c *DialysisAPIController) BatchAdviceCheck() {
  8188. ids := c.GetString("ids")
  8189. idArray := strings.Split(ids, ",")
  8190. creator, _ := c.GetInt64("creator")
  8191. origin, _ := c.GetInt64("origin")
  8192. if origin == 1 {
  8193. err := service.BatchAdviceCheck(idArray, creator)
  8194. fmt.Println(err)
  8195. list, _ := service.GetAdviceExecutionById(idArray)
  8196. c.ServeSuccessJSON(map[string]interface{}{
  8197. "list": list,
  8198. })
  8199. return
  8200. }
  8201. if origin == 2 {
  8202. service.BatchHisAdviceCheck(idArray, creator)
  8203. list, _ := service.GetHisAdviceExecutionById(idArray)
  8204. c.ServeSuccessJSON(map[string]interface{}{
  8205. "list": list,
  8206. })
  8207. return
  8208. }
  8209. }
  8210. func (c *DialysisAPIController) BatchAdviceExecution() {
  8211. ids := c.GetString("ids")
  8212. idArray := strings.Split(ids, ",")
  8213. executionTime := c.GetString("execution_time")
  8214. creator, _ := c.GetInt64("creator")
  8215. timeLayout := "2006-01-02 15:04:05"
  8216. loc, _ := time.LoadLocation("Local")
  8217. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8218. orgin, _ := c.GetInt64("origin")
  8219. if orgin == 1 {
  8220. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8221. list, _ := service.GetAdviceExecutionById(idArray)
  8222. fmt.Println(err)
  8223. c.ServeSuccessJSON(map[string]interface{}{
  8224. "list": list,
  8225. })
  8226. return
  8227. }
  8228. if orgin == 2 {
  8229. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8230. list, _ := service.GetHisAdviceExecutionById(idArray)
  8231. fmt.Println(err)
  8232. c.ServeSuccessJSON(map[string]interface{}{
  8233. "list": list,
  8234. })
  8235. return
  8236. }
  8237. }
  8238. func (c *DialysisAPIController) UpdateStockGoods() {
  8239. good_id, _ := c.GetInt64("good_id")
  8240. record_time, _ := c.GetInt64("record_time")
  8241. patient_id, _ := c.GetInt64("patient_id")
  8242. count, _ := c.GetInt64("count")
  8243. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8244. fmt.Print("err", err)
  8245. c.ServeSuccessJSON(map[string]interface{}{
  8246. "msg": "更新成功",
  8247. })
  8248. return
  8249. }
  8250. // 当前数据比上一次出库数据少
  8251. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8252. //查询该患者当天已经出库的耗材信息
  8253. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8254. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8255. for i := len(goods_yc) - 1; i >= 0; i-- {
  8256. goods_yc_temp := goods_yc[i]
  8257. for j := len(goods) - 1; j >= 0; j-- {
  8258. goods_temp := goods[j]
  8259. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8260. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8261. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8262. if goods_yc_temp.Count == goods_temp.Count {
  8263. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8264. goods = append(goods[:j], goods[j+1:]...)
  8265. break
  8266. }
  8267. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8268. if goods_yc_temp.Count > goods_temp.Count {
  8269. temp_count := goods_yc_temp.Count - goods_temp.Count
  8270. goods_yc[i].Count = temp_count
  8271. goods = append(goods[:j], goods[j+1:]...)
  8272. break
  8273. }
  8274. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8275. if goods_yc_temp.Count < goods_temp.Count {
  8276. temp_count := goods_temp.Count - goods_yc_temp.Count
  8277. goods[j].Count = temp_count
  8278. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8279. break
  8280. }
  8281. }
  8282. }
  8283. }
  8284. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8285. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8286. //退库
  8287. if len(goods_yc) > 0 {
  8288. for _, good_yc := range goods_yc {
  8289. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8290. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8291. }
  8292. }
  8293. return nil
  8294. }
  8295. // 耗材出库删除
  8296. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8297. // 先根据相关信息查询当天该耗材的出库信息
  8298. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8299. if err != nil {
  8300. return err
  8301. }
  8302. var delete_count int64 = 0
  8303. delete_count = warehouseOutInfos.Count - count
  8304. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8305. // 在出库记录表里记录退库详情
  8306. warehouseOutInfo := &models.WarehouseOutInfo{
  8307. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8308. WarehouseOutId: warehouseOut.ID,
  8309. Status: 1,
  8310. Ctime: time.Now().Unix(),
  8311. OrgId: orgID,
  8312. Type: 1,
  8313. IsSys: 1,
  8314. SysRecordTime: record_time,
  8315. GoodTypeId: good_yc.GoodTypeId,
  8316. GoodId: good_yc.GoodId,
  8317. PatientId: good_yc.PatientId,
  8318. ConsumableType: 2,
  8319. StorehouseId: houseConfig.StorehouseOutInfo,
  8320. IsCheck: 1,
  8321. }
  8322. warehouseOutInfo.Count = count
  8323. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8324. warehouseOutInfo.Price = stockInInfo.Price
  8325. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8326. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8327. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8328. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8329. warehouseOutInfo.Number = warehouseOutInfos.Number
  8330. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8331. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8332. //查找当天是否存在出库记录
  8333. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8334. if errcod == gorm.ErrRecordNotFound {
  8335. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8336. //插入详情明细表
  8337. stockFlow := models.VmStockFlow{
  8338. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8339. WarehouseOutId: warehouseOut.ID,
  8340. GoodId: good_yc.GoodId,
  8341. Number: warehouseOutInfos.Number,
  8342. ProductDate: stockInInfo.ProductDate,
  8343. ExpireDate: stockInInfo.ExpiryDate,
  8344. Count: count,
  8345. Price: stockInInfo.Price,
  8346. Status: 1,
  8347. Ctime: time.Now().Unix(),
  8348. UserOrgId: good_yc.OrgId,
  8349. Manufacturer: stockInInfo.Manufacturer,
  8350. Dealer: stockInInfo.Dealer,
  8351. LicenseNumber: stockInInfo.LicenseNumber,
  8352. IsEdit: 2,
  8353. Creator: creater,
  8354. SystemTime: record_time,
  8355. ConsumableType: 3,
  8356. WarehousingDetailId: 0,
  8357. IsSys: 1,
  8358. UpdateCreator: creater,
  8359. PatientId: patient_id,
  8360. StorehouseId: houseConfig.StorehouseOutInfo,
  8361. }
  8362. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8363. if errflow == gorm.ErrRecordNotFound {
  8364. //创建流水表
  8365. err := service.CreateStockFlowOne(stockFlow)
  8366. fmt.Println("err", err)
  8367. } else if errflow == nil {
  8368. //插入详情明细表
  8369. stockFlow := models.VmStockFlow{
  8370. ID: exsit.ID,
  8371. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8372. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8373. WarehouseOutId: warehouseOut.ID,
  8374. GoodId: good_yc.GoodId,
  8375. Number: warehouseOutInfos.Number,
  8376. ProductDate: stockInInfo.ProductDate,
  8377. ExpireDate: stockInInfo.ExpiryDate,
  8378. Count: exsit.Count - delete_count,
  8379. Price: stockInInfo.Price,
  8380. Status: 1,
  8381. Ctime: time.Now().Unix(),
  8382. UserOrgId: good_yc.OrgId,
  8383. Manufacturer: stockInInfo.Manufacturer,
  8384. Dealer: stockInInfo.Dealer,
  8385. LicenseNumber: stockInInfo.LicenseNumber,
  8386. IsEdit: 2,
  8387. Creator: creater,
  8388. SystemTime: record_time,
  8389. ConsumableType: 3,
  8390. WarehousingDetailId: 0,
  8391. IsSys: 1,
  8392. UpdateCreator: creater,
  8393. PatientId: patient_id,
  8394. StorehouseId: houseConfig.StorehouseOutInfo,
  8395. }
  8396. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8397. }
  8398. if errOne != nil {
  8399. return errOne
  8400. }
  8401. } else if errcod == nil {
  8402. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8403. //插入详情明细表
  8404. stockFlow := models.VmStockFlow{
  8405. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8406. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8407. WarehouseOutId: warehouseOut.ID,
  8408. GoodId: good_yc.GoodId,
  8409. Number: warehouseOutInfos.Number,
  8410. ProductDate: stockInInfo.ProductDate,
  8411. ExpireDate: stockInInfo.ExpiryDate,
  8412. Count: count,
  8413. Price: stockInInfo.Price,
  8414. Status: 1,
  8415. Ctime: time.Now().Unix(),
  8416. UserOrgId: good_yc.OrgId,
  8417. Manufacturer: stockInInfo.Manufacturer,
  8418. Dealer: stockInInfo.Dealer,
  8419. LicenseNumber: stockInInfo.LicenseNumber,
  8420. IsEdit: 2,
  8421. Creator: creater,
  8422. SystemTime: record_time,
  8423. ConsumableType: 3,
  8424. WarehousingDetailId: 0,
  8425. IsSys: 1,
  8426. UpdateCreator: creater,
  8427. PatientId: patient_id,
  8428. ReturnCount: delete_count,
  8429. StorehouseId: houseConfig.StorehouseOutInfo,
  8430. }
  8431. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8432. if errflows == gorm.ErrRecordNotFound {
  8433. //创建流水表
  8434. service.CreateStockFlowOne(stockFlow)
  8435. } else if errflows == nil {
  8436. stockFlow := models.VmStockFlow{
  8437. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8438. ID: exsit.ID,
  8439. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8440. WarehouseOutId: warehouseOut.ID,
  8441. GoodId: good_yc.GoodId,
  8442. Number: warehouseOutInfos.Number,
  8443. ProductDate: stockInInfo.ProductDate,
  8444. ExpireDate: stockInInfo.ExpiryDate,
  8445. Count: exsit.Count - delete_count,
  8446. Price: stockInInfo.Price,
  8447. Status: 1,
  8448. Ctime: time.Now().Unix(),
  8449. UserOrgId: good_yc.OrgId,
  8450. Manufacturer: stockInInfo.Manufacturer,
  8451. Dealer: stockInInfo.Dealer,
  8452. LicenseNumber: stockInInfo.LicenseNumber,
  8453. IsEdit: 2,
  8454. Creator: creater,
  8455. SystemTime: record_time,
  8456. ConsumableType: 3,
  8457. WarehousingDetailId: 0,
  8458. IsSys: 1,
  8459. UpdateCreator: creater,
  8460. PatientId: patient_id,
  8461. ReturnCount: delete_count,
  8462. StorehouseId: houseConfig.StorehouseOutInfo,
  8463. }
  8464. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8465. }
  8466. }
  8467. //更改自动出库的表格
  8468. details := models.BloodAutomaticReduceDetail{
  8469. WarehouseOutId: warehouseOutInfo.ID,
  8470. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8471. PatientId: patient_id,
  8472. Ctime: time.Now().Unix(),
  8473. Mtime: time.Now().Unix(),
  8474. Status: 1,
  8475. RecordTime: record_time,
  8476. OrgId: orgID,
  8477. GoodId: good_yc.GoodId,
  8478. GoodTypeId: good_yc.GoodTypeId,
  8479. Count: count,
  8480. StorehouseId: houseConfig.StorehouseOutInfo,
  8481. }
  8482. //查询当天耗材是否已经存在数据
  8483. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8484. if errcode == gorm.ErrRecordNotFound {
  8485. errTwo := service.CreateAutoReduceRecord(&details)
  8486. if errTwo != nil {
  8487. return errTwo
  8488. }
  8489. } else if errcode == nil {
  8490. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8491. service.CreateAutoReduceRecord(&details)
  8492. }
  8493. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8494. //增加出库库存数量
  8495. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8496. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8497. fmt.Println("errOne", errOne)
  8498. // 删除出库完成后,要增加对应批次的库存数量
  8499. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8500. if errThree != nil {
  8501. return errThree
  8502. }
  8503. if good_yc.Count == 0 {
  8504. return nil
  8505. } else {
  8506. return errors.New("退库和出库数据不匹配")
  8507. }
  8508. }
  8509. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8510. //查询该患者当天已经出库的耗材信息
  8511. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8512. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8513. for i := len(goods_yc) - 1; i >= 0; i-- {
  8514. goods_yc_temp := goods_yc[i]
  8515. for j := len(goods) - 1; j >= 0; j-- {
  8516. goods_temp := goods[j]
  8517. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8518. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8519. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8520. if goods_yc_temp.Count == goods_temp.Count {
  8521. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8522. goods = append(goods[:j], goods[j+1:]...)
  8523. break
  8524. }
  8525. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8526. if goods_yc_temp.Count > goods_temp.Count {
  8527. temp_count := goods_yc_temp.Count - goods_temp.Count
  8528. goods_yc[i].Count = temp_count
  8529. goods = append(goods[:j], goods[j+1:]...)
  8530. break
  8531. }
  8532. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8533. if goods_yc_temp.Count < goods_temp.Count {
  8534. temp_count := goods_temp.Count - goods_yc_temp.Count
  8535. goods[j].Count = temp_count
  8536. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8537. break
  8538. }
  8539. }
  8540. }
  8541. }
  8542. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8543. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8544. fmt.Println("剩余需要出库的", len(goods))
  8545. if len(goods) > 0 {
  8546. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8547. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8548. if err == gorm.ErrRecordNotFound {
  8549. //没有记录,则创建出库单
  8550. timeStr := time.Now().Format("2006-01-02")
  8551. timeArr := strings.Split(timeStr, "-")
  8552. total, _ := service.FindAllWarehouseOut(orgID)
  8553. total = total + 1
  8554. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8555. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8556. number = number + total
  8557. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8558. warehouseOut := models.WarehouseOut{
  8559. WarehouseOutOrderNumber: warehousing_out_order,
  8560. OperationTime: time.Now().Unix(),
  8561. OrgId: orgID,
  8562. Creater: creater,
  8563. Ctime: time.Now().Unix(),
  8564. Status: 1,
  8565. WarehouseOutTime: record_time,
  8566. Dealer: 0,
  8567. Manufacturer: 0,
  8568. Type: 1,
  8569. IsSys: 1,
  8570. StorehouseId: houseConfig.StorehouseOutInfo,
  8571. IsCheck: 1,
  8572. }
  8573. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8574. if err != nil {
  8575. utils.TraceLog("创建出库单失败 err = %v", err)
  8576. return err
  8577. } else {
  8578. out = warehouseOut
  8579. }
  8580. }
  8581. for _, item := range goods {
  8582. var newCount int64 = 0
  8583. for _, it := range goodOne {
  8584. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8585. newCount = it.Count
  8586. }
  8587. }
  8588. prepare := models.DialysisBeforePrepare{
  8589. GoodTypeId: item.GoodTypeId,
  8590. GoodId: item.GoodId,
  8591. Count: item.Count,
  8592. StorehouseId: houseConfig.StorehouseOutInfo,
  8593. }
  8594. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8595. //增加出库数量
  8596. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8597. }
  8598. }
  8599. if len(goods_yc) > 0 {
  8600. for _, good_yc := range goods_yc {
  8601. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8602. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8603. }
  8604. }
  8605. return nil
  8606. }
  8607. // 耗材出库删除
  8608. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8609. // 先根据相关信息查询当天该耗材的出库信息
  8610. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8611. if err != nil {
  8612. return err
  8613. }
  8614. var delete_count int64 = 0
  8615. for _, ware := range warehouseOutInfos {
  8616. // 判断当前出库的数据和删除出库数量
  8617. if good_yc.Count <= ware.Count {
  8618. delete_count = good_yc.Count
  8619. } else {
  8620. delete_count = ware.Count
  8621. }
  8622. warehouseOutInfo := &models.WarehouseOutInfo{
  8623. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8624. WarehouseOutId: warehouseOut.ID,
  8625. Status: 1,
  8626. Ctime: time.Now().Unix(),
  8627. Remark: "",
  8628. OrgId: orgID,
  8629. Type: 1,
  8630. Manufacturer: 0,
  8631. Dealer: 0,
  8632. IsSys: 0,
  8633. SysRecordTime: record_time,
  8634. GoodTypeId: good_yc.GoodTypeId,
  8635. GoodId: good_yc.GoodId,
  8636. StorehouseId: warehouseOut.StorehouseId,
  8637. IsCheck: 1,
  8638. }
  8639. warehouseOutInfo.Count = delete_count
  8640. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8641. warehouseOutInfo.Price = stockInInfo.Price
  8642. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8643. if errOne != nil {
  8644. return errOne
  8645. }
  8646. // 删除出库完成后,要改变流水库存(有疑问)
  8647. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8648. fmt.Println("errOne", errOne)
  8649. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8650. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8651. //扣减出库数量
  8652. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8653. if errThree != nil {
  8654. return errThree
  8655. }
  8656. }
  8657. if good_yc.Count == 0 {
  8658. return nil
  8659. } else {
  8660. return errors.New("退库和出库数据不匹配")
  8661. }
  8662. }
  8663. func (this *DialysisAPIController) GetMobileScheduleList() {
  8664. limit, _ := this.GetInt64("limit")
  8665. page, _ := this.GetInt64("page")
  8666. type_options_visible, _ := this.GetInt64("type_options_visible")
  8667. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8668. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8669. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8670. }
  8671. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8672. newArr = make([]*models.HisPrescriptionProject, 0)
  8673. for i := 0; i < len(arr); i++ {
  8674. repeat := false
  8675. for j := i + 1; j < len(arr); j++ {
  8676. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8677. repeat = true
  8678. break
  8679. }
  8680. }
  8681. if !repeat {
  8682. newArr = append(newArr, arr[i])
  8683. }
  8684. }
  8685. return
  8686. }
  8687. func (this *DialysisAPIController) GetRoleList() {
  8688. admin_user_id, _ := this.GetInt64("admin_user_id")
  8689. orgid := this.GetMobileAdminUserInfo().Org.Id
  8690. list, err := service.GetRoleList(orgid, admin_user_id)
  8691. fmt.Println(err)
  8692. this.ServeSuccessJSON(map[string]interface{}{
  8693. "list": list,
  8694. })
  8695. return
  8696. }
  8697. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8698. // 先根据相关信息查询当天该耗材的出库信息
  8699. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8700. if err != nil {
  8701. return err
  8702. }
  8703. var delete_count int64 = 0
  8704. delete_count = warehouseOutInfos.Count - count
  8705. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8706. // 删除出库完成后,要增加对应批次的库存数量
  8707. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8708. if errThree != nil {
  8709. return errThree
  8710. }
  8711. //增加退库数量
  8712. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8713. //扣减出库数量
  8714. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8715. //查询剩余库存
  8716. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8717. var sum_count int64
  8718. for _, item := range goodList {
  8719. sum_count += item.StockCount
  8720. }
  8721. // 在出库记录表里记录退库详情
  8722. warehouseOutInfo := &models.WarehouseOutInfo{
  8723. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8724. WarehouseOutId: warehouseOut.ID,
  8725. Status: 1,
  8726. Ctime: time.Now().Unix(),
  8727. OrgId: orgID,
  8728. Type: 1,
  8729. IsSys: 1,
  8730. SysRecordTime: record_time,
  8731. GoodTypeId: good_yc.GoodTypeId,
  8732. GoodId: good_yc.GoodId,
  8733. PatientId: good_yc.PatientId,
  8734. ConsumableType: 2,
  8735. StorehouseId: houseConfig.StorehouseOutInfo,
  8736. IsCheck: 1,
  8737. OverCount: sum_count,
  8738. }
  8739. warehouseOutInfo.Count = count
  8740. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8741. warehouseOutInfo.Price = stockInInfo.Price
  8742. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8743. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8744. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8745. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8746. warehouseOutInfo.Number = warehouseOutInfos.Number
  8747. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8748. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8749. //查找当天是否存在出库记录
  8750. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8751. if errcod == gorm.ErrRecordNotFound {
  8752. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8753. //插入详情明细表
  8754. if errOne != nil {
  8755. return errOne
  8756. }
  8757. //插入详情明细表
  8758. stockFlow := models.VmStockFlow{
  8759. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8760. WarehouseOutId: warehouseOut.ID,
  8761. GoodId: good_yc.GoodId,
  8762. Number: warehouseOutInfos.Number,
  8763. ProductDate: stockInInfo.ProductDate,
  8764. ExpireDate: stockInInfo.ExpiryDate,
  8765. Count: count,
  8766. Price: stockInInfo.Price,
  8767. Status: 1,
  8768. Ctime: record_time,
  8769. UserOrgId: good_yc.OrgId,
  8770. Manufacturer: stockInInfo.Manufacturer,
  8771. Dealer: stockInInfo.Dealer,
  8772. LicenseNumber: stockInInfo.LicenseNumber,
  8773. IsEdit: 2,
  8774. Creator: creater,
  8775. SystemTime: record_time,
  8776. ConsumableType: 3,
  8777. WarehousingDetailId: 0,
  8778. IsSys: 1,
  8779. UpdateCreator: creater,
  8780. PatientId: patient_id,
  8781. StorehouseId: houseConfig.StorehouseOutInfo,
  8782. OverCount: sum_count,
  8783. ProjectId: good_yc.ProjectId,
  8784. }
  8785. err := service.CreateStockFlowOne(stockFlow)
  8786. fmt.Println("err", err)
  8787. } else if errcod == nil {
  8788. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8789. }
  8790. //创建退库单
  8791. operation_time := time.Now().Unix()
  8792. //创建退库单
  8793. timeStr := time.Now().Format("2006-01-02")
  8794. timeArr := strings.Split(timeStr, "-")
  8795. total, _ := service.FindAllCancelStockTotal(orgID)
  8796. total = total + 1
  8797. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8798. cancelStock := models.CancelStock{
  8799. OrderNumber: orderNumber,
  8800. OperaTime: operation_time,
  8801. OrgId: orgID,
  8802. Creater: warehouseOut.Creater,
  8803. Ctime: time.Now().Unix(),
  8804. Status: 1,
  8805. ReturnTime: record_time,
  8806. Type: 1,
  8807. StorehouseId: stockInInfo.StorehouseId,
  8808. IsCheck: 1,
  8809. }
  8810. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8811. if msgerrkonde == gorm.ErrRecordNotFound {
  8812. service.AddSigleCancelStock(&cancelStock)
  8813. }
  8814. cancel, _ := service.GetLastCancelStockById(orgID)
  8815. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8816. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8817. cancelStockInfo := models.CancelStockInfo{
  8818. GoodId: stockInInfo.GoodId,
  8819. CancelStockId: cancel.ID,
  8820. GoodTypeId: stockInInfo.GoodTypeId,
  8821. Count: delete_count,
  8822. Price: stockInInfo.PackingPrice,
  8823. Total: 0,
  8824. ProductDate: stockInInfo.ProductDate,
  8825. ExpiryDate: stockInInfo.ExpiryDate,
  8826. Ctime: record_time,
  8827. Status: 1,
  8828. OrgId: orgID,
  8829. OrderNumber: cancel.OrderNumber,
  8830. Type: 0,
  8831. Dealer: deaerler.DealerName,
  8832. Manufacturer: manufacturer.ManufacturerName,
  8833. Number: stockInInfo.Number,
  8834. RegisterAccount: "",
  8835. Remark: "",
  8836. WarehouseInfoId: stockInInfo.ID,
  8837. PatientId: patient_id,
  8838. RecordDate: record_time,
  8839. StorehouseId: stockInInfo.StorehouseId,
  8840. IsCheck: 1,
  8841. }
  8842. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8843. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8844. flow := models.VmStockFlow{
  8845. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8846. GoodId: good_yc.GoodId,
  8847. Number: warehouseOutInfos.Number,
  8848. LicenseNumber: stockInInfo.LicenseNumber,
  8849. Count: delete_count,
  8850. UserOrgId: orgID,
  8851. PatientId: patient_id,
  8852. SystemTime: record_time,
  8853. ConsumableType: 7,
  8854. IsSys: 0,
  8855. WarehousingOrder: "",
  8856. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8857. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8858. IsEdit: 0,
  8859. CancelStockId: cancel.ID,
  8860. CancelOrderNumber: cancel.OrderNumber,
  8861. Manufacturer: manufacturer.ID,
  8862. Dealer: 0,
  8863. Creator: warehouseOut.Creater,
  8864. UpdateCreator: 0,
  8865. Status: 1,
  8866. Ctime: record_time,
  8867. Mtime: 0,
  8868. Price: stockInInfo.Price,
  8869. WarehousingDetailId: stockInInfo.ID,
  8870. WarehouseOutDetailId: warehouseOutInfos.ID,
  8871. CancelOutDetailId: cancelInfo.ID,
  8872. ProductDate: stockInInfo.ProductDate,
  8873. ExpireDate: stockInInfo.ExpiryDate,
  8874. StorehouseId: houseConfig.StorehouseOutInfo,
  8875. OverCount: sum_count,
  8876. }
  8877. service.CreateStockFlowOne(flow)
  8878. //更改自动出库的表格
  8879. details := models.BloodAutomaticReduceDetail{
  8880. WarehouseOutId: warehouseOutInfo.ID,
  8881. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8882. PatientId: patient_id,
  8883. Ctime: time.Now().Unix(),
  8884. Mtime: time.Now().Unix(),
  8885. Status: 1,
  8886. RecordTime: record_time,
  8887. OrgId: orgID,
  8888. GoodId: good_yc.GoodId,
  8889. GoodTypeId: good_yc.GoodTypeId,
  8890. Count: count,
  8891. StorehouseId: houseConfig.StorehouseOutInfo,
  8892. }
  8893. //查询当天耗材是否已经存在数据
  8894. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8895. if errcode == gorm.ErrRecordNotFound {
  8896. errTwo := service.CreateAutoReduceRecord(&details)
  8897. if errTwo != nil {
  8898. return errTwo
  8899. }
  8900. } else if errcode == nil {
  8901. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8902. service.CreateAutoReduceRecord(&details)
  8903. }
  8904. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8905. //增加出库库存数量
  8906. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8907. if good_yc.Count == 0 {
  8908. return nil
  8909. } else {
  8910. return errors.New("退库和出库数据不匹配")
  8911. }
  8912. }
  8913. func (this *DialysisAPIController) SavePatientSign() {
  8914. adminUserInfo := this.GetMobileAdminUserInfo()
  8915. patient_id, _ := this.GetInt64("patient_id")
  8916. dialysis_date, _ := this.GetInt64("dialysis_date")
  8917. orgid := adminUserInfo.Org.Id
  8918. var esdata models.DialysisOrder
  8919. var err error
  8920. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8921. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8922. return
  8923. }
  8924. esdata.Hash = esdata.Hash
  8925. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8926. order := models.DialysisOrder{
  8927. Hash: esdata.Hash,
  8928. Url: esdata.Url,
  8929. }
  8930. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8931. redis := service.RedisClient()
  8932. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8933. redis.Set(key, "", time.Second)
  8934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8935. //清空key 值
  8936. redis.Set(keyOne, "", time.Second)
  8937. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8938. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8939. //redis.Set(keyTwo, "", time.Second)
  8940. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8941. redis.Set(keyThree, "", time.Second)
  8942. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8943. redis.Set(keyFour, "", time.Second)
  8944. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8945. redis.Set(keyFive, "", time.Second)
  8946. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8947. redis.Set(keySix, "", time.Second)
  8948. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8949. redis.Set(keySeven, "", time.Second)
  8950. if err != nil {
  8951. fmt.Println(err)
  8952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8953. return
  8954. }
  8955. this.ServeSuccessJSON(map[string]interface{}{
  8956. "electronic_signature": esdata,
  8957. })
  8958. }
  8959. func (this *DialysisAPIController) GetPatientSign() {
  8960. patient_id, _ := this.GetInt64("patient_id")
  8961. dialysis_date, _ := this.GetInt64("dialysis_date")
  8962. adminUserInfo := this.GetMobileAdminUserInfo()
  8963. orgId := adminUserInfo.Org.Id
  8964. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8965. if err != nil {
  8966. fmt.Println(err)
  8967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8968. return
  8969. }
  8970. this.ServeSuccessJSON(map[string]interface{}{
  8971. "dialysisOrder": dialysisOrder,
  8972. })
  8973. }
  8974. func (this *DialysisAPIController) GetScheduleByPatient() {
  8975. patient_id, _ := this.GetInt64("patient_id")
  8976. schedule_date, _ := this.GetInt64("schedule_date")
  8977. orgid := this.GetMobileAdminUserInfo().Org.Id
  8978. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8979. this.ServeSuccessJSON(map[string]interface{}{
  8980. "schedule": schedule,
  8981. })
  8982. }
  8983. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8984. org_id := this.GetMobileAdminUserInfo().Org.Id
  8985. patient_id, _ := this.GetInt64("patient_id")
  8986. schedule_date, _ := this.GetInt64("schedule_date")
  8987. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8988. this.ServeSuccessJSON(map[string]interface{}{
  8989. "order": order,
  8990. })
  8991. }
  8992. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8993. org_id := this.GetMobileAdminUserInfo().Org.Id
  8994. schedule_date := this.GetString("schedule_date")
  8995. schedule_type, _ := this.GetInt64("schedule_type")
  8996. timeLayout := "2006-01-02"
  8997. loc, _ := time.LoadLocation("Local")
  8998. var startdateunix int64
  8999. if len(schedule_date) > 0 {
  9000. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9001. if err != nil {
  9002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9003. return
  9004. }
  9005. startdateunix = theTime.Unix()
  9006. }
  9007. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9008. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9009. devices, _ := service.GetAllDevicetByListSix(org_id)
  9010. for key, item := range scheduals {
  9011. // 床位信息
  9012. for _, device := range devices {
  9013. if item.BedId == device.ID {
  9014. scheduals[key].DeviceNumber = device
  9015. break
  9016. }
  9017. }
  9018. }
  9019. this.ServeSuccessJSON(map[string]interface{}{
  9020. "list": list,
  9021. "scheduals": scheduals,
  9022. })
  9023. }
  9024. func (this *DialysisAPIController) SavePatientPicture() {
  9025. patient_id, _ := this.GetInt64("patient_id")
  9026. dialysis_date, _ := this.GetInt64("schedule_date")
  9027. avatar := this.GetString("avatar")
  9028. fmt.Println("patient_id", patient_id)
  9029. orgId := this.GetMobileAdminUserInfo().Org.Id
  9030. order := models.DialysisOrder{
  9031. Url: avatar,
  9032. }
  9033. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9034. redis := service.RedisClient()
  9035. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9036. redis.Set(key, "", time.Second)
  9037. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9038. //清空key 值
  9039. redis.Set(keyOne, "", time.Second)
  9040. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9041. redis.Set(keyThree, "", time.Second)
  9042. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9043. redis.Set(keyFour, "", time.Second)
  9044. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9045. redis.Set(keyFive, "", time.Second)
  9046. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9047. redis.Set(keySix, "", time.Second)
  9048. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9049. redis.Set(keySeven, "", time.Second)
  9050. if err != nil {
  9051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9052. return
  9053. }
  9054. this.ServeSuccessJSON(map[string]interface{}{
  9055. "order": order,
  9056. })
  9057. }
  9058. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9059. ids := this.GetString("ids")
  9060. idSplit := strings.Split(ids, ",")
  9061. orgId := this.GetMobileAdminUserInfo().Org.Id
  9062. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9063. execution_time := this.GetString("exce_time")
  9064. timeLayout2 := "2006-01-02 15:04:05"
  9065. loc, _ := time.LoadLocation("Local")
  9066. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9067. if errs != nil {
  9068. utils.ErrorLog(errs.Error())
  9069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9070. return
  9071. }
  9072. //his客户
  9073. if config.IsOpen == 1 {
  9074. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9075. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9076. for _, item := range list {
  9077. for _, it := range adviceList {
  9078. if item.DrugId == it.DrugId {
  9079. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9080. }
  9081. }
  9082. }
  9083. for _, item := range list {
  9084. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9085. var sum_out_count int64
  9086. for _, itemThree := range item.ChildDoctorAdvice {
  9087. var prescribing_number int64
  9088. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9089. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9090. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9091. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9092. }
  9093. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9094. prescribing_number = parseIntPrescribingNumber
  9095. }
  9096. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9097. prescribing_number = parseIntPrescribingNumber
  9098. }
  9099. sum_out_count += prescribing_number
  9100. }
  9101. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9102. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9103. //库存不足
  9104. if sum_out_count > drugStockOut.FlushCount {
  9105. this.ServeSuccessJSON(map[string]interface{}{
  9106. "msg": "2",
  9107. "drug": medical,
  9108. "ids": ids,
  9109. })
  9110. return
  9111. }
  9112. }
  9113. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9114. //执行医嘱
  9115. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9116. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9117. for _, item := range advices {
  9118. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9119. redis := service.RedisClient()
  9120. //清空key 值
  9121. redis.Set(key, "", time.Second)
  9122. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9123. redis.Set(keyTwo, "", time.Second)
  9124. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9125. redis.Set(keyThree, "", time.Second)
  9126. recordDate := theTime.Format("2006-01-02")
  9127. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9128. redis.Set(keyFour, "", time.Second)
  9129. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9130. redis.Set(keyFive, "", time.Second)
  9131. defer redis.Close()
  9132. }
  9133. if errs == nil {
  9134. //药品管理信息
  9135. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9136. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9137. if drugStockConfig.IsOpen == 1 {
  9138. for _, item := range advices {
  9139. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9140. config, _ := service.GetDrugOpenConfigOne(orgId)
  9141. if config.IsOpen != 1 {
  9142. //查询该药品是否有库存
  9143. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9144. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9145. if medical.IsUse == 2 {
  9146. if config.IsOpen != 1 {
  9147. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9148. service.HisDrugsDelivery(orgId, creater, &advice)
  9149. if orgId == 3877 || orgId == 10265 {
  9150. //查询该药品是否有出库记录
  9151. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9152. if len(flowMap) == 0 {
  9153. errs := service.UpdateHisAdviceById(advice.ID)
  9154. if errs != nil {
  9155. drugError := models.XtDrugError{
  9156. UserOrgId: orgId,
  9157. DrugId: item.DrugId,
  9158. RecordDate: item.AdviceDate,
  9159. PatientId: item.PatientId,
  9160. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9161. Status: 1,
  9162. Ctime: time.Now().Unix(),
  9163. Mtime: 0,
  9164. SumCount: 0,
  9165. Prescribingnumber: advice.PrescribingNumber,
  9166. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9167. }
  9168. service.CreateDrugError(drugError)
  9169. }
  9170. this.ServeSuccessJSON(map[string]interface{}{
  9171. "msg": "2",
  9172. "drug": medical,
  9173. "ids": ids,
  9174. })
  9175. return
  9176. }
  9177. }
  9178. }
  9179. if pharmacyConfig.IsOpen != 1 {
  9180. service.HisDrugsDelivery(orgId, creater, &advice)
  9181. if orgId == 3877 || orgId == 10265 {
  9182. //查询该药品是否有出库记录
  9183. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9184. if len(flowMap) == 0 {
  9185. errs := service.UpdateHisAdviceById(advice.ID)
  9186. if errs != nil {
  9187. drugError := models.XtDrugError{
  9188. UserOrgId: orgId,
  9189. DrugId: item.DrugId,
  9190. RecordDate: item.AdviceDate,
  9191. PatientId: item.PatientId,
  9192. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9193. Status: 1,
  9194. Ctime: time.Now().Unix(),
  9195. Mtime: 0,
  9196. SumCount: 0,
  9197. Prescribingnumber: advice.PrescribingNumber,
  9198. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9199. }
  9200. service.CreateDrugError(drugError)
  9201. }
  9202. this.ServeSuccessJSON(map[string]interface{}{
  9203. "msg": "2",
  9204. "drug": medical,
  9205. "ids": ids,
  9206. })
  9207. return
  9208. }
  9209. }
  9210. }
  9211. //更新字典里面的库存
  9212. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9213. var sum_count int64
  9214. for _, its := range stockInfo {
  9215. if its.MaxUnit == medical.MaxUnit {
  9216. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9217. }
  9218. sum_count += its.StockMaxNumber + its.StockMinNumber
  9219. }
  9220. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9221. //剩余库存
  9222. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9223. }
  9224. }
  9225. }
  9226. }
  9227. }
  9228. this.ServeSuccessJSON(map[string]interface{}{
  9229. "msg": "1",
  9230. "ids": ids,
  9231. })
  9232. return
  9233. } else {
  9234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9235. }
  9236. }
  9237. //血透客户
  9238. if config.IsOpen == 2 || config.IsOpen == 0 {
  9239. //药品管理信息
  9240. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9241. if drugStockConfig.IsOpen == 1 {
  9242. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9243. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9244. for _, item := range list {
  9245. for _, it := range adviceList {
  9246. if item.DrugId == it.DrugId {
  9247. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9248. }
  9249. }
  9250. }
  9251. for _, item := range list {
  9252. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9253. var sum_out_count int64
  9254. for _, itemThree := range item.ChildDoctorAdvice {
  9255. var prescribing_number int64
  9256. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9257. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9258. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9259. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9260. }
  9261. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9262. prescribing_number = parseIntPrescribingNumber
  9263. }
  9264. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9265. prescribing_number = parseIntPrescribingNumber
  9266. }
  9267. sum_out_count += prescribing_number
  9268. }
  9269. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9270. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9271. //库存不足
  9272. if sum_out_count > drugStockOut.FlushCount {
  9273. this.ServeSuccessJSON(map[string]interface{}{
  9274. "msg": "2",
  9275. "drug": medical,
  9276. "ids": ids,
  9277. })
  9278. return
  9279. }
  9280. }
  9281. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9282. //执行医嘱
  9283. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9284. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9285. for _, item := range advices {
  9286. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9287. redis := service.RedisClient()
  9288. //清空key 值
  9289. redis.Set(key, "", time.Second)
  9290. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9291. redis.Set(keyTwo, "", time.Second)
  9292. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9293. redis.Set(keyThree, "", time.Second)
  9294. recordDate := theTime.Format("2006-01-02")
  9295. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9296. redis.Set(keyFour, "", time.Second)
  9297. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9298. redis.Set(keyFive, "", time.Second)
  9299. defer redis.Close()
  9300. }
  9301. if errs == nil {
  9302. for _, item := range advices {
  9303. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9304. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9305. //查询是否出库按钮开启
  9306. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9307. if adviceSetting.IsAdviceOpen == 1 {
  9308. //查询是否出库按钮开启
  9309. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9310. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9311. if prescriptionConfig.IsOpen == 1 {
  9312. if medical.IsUse == 2 {
  9313. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9314. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9315. }
  9316. if pharmacyConfig.IsOpen != 1 {
  9317. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9318. }
  9319. //更新字典里面的库存
  9320. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9321. var sum_count int64
  9322. for _, its := range stockInfo {
  9323. if its.MaxUnit == medical.MaxUnit {
  9324. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9325. }
  9326. sum_count += its.StockMaxNumber + its.StockMinNumber
  9327. }
  9328. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9329. //剩余库存
  9330. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9331. }
  9332. }
  9333. } else {
  9334. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9335. if medical.IsUse == 2 {
  9336. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9337. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9338. }
  9339. if pharmacyConfig.IsOpen != 1 {
  9340. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9341. }
  9342. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9343. var sum_count int64
  9344. for _, its := range stockInfo {
  9345. if its.MaxUnit == medical.MaxUnit {
  9346. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9347. }
  9348. sum_count += its.StockMaxNumber + its.StockMinNumber
  9349. }
  9350. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9351. //剩余库存
  9352. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9353. }
  9354. }
  9355. }
  9356. }
  9357. this.ServeSuccessJSON(map[string]interface{}{
  9358. "msg": "1",
  9359. "ids": ids,
  9360. })
  9361. return
  9362. } else {
  9363. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9364. //执行医嘱
  9365. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9366. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9367. for _, item := range advices {
  9368. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9369. redis := service.RedisClient()
  9370. //清空key 值
  9371. redis.Set(key, "", time.Second)
  9372. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9373. redis.Set(keyTwo, "", time.Second)
  9374. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9375. redis.Set(keyThree, "", time.Second)
  9376. recordDate := theTime.Format("2006-01-02")
  9377. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9378. redis.Set(keyFour, "", time.Second)
  9379. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9380. redis.Set(keyFive, "", time.Second)
  9381. defer redis.Close()
  9382. }
  9383. this.ServeSuccessJSON(map[string]interface{}{
  9384. "msg": "1",
  9385. "ids": ids,
  9386. })
  9387. return
  9388. }
  9389. }
  9390. }
  9391. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9392. ids := this.GetString("ids")
  9393. idSplit := strings.Split(ids, ",")
  9394. orgId := this.GetMobileAdminUserInfo().Org.Id
  9395. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9396. if config.IsOpen == 1 {
  9397. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9398. this.ServeSuccessJSON(map[string]interface{}{
  9399. "msg": "1",
  9400. "ids": ids,
  9401. })
  9402. return
  9403. }
  9404. if config.IsOpen == 0 || config.IsOpen == 2 {
  9405. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9406. this.ServeSuccessJSON(map[string]interface{}{
  9407. "msg": "1",
  9408. "ids": ids,
  9409. })
  9410. return
  9411. }
  9412. }
  9413. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9414. ids := this.GetString("ids")
  9415. idSplit := strings.Split(ids, ",")
  9416. orgId := this.GetMobileAdminUserInfo().Org.Id
  9417. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9418. //his
  9419. if config.IsOpen == 1 {
  9420. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9421. theTime := time.Now()
  9422. advices := models.HisDoctorAdviceThirty{
  9423. CheckTime: theTime.Unix(),
  9424. Checker: checker,
  9425. UpdatedTime: time.Now().Unix(),
  9426. }
  9427. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9428. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9429. for _, item := range list {
  9430. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9431. redis := service.RedisClient()
  9432. //清空key 值
  9433. redis.Set(key, "", time.Second)
  9434. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9435. redis.Set(keyTwo, "", time.Second)
  9436. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9437. redis.Set(keyThree, "", time.Second)
  9438. recordDate := theTime.Format("2006-01-02")
  9439. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9440. redis.Set(keyFour, "", time.Second)
  9441. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9442. redis.Set(keyFive, "", time.Second)
  9443. defer redis.Close()
  9444. }
  9445. this.ServeSuccessJSON(map[string]interface{}{
  9446. "msg": "1",
  9447. "ids": ids,
  9448. })
  9449. return
  9450. }
  9451. //血透
  9452. if config.IsOpen == 0 || config.IsOpen == 2 {
  9453. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9454. theTime := time.Now()
  9455. advices := models.DoctorAdvice{
  9456. CheckTime: theTime.Unix(),
  9457. Checker: checker,
  9458. UpdatedTime: time.Now().Unix(),
  9459. }
  9460. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9461. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9462. for _, item := range list {
  9463. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9464. redis := service.RedisClient()
  9465. //清空key 值
  9466. redis.Set(key, "", time.Second)
  9467. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9468. redis.Set(keyTwo, "", time.Second)
  9469. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9470. redis.Set(keyThree, "", time.Second)
  9471. recordDate := theTime.Format("2006-01-02")
  9472. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9473. redis.Set(keyFour, "", time.Second)
  9474. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9475. redis.Set(keyFive, "", time.Second)
  9476. defer redis.Close()
  9477. }
  9478. this.ServeSuccessJSON(map[string]interface{}{
  9479. "msg": "1",
  9480. "ids": ids,
  9481. })
  9482. return
  9483. }
  9484. }
  9485. func (this *DialysisAPIController) CheckSchedule() {
  9486. patientID, _ := this.GetInt64("patient_id")
  9487. recordDateStr := this.GetString("record_date")
  9488. nurseID, _ := this.GetInt64("start_nurse")
  9489. schedual_type, _ := this.GetInt64("schedual_type")
  9490. bedID, _ := this.GetInt64("bed")
  9491. start_time := this.GetString("start_time")
  9492. fmt.Println("patientID", patientID)
  9493. fmt.Println("recordDateStr", recordDateStr)
  9494. fmt.Println("nurseID", nurseID)
  9495. fmt.Println("schedual_type------", schedual_type)
  9496. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9498. return
  9499. }
  9500. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9501. if parseStartDateErr != nil {
  9502. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9504. return
  9505. }
  9506. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9507. if parseErr != nil {
  9508. this.ErrorLog("时间解析失败:%v", parseErr)
  9509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9510. return
  9511. }
  9512. adminUserInfo := this.GetMobileAdminUserInfo()
  9513. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9514. if getPatientErr != nil {
  9515. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9517. return
  9518. } else if patient == nil {
  9519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9520. return
  9521. }
  9522. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9523. if getNurseErr != nil {
  9524. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9526. return
  9527. } else if nurse == nil {
  9528. this.ErrorLog("护士不存在")
  9529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9530. return
  9531. }
  9532. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9533. if getDeviceNumberErr != nil {
  9534. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9536. return
  9537. } else if deviceNumber == nil {
  9538. this.ErrorLog("床位号不存在")
  9539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9540. return
  9541. }
  9542. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9543. if getRecordErr != nil {
  9544. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9546. return
  9547. } else if dialysisRecord != nil {
  9548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9549. return
  9550. }
  9551. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9552. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9553. timeLayout := "2006-01-02 15:04:05"
  9554. loc, _ := time.LoadLocation("Local")
  9555. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9556. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9557. schedulestartTime := theStartTime.Unix()
  9558. scheduleendTime := theEndTime.Unix()
  9559. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9560. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9561. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9562. //查询该床位是否有人用了
  9563. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9564. if err == nil {
  9565. if schedule.ID == 0 {
  9566. this.ServeSuccessJSON(map[string]interface{}{
  9567. "status": 0,
  9568. "msg": "请求失败",
  9569. })
  9570. } else {
  9571. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9572. if order.ID > 0 { //该机位被其他人占用了
  9573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9574. return
  9575. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9576. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9577. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9578. this.ServeSuccessJSON(map[string]interface{}{
  9579. "status": 1,
  9580. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9581. })
  9582. return
  9583. } else {
  9584. this.ServeSuccessJSON(map[string]interface{}{
  9585. "status": 0,
  9586. "msg": "",
  9587. })
  9588. }
  9589. }
  9590. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9591. this.ServeSuccessJSON(map[string]interface{}{
  9592. "status": 2,
  9593. "msg": "当前机位已有患者在使用,请重新选择!",
  9594. })
  9595. }
  9596. }
  9597. } else {
  9598. this.ServeSuccessJSON(map[string]interface{}{
  9599. "status": 0,
  9600. "msg": "",
  9601. })
  9602. }
  9603. }
  9604. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9605. orgId := this.GetMobileAdminUserInfo().Org.Id
  9606. schedule_type, _ := this.GetInt64("schedule_type")
  9607. partion_type, _ := this.GetInt64("partion_type")
  9608. start_time := this.GetString("start_time")
  9609. timeLayout := "2006-01-02"
  9610. loc, _ := time.LoadLocation("Local")
  9611. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9612. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9613. _, config := service.FindXTHisRecordByOrgId(orgId)
  9614. appId := this.GetMobileAdminUserInfo().App.Id
  9615. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9616. if err == nil {
  9617. this.ServeSuccessJSON(map[string]interface{}{
  9618. "list": list,
  9619. "config": config,
  9620. "doctorList": doctorList,
  9621. })
  9622. return
  9623. } else {
  9624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9625. return
  9626. }
  9627. }
  9628. func (this *DialysisAPIController) SaveMobileInformation() {
  9629. patient_id, _ := this.GetInt64("patient_id")
  9630. record_date, _ := this.GetInt64("record_date")
  9631. startTime := this.GetString("start_time")
  9632. module, _ := this.GetInt64("module")
  9633. remark := this.GetString("remark")
  9634. timeLayout := "2006-01-02 15:04"
  9635. loc, _ := time.LoadLocation("Local")
  9636. if len(startTime) == 0 {
  9637. utils.ErrorLog("len(start_time) == 0")
  9638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9639. return
  9640. }
  9641. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9642. if err != nil {
  9643. utils.ErrorLog(err.Error())
  9644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9645. return
  9646. }
  9647. StartTime := theTime.Unix()
  9648. fmt.Println("startime-------------", StartTime)
  9649. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9650. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9651. information := models.XtDialysisInformation{
  9652. Module: module,
  9653. PatientId: patient_id,
  9654. RecordDate: record_date,
  9655. ApplicationDate: StartTime,
  9656. Creater: creater,
  9657. ApplicationStatus: 2,
  9658. Checker: 0,
  9659. CheckTime: 0,
  9660. Remark: remark,
  9661. UserOrgId: user_org_id,
  9662. Ctime: time.Now().Unix(),
  9663. Status: 1,
  9664. Mtime: 0,
  9665. }
  9666. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9667. if infor.ID == 0 {
  9668. service.SaveDialysisInformation(information)
  9669. }
  9670. if infor.ID > 0 {
  9671. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9672. }
  9673. this.ServeSuccessJSON(map[string]interface{}{
  9674. "information": information,
  9675. })
  9676. return
  9677. }
  9678. func (this *DialysisAPIController) GetMobileInformation() {
  9679. limit, _ := this.GetInt64("limit")
  9680. page, _ := this.GetInt64("page")
  9681. orgid := this.GetMobileAdminUserInfo().Org.Id
  9682. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9683. appid := this.GetMobileAdminUserInfo().App.Id
  9684. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9685. patients, _ := service.GetAllpatientThirty(orgid)
  9686. this.ServeSuccessJSON(map[string]interface{}{
  9687. "information": information,
  9688. "total": total,
  9689. "doclist": doclist,
  9690. "patients": patients,
  9691. })
  9692. return
  9693. }
  9694. func (this *DialysisAPIController) GetMobileInformationOne() {
  9695. limit, _ := this.GetInt64("limit")
  9696. page, _ := this.GetInt64("page")
  9697. orgid := this.GetMobileAdminUserInfo().Org.Id
  9698. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9699. appid := this.GetMobileAdminUserInfo().App.Id
  9700. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9701. patients, _ := service.GetAllpatientThirty(orgid)
  9702. this.ServeSuccessJSON(map[string]interface{}{
  9703. "information": information,
  9704. "total": total,
  9705. "doclist": doclist,
  9706. "patients": patients,
  9707. })
  9708. return
  9709. }
  9710. func (this *DialysisAPIController) CheckMobileInformation() {
  9711. id, _ := this.GetInt64("id")
  9712. application_status, _ := this.GetInt64("application_status")
  9713. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9714. checktime := time.Now().Unix()
  9715. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9716. if err == nil {
  9717. this.ServeSuccessJSON(map[string]interface{}{
  9718. "msg": "ok",
  9719. })
  9720. return
  9721. }
  9722. }
  9723. func (c *DialysisAPIController) GetControlMonitorList() {
  9724. partition, _ := c.GetInt64("partition")
  9725. monitorDate := c.GetString("date")
  9726. patient_id, _ := c.GetInt64("patient_id")
  9727. pat_type, _ := c.GetInt64("pat_type")
  9728. timeLayout := "2006-01-02"
  9729. loc, _ := time.LoadLocation("Local")
  9730. var theStartTime int64
  9731. if len(monitorDate) > 0 {
  9732. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9733. if err != nil {
  9734. theStartTime = 0
  9735. }
  9736. theStartTime = theTime.Unix()
  9737. }
  9738. adminInfo := c.GetMobileAdminUserInfo()
  9739. orgID := adminInfo.Org.Id
  9740. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9741. if err != nil {
  9742. c.ErrorLog("获取排班信息失败:%v", err)
  9743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9744. } else {
  9745. if len(monitor) > 0 {
  9746. //获取所有床位
  9747. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9748. //获取所有分区
  9749. zoneList, _ := service.GetAllZoneByList(orgID)
  9750. //获取透析处方
  9751. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9752. //获取透前评估
  9753. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9754. //获取上机
  9755. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9756. //获取透后
  9757. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9758. //获取透后监测
  9759. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9760. //获取所有的患者
  9761. patients, _ := service.GetAllPatientListByListOne(orgID)
  9762. //获取所有透析模式
  9763. treatments, _ := service.GetAllTreatModeByList(orgID)
  9764. //获取所有医嘱
  9765. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9766. //获取双人核对
  9767. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9768. //治疗小结
  9769. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9770. //待消毒
  9771. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9772. for key, item := range monitor {
  9773. // 获取床位信息
  9774. for _, it := range numberList {
  9775. if item.BedId == it.ID {
  9776. monitor[key].DeviceNumber = it
  9777. break
  9778. }
  9779. }
  9780. //获取分区信息
  9781. for _, it := range zoneList {
  9782. if item.PartitionId == it.ID {
  9783. monitor[key].DeviceZone = it
  9784. }
  9785. }
  9786. for _, prescription := range prescriptions {
  9787. if item.PatientId == prescription.PatientId {
  9788. monitor[key].Prescription = prescription
  9789. break
  9790. }
  9791. }
  9792. for _, it := range checkList {
  9793. if item.PatientId == it.PatientId {
  9794. monitor[key].DoubleCheck = it
  9795. break
  9796. }
  9797. }
  9798. for _, it := range summaryList {
  9799. if item.PatientId == it.PatientId {
  9800. monitor[key].TreatmentSummaryForList = it
  9801. break
  9802. }
  9803. }
  9804. // 透前评估
  9805. for _, assessmentBefore := range assessmentBefores {
  9806. if item.PatientId == assessmentBefore.PatientId {
  9807. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9808. break
  9809. }
  9810. }
  9811. // 透析上下机
  9812. for _, dialysisOrder := range dialysisOrders {
  9813. if item.PatientId == dialysisOrder.PatientId {
  9814. monitor[key].DialysisOrder = dialysisOrder
  9815. break
  9816. }
  9817. }
  9818. // 治疗小节
  9819. for _, afterDislysis := range AssessmentAfterDislysis {
  9820. if item.PatientId == afterDislysis.PatientId {
  9821. monitor[key].AssessmentAfterDislysis = afterDislysis
  9822. break
  9823. }
  9824. }
  9825. for _, it := range monitorlist {
  9826. if item.PatientId == it.PatientId {
  9827. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9828. }
  9829. }
  9830. for _, it := range adviceList {
  9831. if item.PatientId == it.PatientId {
  9832. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9833. }
  9834. }
  9835. for _, patient := range patients {
  9836. if item.PatientId == patient.ID {
  9837. monitor[key].MonitorPatients = patient
  9838. break
  9839. }
  9840. }
  9841. for _, treatment := range treatments {
  9842. if item.ModeId == treatment.ID {
  9843. monitor[key].TreatmentMode = treatment
  9844. break
  9845. }
  9846. }
  9847. for _, infor := range informationList {
  9848. if item.PatientId == infor.PatientId {
  9849. monitor[key].NewDeviceInformation = infor
  9850. break
  9851. }
  9852. }
  9853. }
  9854. }
  9855. }
  9856. patients, err := service.GetAllpatientFourty(orgID)
  9857. var mds []*models.NewMonitorDialysisScheduleList
  9858. if pat_type == 0 {
  9859. for _, item := range monitor {
  9860. mds = append(mds, item)
  9861. }
  9862. }
  9863. //待医嘱核对
  9864. if pat_type == 1 {
  9865. for _, item := range monitor {
  9866. if len(item.AdviceList) > 0 {
  9867. mds = append(mds, item)
  9868. }
  9869. }
  9870. }
  9871. //待开小结
  9872. if pat_type == 2 {
  9873. for _, item := range monitor {
  9874. if item.TreatmentSummaryForList == nil {
  9875. mds = append(mds, item)
  9876. }
  9877. }
  9878. }
  9879. //待下机
  9880. if pat_type == 3 {
  9881. for _, item := range monitor {
  9882. if item.DialysisOrder != nil {
  9883. if item.DialysisOrder.ID > 0 {
  9884. mds = append(mds, item)
  9885. }
  9886. }
  9887. }
  9888. }
  9889. //待消毒
  9890. if pat_type == 4 {
  9891. for _, item := range monitor {
  9892. if item.NewDeviceInformation == nil {
  9893. mds = append(mds, item)
  9894. }
  9895. }
  9896. }
  9897. //待双人核对
  9898. if pat_type == 5 {
  9899. for _, item := range monitor {
  9900. if item.DoubleCheck == nil {
  9901. mds = append(mds, item)
  9902. }
  9903. }
  9904. }
  9905. //医嘱未执行
  9906. if pat_type == 6 {
  9907. for _, item := range monitor {
  9908. if len(item.AdviceList) > 0 {
  9909. mds = append(mds, item)
  9910. }
  9911. }
  9912. }
  9913. //患者未签名
  9914. if pat_type == 7 {
  9915. for _, item := range monitor {
  9916. if item.DialysisOrder != nil {
  9917. if item.DialysisOrder.ID > 0 {
  9918. mds = append(mds, item)
  9919. }
  9920. }
  9921. }
  9922. }
  9923. //目标超滤于实际超滤不同
  9924. if pat_type == 8 {
  9925. for _, item := range monitor {
  9926. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9927. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9928. mds = append(mds, item)
  9929. }
  9930. }
  9931. }
  9932. }
  9933. //血压少于5次
  9934. if pat_type == 9 {
  9935. for _, item := range monitor {
  9936. if len(item.MonitoringRecord) < 5 {
  9937. mds = append(mds, item)
  9938. }
  9939. }
  9940. }
  9941. if pat_type == 13 {
  9942. for _, item := range monitor {
  9943. if len(item.MonitoringRecord) < 3 {
  9944. mds = append(mds, item)
  9945. }
  9946. }
  9947. }
  9948. if pat_type == 10 {
  9949. for _, item := range monitor {
  9950. if len(item.MonitoringRecord) == 0 {
  9951. mds = append(mds, item)
  9952. }
  9953. }
  9954. }
  9955. if pat_type == 11 {
  9956. for _, item := range monitor {
  9957. if len(item.MonitoringRecord) > 0 {
  9958. mds = append(mds, item)
  9959. }
  9960. }
  9961. }
  9962. if pat_type == 12 {
  9963. for _, item := range monitor {
  9964. if len(item.MonitoringRecord) > 0 {
  9965. mds = append(mds, item)
  9966. }
  9967. }
  9968. }
  9969. if err == nil {
  9970. c.ServeSuccessJSON(map[string]interface{}{
  9971. "monitor": mds,
  9972. "patients": patients,
  9973. })
  9974. } else {
  9975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9976. }
  9977. }
  9978. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9979. admin_user_id, _ := c.GetInt64("admin_user_id")
  9980. timeStr := time.Now().Format("2006-01-02")
  9981. timeLayout := "2006-01-02 15:04:05"
  9982. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9983. timenow := timeStringToTime.Unix()
  9984. orgId := c.GetMobileAdminUserInfo().Org.Id
  9985. //查询当前护士的患者
  9986. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9987. var patientIds []int64
  9988. for _, item := range orderList {
  9989. patientIds = append(patientIds, item.PatientId)
  9990. }
  9991. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9992. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9993. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9994. //药品管理信息
  9995. _, drugStockConfig := service.FindHisConfig(orgId)
  9996. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9997. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9998. c.ServeSuccessJSON(map[string]interface{}{
  9999. "adviceList": adviceList,
  10000. "hisAdviceList": hisAdviceList,
  10001. "projectList": projectList,
  10002. "drugStockConfig": drugStockConfig,
  10003. "patientList": patientList,
  10004. "projectConfig": projectConfig,
  10005. })
  10006. }
  10007. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10008. patient_id, _ := c.GetInt64("patient_id")
  10009. org_id := c.GetMobileAdminUserInfo().Org.Id
  10010. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10011. c.ServeSuccessJSON(map[string]interface{}{
  10012. "recrods": recrods,
  10013. })
  10014. }
  10015. func (c *DialysisAPIController) ExMobileChangeSch() {
  10016. id_one, _ := c.GetInt64("id_one")
  10017. id_two, _ := c.GetInt64("id_two")
  10018. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10019. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10020. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10021. //if order2.ID > 0 {
  10022. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10023. // return
  10024. //}
  10025. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10026. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10027. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10028. if count > 0 {
  10029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10030. return
  10031. }
  10032. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10033. if count1 > 0 {
  10034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10035. return
  10036. }
  10037. }
  10038. err := service.UpdateScheduleThree(sch, sch_two)
  10039. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10040. if order.ID > 0 {
  10041. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10042. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10043. redis := service.RedisClient()
  10044. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10045. redis.Set(key, "", time.Second)
  10046. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10047. //清空key 值
  10048. redis.Set(keyOne, "", time.Second)
  10049. }
  10050. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10051. if orderOne.ID > 0 {
  10052. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10053. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10054. redis := service.RedisClient()
  10055. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10056. redis.Set(key, "", time.Second)
  10057. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10058. //清空key 值
  10059. redis.Set(keyOne, "", time.Second)
  10060. }
  10061. if err == nil {
  10062. //去除当天患者排班中重复数据,保留最后一条数据
  10063. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10064. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10065. c.ServeSuccessJSON(map[string]interface{}{
  10066. "msg": "交换成功",
  10067. })
  10068. } else {
  10069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10070. return
  10071. }
  10072. }
  10073. func (c *DialysisAPIController) MobileCoverSch() {
  10074. id_one, _ := c.GetInt64("id_one")
  10075. id_two, _ := c.GetInt64("id_two")
  10076. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10077. //针对凤凰医院
  10078. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10079. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10080. if len(advice) > 0 {
  10081. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10082. }
  10083. }
  10084. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10085. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10086. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10087. if len(hisAdvice) > 0 {
  10088. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10089. }
  10090. if len(project) > 0 {
  10091. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10092. }
  10093. }
  10094. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10095. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10096. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10097. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10098. if count > 0 {
  10099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10100. return
  10101. }
  10102. }
  10103. var new_sch models.Schedule
  10104. new_sch = sch
  10105. new_sch.BedId = sch_two.BedId
  10106. new_sch.ScheduleDate = sch_two.ScheduleDate
  10107. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10108. new_sch.PartitionId = sch_two.PartitionId
  10109. new_sch.ScheduleType = sch_two.ScheduleType
  10110. new_sch.ID = 0
  10111. //删除原来的排班
  10112. err := service.SaveSchTwo(sch, sch_two)
  10113. //生成新的排班
  10114. if err == nil {
  10115. err2 := service.SaveSch(&new_sch)
  10116. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10117. if order.ID > 0 {
  10118. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10119. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10120. redis := service.RedisClient()
  10121. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10122. redis.Set(key, "", time.Second)
  10123. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10124. //清空key 值
  10125. redis.Set(keyOne, "", time.Second)
  10126. }
  10127. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10128. if orderOne.ID > 0 {
  10129. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10130. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10131. redis := service.RedisClient()
  10132. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10133. redis.Set(key, "", time.Second)
  10134. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10135. //清空key 值
  10136. redis.Set(keyOne, "", time.Second)
  10137. }
  10138. if err2 == nil {
  10139. //去除当天患者排班中重复数据,保留最后一条数据
  10140. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10141. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10142. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10143. c.ServeSuccessJSON(map[string]interface{}{
  10144. "msg": "覆盖成功",
  10145. "new_sch": new_sch,
  10146. })
  10147. } else {
  10148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10149. return
  10150. }
  10151. } else {
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10153. return
  10154. }
  10155. }
  10156. func (c *DialysisAPIController) BatchCheckAdvice() {
  10157. patient_id, _ := c.GetInt64("patient_id")
  10158. advice_date, _ := c.GetInt64("advice_date")
  10159. org_id := c.GetMobileAdminUserInfo().Org.Id
  10160. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10161. //查询是his系统还是血透系统
  10162. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10163. //his客户
  10164. if configs.IsOpen == 1 {
  10165. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10166. for _, item := range adviceList {
  10167. service.BatchCheckHisAdvice(item.ID, creater)
  10168. }
  10169. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10170. for _, item := range projectList {
  10171. service.BatchCheckProject(item.ID, creater)
  10172. }
  10173. c.ServeSuccessJSON(map[string]interface{}{
  10174. "adviceList": adviceList,
  10175. "projectList": projectList,
  10176. })
  10177. }
  10178. if configs.IsOpen != 1 {
  10179. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10180. for _, item := range adviceList {
  10181. service.BatchAdviceList(item.ID, creater)
  10182. }
  10183. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10184. for _, item := range projectList {
  10185. service.BatchCheckProject(item.ID, creater)
  10186. }
  10187. c.ServeSuccessJSON(map[string]interface{}{
  10188. "adviceList": adviceList,
  10189. "projectList": projectList,
  10190. })
  10191. }
  10192. return
  10193. }
  10194. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10195. org_id := c.GetMobileAdminUserInfo().Org.Id
  10196. drugList, _ := service.GetAllDrugList(org_id)
  10197. c.ServeSuccessJSON(map[string]interface{}{
  10198. "drugList": drugList,
  10199. })
  10200. }
  10201. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10202. org_id := c.GetMobileAdminUserInfo().Org.Id
  10203. dataBody := make(map[string]interface{}, 0)
  10204. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10205. if err != nil {
  10206. utils.ErrorLog(err.Error())
  10207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10208. return
  10209. }
  10210. timeLayout := "2006-01-02"
  10211. loc, _ := time.LoadLocation("Local")
  10212. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10213. utils.ErrorLog("advice_type")
  10214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10215. return
  10216. }
  10217. adviceType := int64(dataBody["advice_type"].(float64))
  10218. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10219. utils.ErrorLog("start_time")
  10220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10221. return
  10222. }
  10223. startTime2, _ := dataBody["start_time"].(string)
  10224. time_arr := strings.Split(startTime2, " ")
  10225. if len(time_arr) > 0 {
  10226. startTime2 = time_arr[0]
  10227. }
  10228. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10229. utils.ErrorLog("advice_date")
  10230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10231. return
  10232. }
  10233. advice_date, _ := dataBody["advice_date"].(string)
  10234. var advicedateunix int64
  10235. if len(advice_date) > 0 {
  10236. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10237. if err != nil {
  10238. fmt.Println(err)
  10239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10240. return
  10241. }
  10242. advicedateunix = theTime.Unix()
  10243. }
  10244. adviceDate := startTime2
  10245. if len(adviceDate) == 0 {
  10246. utils.ErrorLog("len(adviceDate) == 0")
  10247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10248. return
  10249. }
  10250. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10251. if err != nil {
  10252. utils.ErrorLog(err.Error())
  10253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10254. return
  10255. }
  10256. AdviceDate := advicedateunix
  10257. RecordDate := advicedateunix
  10258. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10259. utils.ErrorLog("start_time")
  10260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10261. return
  10262. }
  10263. startTime, _ := dataBody["start_time"].(string)
  10264. if len(startTime) == 0 {
  10265. utils.ErrorLog("len(start_time) == 0")
  10266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10267. return
  10268. }
  10269. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10270. if err != nil {
  10271. utils.ErrorLog(err.Error())
  10272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10273. return
  10274. }
  10275. StartTime := theTime.Unix()
  10276. advice_name, _ := dataBody["advice_name"].(string)
  10277. advice_desc, _ := dataBody["advice_desc"].(string)
  10278. delivery_way, _ := dataBody["delivery_way"].(string)
  10279. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10280. frequency_type := int64(dataBody["frequency_type"].(float64))
  10281. frequency_week, _ := dataBody["frequency_week"].(string)
  10282. prescribing_number := dataBody["prescribing_number"].(float64)
  10283. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10284. remark := dataBody["remark"].(string)
  10285. single_dose := dataBody["single_dose"].(float64)
  10286. single_dose_unit := dataBody["single_dose_unit"].(string)
  10287. patient_id := int64(dataBody["patient_id"].(float64))
  10288. day_count := int64(dataBody["day_count"].(float64))
  10289. groupNo := int64(dataBody["group_no"].(float64))
  10290. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10291. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10292. if groupNo <= 0 {
  10293. group := service.GetMaxAdviceGroupID(org_id)
  10294. groupNo = group + 1
  10295. }
  10296. var template_id = ""
  10297. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10298. template_id = "M" + adviceLastId
  10299. advice := models.DoctorAdvice{
  10300. UserOrgId: org_id,
  10301. PatientId: patient_id,
  10302. AdviceType: adviceType,
  10303. AdviceDate: AdviceDate,
  10304. StartTime: StartTime,
  10305. AdviceName: advice_name,
  10306. AdviceDesc: advice_desc,
  10307. ReminderDate: 0,
  10308. SingleDose: single_dose,
  10309. SingleDoseUnit: single_dose_unit,
  10310. DrugSpec: 0,
  10311. DrugSpecUnit: "",
  10312. PrescribingNumber: prescribing_number,
  10313. PrescribingNumberUnit: prescribing_number_unit,
  10314. DeliveryWay: delivery_way,
  10315. ExecutionFrequency: execution_frequency,
  10316. AdviceDoctor: advice_doctor,
  10317. Status: 1,
  10318. CreatedTime: time.Now().Unix(),
  10319. UpdatedTime: 0,
  10320. AdviceAffirm: "",
  10321. Remark: remark,
  10322. StopTime: 0,
  10323. StopReason: "",
  10324. StopDoctor: 0,
  10325. StopState: 0,
  10326. ParentId: 0,
  10327. ExecutionTime: 0,
  10328. ExecutionStaff: 0,
  10329. ExecutionState: 0,
  10330. Checker: 0,
  10331. RecordDate: RecordDate,
  10332. DialysisOrderId: 0,
  10333. CheckTime: 0,
  10334. CheckState: 0,
  10335. AdviceId: 0,
  10336. RemindType: 0,
  10337. FrequencyType: frequency_type,
  10338. DayCount: day_count,
  10339. WeekDay: frequency_week,
  10340. ChildDoctorAdvice: nil,
  10341. TemplateId: template_id,
  10342. Modifier: 0,
  10343. IsCheck: 0,
  10344. Way: 0,
  10345. DrugId: 0,
  10346. DrugNameId: 0,
  10347. IsMedicine: 0,
  10348. PushStartTime: 0,
  10349. IsSettle: 0,
  10350. IsPrescription: 0,
  10351. GroupNo: groupNo,
  10352. }
  10353. service.CreateMobileAdivce(advice)
  10354. c.ServeSuccessJSON(map[string]interface{}{
  10355. "msg": "保存成功!",
  10356. })
  10357. }
  10358. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10359. patient_id, _ := c.GetInt64("patient_id")
  10360. org_id := c.GetMobileAdminUserInfo().Org.Id
  10361. app_id := c.GetMobileAdminUserInfo().App.Id
  10362. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10363. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10364. c.ServeSuccessJSON(map[string]interface{}{
  10365. "adviceList": adviceList,
  10366. "adminRoles": adminRoles,
  10367. })
  10368. }
  10369. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10370. org_id := c.GetMobileAdminUserInfo().Org.Id
  10371. dataBody := make(map[string]interface{}, 0)
  10372. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10373. if err != nil {
  10374. utils.ErrorLog(err.Error())
  10375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10376. return
  10377. }
  10378. timeLayout := "2006-01-02"
  10379. loc, _ := time.LoadLocation("Local")
  10380. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10381. utils.ErrorLog("start_time")
  10382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10383. return
  10384. }
  10385. startTime2, _ := dataBody["start_time"].(string)
  10386. time_arr := strings.Split(startTime2, " ")
  10387. if len(time_arr) > 0 {
  10388. startTime2 = time_arr[0]
  10389. }
  10390. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10391. utils.ErrorLog("advice_date")
  10392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10393. return
  10394. }
  10395. advice_date, _ := dataBody["advice_date"].(string)
  10396. var advicedateunix int64
  10397. if len(advice_date) > 0 {
  10398. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10399. if err != nil {
  10400. fmt.Println(err)
  10401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10402. return
  10403. }
  10404. advicedateunix = theTime.Unix()
  10405. }
  10406. adviceDate := startTime2
  10407. if len(adviceDate) == 0 {
  10408. utils.ErrorLog("len(adviceDate) == 0")
  10409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10410. return
  10411. }
  10412. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10413. if err != nil {
  10414. utils.ErrorLog(err.Error())
  10415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10416. return
  10417. }
  10418. AdviceDate := advicedateunix
  10419. RecordDate := advicedateunix
  10420. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10421. utils.ErrorLog("start_time")
  10422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10423. return
  10424. }
  10425. startTime, _ := dataBody["start_time"].(string)
  10426. if len(startTime) == 0 {
  10427. utils.ErrorLog("len(start_time) == 0")
  10428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10429. return
  10430. }
  10431. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10432. if err != nil {
  10433. utils.ErrorLog(err.Error())
  10434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10435. return
  10436. }
  10437. StartTime := theTime.Unix()
  10438. advice_name, _ := dataBody["advice_name"].(string)
  10439. advice_desc, _ := dataBody["advice_desc"].(string)
  10440. delivery_way, _ := dataBody["delivery_way"].(string)
  10441. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10442. prescribing_number := dataBody["prescribing_number"].(float64)
  10443. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10444. remark := dataBody["remark"].(string)
  10445. single_dose := dataBody["single_dose"].(float64)
  10446. single_dose_unit := dataBody["single_dose_unit"].(string)
  10447. patient_id := int64(dataBody["patient_id"].(float64))
  10448. groupNo := int64(dataBody["group_no"].(float64))
  10449. parent_id := int64(dataBody["parent_id"].(float64))
  10450. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10451. advice := models.XtDoctorAdviceOne{
  10452. UserOrgId: org_id,
  10453. PatientId: patient_id,
  10454. AdviceType: 1,
  10455. AdviceDate: AdviceDate,
  10456. StartTime: StartTime,
  10457. AdviceName: advice_name,
  10458. AdviceDesc: advice_desc,
  10459. ReminderDate: 0,
  10460. SingleDose: single_dose,
  10461. SingleDoseUnit: single_dose_unit,
  10462. PrescribingNumber: prescribing_number,
  10463. PrescribingNumberUnit: prescribing_number_unit,
  10464. DeliveryWay: delivery_way,
  10465. ExecutionFrequency: execution_frequency,
  10466. AdviceDoctor: advice_doctor,
  10467. Status: 1,
  10468. CreatedTime: time.Now().Unix(),
  10469. UpdatedTime: time.Now().Unix(),
  10470. AdviceAffirm: "",
  10471. Remark: remark,
  10472. StopTime: 0,
  10473. StopReason: "",
  10474. StopDoctor: 0,
  10475. StopState: 2,
  10476. ParentId: parent_id,
  10477. ExecutionTime: 0,
  10478. ExecutionStaff: 0,
  10479. ExecutionState: 0,
  10480. Checker: 0,
  10481. RecordDate: RecordDate,
  10482. DialysisOrderId: 0,
  10483. CheckTime: 0,
  10484. CheckState: 0,
  10485. DrugSpec: 0,
  10486. DrugSpecUnit: "",
  10487. Groupno: groupNo,
  10488. RemindType: 0,
  10489. FrequencyType: 0,
  10490. DayCount: 0,
  10491. WeekDay: "",
  10492. TemplateId: "",
  10493. Modifier: 0,
  10494. }
  10495. service.CreateMobileAdivceOne(advice)
  10496. c.ServeSuccessJSON(map[string]interface{}{
  10497. "msg": "保存成功!",
  10498. })
  10499. }
  10500. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10501. id, _ := c.GetInt64("id")
  10502. service.DeleteSelfAdviceSubAdvice(id)
  10503. c.ServeSuccessJSON(map[string]interface{}{
  10504. "msg": "保存成功!",
  10505. })
  10506. }
  10507. func (c *DialysisAPIController) GetEditAdviceAction() {
  10508. id, _ := c.GetInt64("id")
  10509. org_id := c.GetMobileAdminUserInfo().Org.Id
  10510. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10511. drugList, _ := service.GetAllDrugList(org_id)
  10512. c.ServeSuccessJSON(map[string]interface{}{
  10513. "advice": advice,
  10514. "drugList": drugList,
  10515. })
  10516. }
  10517. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10518. dataBody := make(map[string]interface{}, 0)
  10519. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10520. if err != nil {
  10521. utils.ErrorLog(err.Error())
  10522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10523. return
  10524. }
  10525. timeLayout := "2006-01-02"
  10526. loc, _ := time.LoadLocation("Local")
  10527. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10528. utils.ErrorLog("start_time")
  10529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10530. return
  10531. }
  10532. startTime2, _ := dataBody["start_time"].(string)
  10533. time_arr := strings.Split(startTime2, " ")
  10534. if len(time_arr) > 0 {
  10535. startTime2 = time_arr[0]
  10536. }
  10537. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10538. utils.ErrorLog("advice_date")
  10539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10540. return
  10541. }
  10542. advice_date, _ := dataBody["advice_date"].(string)
  10543. var advicedateunix int64
  10544. if len(advice_date) > 0 {
  10545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10546. if err != nil {
  10547. fmt.Println(err)
  10548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10549. return
  10550. }
  10551. advicedateunix = theTime.Unix()
  10552. }
  10553. adviceDate := startTime2
  10554. if len(adviceDate) == 0 {
  10555. utils.ErrorLog("len(adviceDate) == 0")
  10556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10557. return
  10558. }
  10559. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10560. if err != nil {
  10561. utils.ErrorLog(err.Error())
  10562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10563. return
  10564. }
  10565. AdviceDate := advicedateunix
  10566. RecordDate := advicedateunix
  10567. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10568. utils.ErrorLog("start_time")
  10569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10570. return
  10571. }
  10572. startTime, _ := dataBody["start_time"].(string)
  10573. if len(startTime) == 0 {
  10574. utils.ErrorLog("len(start_time) == 0")
  10575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10576. return
  10577. }
  10578. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10579. if err != nil {
  10580. utils.ErrorLog(err.Error())
  10581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10582. return
  10583. }
  10584. StartTime := theTime.Unix()
  10585. advice_name, _ := dataBody["advice_name"].(string)
  10586. advice_desc, _ := dataBody["advice_desc"].(string)
  10587. delivery_way, _ := dataBody["delivery_way"].(string)
  10588. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10589. prescribing_number := dataBody["prescribing_number"].(float64)
  10590. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10591. remark := dataBody["remark"].(string)
  10592. single_dose := dataBody["single_dose"].(float64)
  10593. single_dose_unit := dataBody["single_dose_unit"].(string)
  10594. id := int64(dataBody["id"].(float64))
  10595. frequency_type := int64(dataBody["frequency_type"].(float64))
  10596. frequency_week, _ := dataBody["frequency_week"].(string)
  10597. day_count := int64(dataBody["day_count"].(float64))
  10598. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10599. advice := models.XtDoctorAdviceOne{
  10600. AdviceDate: AdviceDate,
  10601. StartTime: StartTime,
  10602. AdviceName: advice_name,
  10603. AdviceDesc: advice_desc,
  10604. SingleDose: single_dose,
  10605. SingleDoseUnit: single_dose_unit,
  10606. PrescribingNumber: prescribing_number,
  10607. PrescribingNumberUnit: prescribing_number_unit,
  10608. DeliveryWay: delivery_way,
  10609. ExecutionFrequency: execution_frequency,
  10610. AdviceDoctor: advice_doctor,
  10611. Remark: remark,
  10612. RecordDate: RecordDate,
  10613. FrequencyType: frequency_type,
  10614. DayCount: day_count,
  10615. WeekDay: frequency_week,
  10616. }
  10617. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10618. c.ServeSuccessJSON(map[string]interface{}{
  10619. "advice": advice,
  10620. })
  10621. }
  10622. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10623. dataBody := make(map[string]interface{}, 0)
  10624. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10625. if err != nil {
  10626. utils.ErrorLog(err.Error())
  10627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10628. return
  10629. }
  10630. timeLayout := "2006-01-02"
  10631. loc, _ := time.LoadLocation("Local")
  10632. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10633. utils.ErrorLog("start_time")
  10634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10635. return
  10636. }
  10637. startTime2, _ := dataBody["start_time"].(string)
  10638. time_arr := strings.Split(startTime2, " ")
  10639. if len(time_arr) > 0 {
  10640. startTime2 = time_arr[0]
  10641. }
  10642. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10643. utils.ErrorLog("advice_date")
  10644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10645. return
  10646. }
  10647. advice_date, _ := dataBody["advice_date"].(string)
  10648. var advicedateunix int64
  10649. if len(advice_date) > 0 {
  10650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10651. if err != nil {
  10652. fmt.Println(err)
  10653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10654. return
  10655. }
  10656. advicedateunix = theTime.Unix()
  10657. }
  10658. adviceDate := startTime2
  10659. if len(adviceDate) == 0 {
  10660. utils.ErrorLog("len(adviceDate) == 0")
  10661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10662. return
  10663. }
  10664. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10665. if err != nil {
  10666. utils.ErrorLog(err.Error())
  10667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10668. return
  10669. }
  10670. AdviceDate := advicedateunix
  10671. RecordDate := advicedateunix
  10672. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10673. utils.ErrorLog("start_time")
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. startTime, _ := dataBody["start_time"].(string)
  10678. if len(startTime) == 0 {
  10679. utils.ErrorLog("len(start_time) == 0")
  10680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10681. return
  10682. }
  10683. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10684. if err != nil {
  10685. utils.ErrorLog(err.Error())
  10686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10687. return
  10688. }
  10689. StartTime := theTime.Unix()
  10690. advice_name, _ := dataBody["advice_name"].(string)
  10691. advice_desc, _ := dataBody["advice_desc"].(string)
  10692. delivery_way, _ := dataBody["delivery_way"].(string)
  10693. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10694. prescribing_number := dataBody["prescribing_number"].(float64)
  10695. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10696. remark := dataBody["remark"].(string)
  10697. single_dose := dataBody["single_dose"].(float64)
  10698. single_dose_unit := dataBody["single_dose_unit"].(string)
  10699. id := int64(dataBody["id"].(float64))
  10700. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10701. advice := models.XtDoctorAdviceOne{
  10702. AdviceDate: AdviceDate,
  10703. StartTime: StartTime,
  10704. AdviceName: advice_name,
  10705. AdviceDesc: advice_desc,
  10706. SingleDose: single_dose,
  10707. SingleDoseUnit: single_dose_unit,
  10708. PrescribingNumber: prescribing_number,
  10709. PrescribingNumberUnit: prescribing_number_unit,
  10710. DeliveryWay: delivery_way,
  10711. ExecutionFrequency: execution_frequency,
  10712. AdviceDoctor: advice_doctor,
  10713. Remark: remark,
  10714. RecordDate: RecordDate,
  10715. }
  10716. service.UpdateMobileDoctorAdviceById(id, advice)
  10717. c.ServeSuccessJSON(map[string]interface{}{
  10718. "advice": advice,
  10719. })
  10720. }
  10721. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10722. dataBody := make(map[string]interface{}, 0)
  10723. timeLayout := "2006-01-02"
  10724. loc, _ := time.LoadLocation("Local")
  10725. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10726. if err != nil {
  10727. utils.ErrorLog(err.Error())
  10728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10729. return
  10730. }
  10731. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10732. utils.ErrorLog("start_time")
  10733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10734. return
  10735. }
  10736. startTime2, _ := dataBody["start_time"].(string)
  10737. time_arr := strings.Split(startTime2, " ")
  10738. if len(time_arr) > 0 {
  10739. startTime2 = time_arr[0]
  10740. }
  10741. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10742. utils.ErrorLog("advice_date")
  10743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10744. return
  10745. }
  10746. advice_date, _ := dataBody["advice_date"].(string)
  10747. var advicedateunix int64
  10748. if len(advice_date) > 0 {
  10749. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10750. if err != nil {
  10751. fmt.Println(err)
  10752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10753. return
  10754. }
  10755. advicedateunix = theTime.Unix()
  10756. }
  10757. adviceDate := startTime2
  10758. if len(adviceDate) == 0 {
  10759. utils.ErrorLog("len(adviceDate) == 0")
  10760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10761. return
  10762. }
  10763. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10764. if err != nil {
  10765. utils.ErrorLog(err.Error())
  10766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10767. return
  10768. }
  10769. RecordDate := advicedateunix
  10770. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10771. utils.ErrorLog("start_time")
  10772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10773. return
  10774. }
  10775. startTime, _ := dataBody["start_time"].(string)
  10776. if len(startTime) == 0 {
  10777. utils.ErrorLog("len(start_time) == 0")
  10778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10779. return
  10780. }
  10781. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10782. if err != nil {
  10783. utils.ErrorLog(err.Error())
  10784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10785. return
  10786. }
  10787. StartTime := theTime.Unix()
  10788. patient_id := int64(dataBody["patient_id"].(float64))
  10789. group_no := int64(dataBody["group_no"].(float64))
  10790. org_id := c.GetMobileAdminUserInfo().Org.Id
  10791. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10792. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10793. utils.ErrorLog("advices")
  10794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10795. return
  10796. }
  10797. adviceNames := dataBody["advices"].([]interface{})
  10798. var advices []*models.GroupAdvice
  10799. for _, adviceNameMap := range adviceNames {
  10800. var advice models.GroupAdvice
  10801. adviceNameM := adviceNameMap.(map[string]interface{})
  10802. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10803. utils.ErrorLog("advice_name")
  10804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10805. return
  10806. }
  10807. adviceName, _ := adviceNameM["advice_name"].(string)
  10808. if len(adviceName) == 0 {
  10809. utils.ErrorLog("len(advice_name) == 0")
  10810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10811. return
  10812. }
  10813. advice.AdviceName = adviceName
  10814. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10815. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10816. advice.DrugSpec = drugSpec
  10817. }
  10818. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10819. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10820. advice.AdviceDesc = adviceDesc
  10821. }
  10822. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10823. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10824. advice.DrugSpecUnit = drugSpecUnit
  10825. }
  10826. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10827. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10828. advice.SingleDose = singleDose
  10829. }
  10830. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10831. singleDose := adviceNameM["single_dose"].(float64)
  10832. advice.SingleDose = singleDose
  10833. }
  10834. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10835. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10836. advice.SingleDoseUnit = singleDoseUnit
  10837. }
  10838. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10839. tmp := adviceNameM["single_dose_unit"].(float64)
  10840. singleDoseUnit := service.TypeConversion(tmp)
  10841. advice.SingleDoseUnit = singleDoseUnit
  10842. }
  10843. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10844. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10845. advice.PrescribingNumber = prescribingNumber
  10846. }
  10847. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10848. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10849. advice.PrescribingNumber = prescribingNumber
  10850. }
  10851. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10852. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10853. advice.PrescribingNumberUnit = prescribingNumberUnit
  10854. }
  10855. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10856. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10857. advice.DeliveryWay = deliveryWay
  10858. }
  10859. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10860. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10861. advice.ExecutionFrequency = executionFrequency
  10862. }
  10863. remark, _ := adviceNameM["remark"].(string)
  10864. advice.Remark = remark
  10865. advice.AdviceType = 1
  10866. advice.StartTime = StartTime
  10867. advice.RecordDate = RecordDate
  10868. advice.PatientId = patient_id
  10869. advice.UserOrgId = org_id
  10870. advice.AdviceDoctor = advice_doctor
  10871. advice.StopState = 2
  10872. advices = append(advices, &advice)
  10873. }
  10874. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10875. c.ServeSuccessJSON(map[string]interface{}{
  10876. "advice": newAdvices,
  10877. })
  10878. }
  10879. func (c *DialysisAPIController) StopLongAdvice() {
  10880. stop_time := c.GetString("execution_time")
  10881. id, _ := c.GetInt64("id")
  10882. if len(stop_time) <= 0 {
  10883. utils.ErrorLog("stop_time")
  10884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10885. return
  10886. }
  10887. timeLayout2 := "2006-01-02 15:04:05"
  10888. loc, _ := time.LoadLocation("Local")
  10889. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10890. if errs != nil {
  10891. utils.ErrorLog(errs.Error())
  10892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10893. return
  10894. }
  10895. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10896. c.ServeSuccessJSON(map[string]interface{}{
  10897. "advice": advice,
  10898. })
  10899. }