dialysis_api_controller.go 443KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. if id <= 0 {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. adminUserInfo := c.GetMobileAdminUserInfo()
  1327. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1328. if patient.ID == 0 {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1330. return
  1331. }
  1332. if len(recordDateStr) == 0 {
  1333. recordDateStr = time.Now().Format("2006-01-02")
  1334. }
  1335. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1336. fmt.Println("parseDateErr", parseDateErr)
  1337. if parseDateErr != nil {
  1338. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. //now := time.Now()
  1343. //year, month, day := now.Date()
  1344. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1345. //todayTimeStamp := today_time.Unix()
  1346. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1347. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1348. UserOrgId: adminUserInfo.Org.Id,
  1349. PatientId: id,
  1350. AssessmentDate: recordDate.Unix(),
  1351. Temperature: temperature,
  1352. PulseFrequency: pulse_frequency,
  1353. BreathingRate: breathing_rate,
  1354. SystolicBloodPressure: systolic_blood_pressure,
  1355. DiastolicBloodPressure: diastolic_blood_pressure,
  1356. ActualUltrafiltration: actual_ultrafiltration,
  1357. ActualDisplacement: actual_displacement,
  1358. ActualTreatmentHour: actualtreatHour,
  1359. ActualTreatmentMinute: actualtreatmin,
  1360. WeightAfter: weightAfter,
  1361. AdditionalWeight: additionalWeight,
  1362. WeightLoss: weightReduce,
  1363. Cruor: cruor,
  1364. SymptomAfterDialysis: symptomsAfterDialysi,
  1365. InternalFistula: internalFistula,
  1366. Catheter: catheter,
  1367. Complication: complications,
  1368. DialysisIntakes: dialysateVolume,
  1369. CreatedTime: time.Now().Unix(),
  1370. UpdatedTime: time.Now().Unix(),
  1371. Status: 1,
  1372. Remark: remark,
  1373. BloodAccessPartId: blood_access_part_id,
  1374. BloodAccessPartOperaId: blood_access_part_opera_id,
  1375. DialysisIntakesUnit: dialysis_intakes_unit,
  1376. PuncturePointOozingBlood: puncturePointOozingBlood,
  1377. PuncturePointHaematoma: puncturePointHaematoma,
  1378. InternalFistulaTremorAc: internalFistulaTremorAc,
  1379. PatientGose: patientGose,
  1380. InpatientDepartment: inpatientDepartment,
  1381. ObservationContent: observationContent,
  1382. ObservationContentOther: observationContentOther,
  1383. DialysisProcess: dialysis_process,
  1384. InAdvanceMinute: in_advance_minute,
  1385. InAdvanceReason: in_advance_reason,
  1386. HemostasisMinute: hemostasis_minute,
  1387. HemostasisOpera: hemostasis_opera,
  1388. TremorNoise: tremor_noise,
  1389. DisequilibriumSyndrome: disequilibrium_syndrome,
  1390. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1391. ArterialTube: arterial_tube,
  1392. IntravenousTube: intravenous_tube,
  1393. Dialyzer: dialyzer,
  1394. InAdvanceReasonOther: in_advance_reason_other,
  1395. IsEat: is_eat,
  1396. CvcA: cvc_a,
  1397. CvcV: cvc_v,
  1398. Channel: channels,
  1399. ReturnBlood: return_blood,
  1400. RehydrationVolume: rehydration_volume,
  1401. DialysisDuring: dialysis_during,
  1402. StrokeVolume: stroke_volume,
  1403. BloodFlow: blood_flow,
  1404. SealingFluidDispose: sealing_fluid_dispose,
  1405. SealingFluidSpecial: sealing_fluid_special,
  1406. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1407. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1408. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1409. SettingPressure: setting_pressure,
  1410. DiastolicPressure: diastolic_pressure,
  1411. OtherComplication: other_complication,
  1412. Ktv: ktv,
  1413. Urr: urr,
  1414. Hypopiesia: hypopiesia,
  1415. Hypertenison: hypertenison,
  1416. Lapse: lapse,
  1417. LeaveOfficeMethod: leave_office_method,
  1418. Consciousness: consciousness,
  1419. Fallrisk: fallrisk,
  1420. MachineRun: machine_run,
  1421. AfterUrea: after_urea,
  1422. PipCoagulation: pip_coagulation,
  1423. AccumulatedBloodVolume: accumulated_blood_volume,
  1424. TransfusionVolume: transfusion_volume,
  1425. LastAfterWeight: last_after_weight,
  1426. DisplaceLiquiValue: displace_liqui_value,
  1427. }
  1428. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1429. // 查询信息规挡的设置天数
  1430. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1431. if infor.ID > 0 && infor.WeekDay > 0 {
  1432. var cha_time int64
  1433. timeNowStr := time.Now().Format("2006-01-02")
  1434. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1435. //今日的日期减去设置的日期
  1436. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1437. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1438. if cha_time >= recordDate.Unix() {
  1439. //查询审核是否允许
  1440. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1441. //申请状态不允许的情况 拒绝修改
  1442. if infor.ApplicationStatus != 1 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1449. if assessmentAfter.ID == 0 { //新增
  1450. if appRole.UserType == 2 || appRole.UserType == 1 {
  1451. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1452. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1453. } else {
  1454. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1455. }
  1456. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1457. if assessmentAfterDislysis.UserOrgId != 10340 {
  1458. if assessmentAfterDislysis.WeightAfter == 0 {
  1459. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1460. }
  1461. }
  1462. if adminUserInfo.Org.Id == 10693 {
  1463. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1464. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1465. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1466. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1467. }
  1468. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1471. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1472. }
  1473. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.PulseFrequency == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1481. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1482. }
  1483. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1486. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1487. }
  1488. }
  1489. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1490. //记录日志
  1491. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1492. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1493. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1494. PatientId: assessmentAfterDislysis.PatientId,
  1495. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1496. Status: 1,
  1497. ErrLog: string(byterequest),
  1498. AdminUserId: adminUserInfo.AdminUser.Id,
  1499. Ctime: 0,
  1500. Mtime: 0,
  1501. Source: "手机端保存透后评估",
  1502. }
  1503. service.CreateAfterDialysisLog(afterDialysisLog)
  1504. finish := models.XtDialysisFinish{
  1505. IsFinish: 1,
  1506. UserOrgId: adminUserInfo.Org.Id,
  1507. Status: 1,
  1508. Ctime: time.Now().Unix(),
  1509. Mtime: 0,
  1510. Module: 9,
  1511. RecordDate: recordDate.Unix(),
  1512. Sourse: 1,
  1513. PatientId: id,
  1514. }
  1515. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1516. if dialysisFinish.ID == 0 {
  1517. service.CreateDialysisFinish(finish)
  1518. }
  1519. redis := service.RedisClient()
  1520. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1521. redis.Set(keyTwo, "", time.Second)
  1522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1523. //清空key 值
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1526. redis.Set(keyOne, "", time.Second)
  1527. defer redis.Close()
  1528. if err == nil {
  1529. c.ServeSuccessJSON(map[string]interface{}{
  1530. "assessmentAfterDislysis": assessmentAfterDislysis,
  1531. })
  1532. }
  1533. return
  1534. } else { //修改
  1535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1536. if infor.ID > 0 && infor.WeekDay > 0 {
  1537. var cha_time int64
  1538. timeNowStr := time.Now().Format("2006-01-02")
  1539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1540. //今日的日期减去设置的日期
  1541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1542. if cha_time >= recordDate.Unix() {
  1543. //查询审核是否允许
  1544. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1545. //申请状态不允许的情况 拒绝修改
  1546. if infor.ApplicationStatus != 1 {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. if appRole.UserType == 2 || appRole.UserType == 1 {
  1553. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1554. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1555. } else {
  1556. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1557. if assessmentAfterDislysis.Creater == 0 {
  1558. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1559. }
  1560. }
  1561. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1562. assessmentAfterDislysis.ID = assessmentAfter.ID
  1563. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1564. if assessmentAfterDislysis.UserOrgId != 10340 {
  1565. if assessmentAfterDislysis.WeightAfter == 0 {
  1566. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1567. }
  1568. }
  1569. if adminUserInfo.Org.Id == 10693 {
  1570. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1571. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1572. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1573. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1574. }
  1575. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1578. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1579. }
  1580. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.PulseFrequency == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1588. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1589. }
  1590. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1593. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1594. }
  1595. }
  1596. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1597. //记录日志
  1598. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1599. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1600. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1601. PatientId: assessmentAfterDislysis.PatientId,
  1602. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1603. Status: 1,
  1604. ErrLog: string(byterequest),
  1605. AdminUserId: adminUserInfo.AdminUser.Id,
  1606. Ctime: time.Now().Unix(),
  1607. Mtime: 0,
  1608. Source: "手机端修改保存透后评估",
  1609. }
  1610. service.CreateAfterDialysisLog(afterDialysisLog)
  1611. redis := service.RedisClient()
  1612. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1613. redis.Set(keyTwo, "", time.Second)
  1614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1615. //清空key 值
  1616. redis.Set(key, "", time.Second)
  1617. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1618. redis.Set(keyOne, "", time.Second)
  1619. if err == nil {
  1620. c.ServeSuccessJSON(map[string]interface{}{
  1621. "assessmentAfterDislysis": assessmentAfterDislysis,
  1622. })
  1623. return
  1624. }
  1625. }
  1626. return
  1627. }
  1628. func (c *DialysisAPIController) PostDialysisPrescription() {
  1629. id, _ := c.GetInt64("patient", 0)
  1630. recordDateStr := c.GetString("record_date")
  1631. if id <= 0 {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. adminUserInfo := c.GetMobileAdminUserInfo()
  1636. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1637. if patient.ID == 0 {
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1639. return
  1640. }
  1641. if len(recordDateStr) == 0 {
  1642. recordDateStr = time.Now().Format("2006-01-02")
  1643. }
  1644. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1645. if parseDateErr != nil {
  1646. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. mode_id, _ := c.GetInt64("mode_id", 0)
  1651. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1652. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1653. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1654. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1655. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1656. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1657. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1658. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1659. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1660. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1661. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1662. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1663. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1664. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1665. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1666. kalium, _ := c.GetFloat("kalium", 0)
  1667. sodium, _ := c.GetFloat("sodium", 0)
  1668. calcium, _ := c.GetFloat("calcium", 0)
  1669. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1670. glucose, _ := c.GetFloat("glucose", 0)
  1671. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1672. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1673. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1674. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1675. conductivity, _ := c.GetFloat("conductivity", 0)
  1676. remark := c.GetString("remark")
  1677. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1678. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1679. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1680. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1681. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1682. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1683. special_medicine_other := c.GetString("special_medicine_other")
  1684. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1685. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1686. blood_access, _ := c.GetInt64("blood_access", 0)
  1687. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1688. body_fluid_other := c.GetString("body_fluid_other")
  1689. niprocart, _ := c.GetInt64("niprocart", 0)
  1690. jms, _ := c.GetInt64("jms", 0)
  1691. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1692. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1693. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1694. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1695. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1696. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1697. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1698. injector, _ := c.GetInt64("injector", 0)
  1699. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1700. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1701. safe_package, _ := c.GetInt64("package", 0)
  1702. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1703. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1704. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1705. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1706. blood := c.GetString("blood")
  1707. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1708. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1709. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1710. displace_speed := c.GetString("displace_speed")
  1711. illness, _ := c.GetInt64("illness")
  1712. amylaceum := c.GetString("amylaceum")
  1713. single_time := c.GetString("single_time")
  1714. single_water := c.GetString("single_water")
  1715. replacement_flow := c.GetString("replacement_flow")
  1716. plasma_separator := c.GetString("plasma_separator")
  1717. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1718. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1719. oxygen_flow := c.GetString("oxygen_flow")
  1720. oxygen_time := c.GetString("oxygen_time")
  1721. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1722. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1723. puncture_needle := c.GetString("puncture_needle")
  1724. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1725. epo := c.GetString("epo")
  1726. epo_count, _ := c.GetFloat("epo_count", 0)
  1727. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1728. admin_user_id, _ := c.GetInt64("admin_user_id")
  1729. is_water := c.GetString("is_water")
  1730. var is_war int64
  1731. if is_water == "是" {
  1732. is_war = 1
  1733. }
  1734. if is_water == "否" {
  1735. is_war = 2
  1736. }
  1737. if is_water == "请选择" {
  1738. is_war = 0
  1739. }
  1740. drhy_water := c.GetString("drhy_water")
  1741. dry_water_hour := c.GetString("dry_water_hour")
  1742. water_machine := c.GetString("water_machine")
  1743. add_amount, _ := c.GetFloat("add_amount")
  1744. reduce_amount, _ := c.GetFloat("reduce_amount")
  1745. dialysis_remark := c.GetString("dialysis_remark")
  1746. prescribing_number, _ := c.GetFloat("prescribing_number")
  1747. prescription_sodium := c.GetString("prescription_sodium")
  1748. start_sodium := c.GetString("start_sodium")
  1749. sodium_curve := c.GetString("sodium_curve")
  1750. treatment_remark := c.GetString("treatment_remark")
  1751. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1752. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1753. prescription_water, _ := c.GetFloat("prescription_water")
  1754. dialysis_strainer := c.GetString("dialysis_strainer")
  1755. chaptalization := c.GetString("chaptalization")
  1756. washing_time := c.GetString("washing_time")
  1757. warsh_count := c.GetString("warsh_count")
  1758. blood_access_part_id := c.GetString("blood_access_part_id")
  1759. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1760. dialyzate := c.GetString("dialyzate")
  1761. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1762. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1763. //
  1764. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1765. // if appRole.UserType == 3 {
  1766. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1767. // if getPermissionErr != nil {
  1768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1769. // return
  1770. // } else if headNursePermission == nil {
  1771. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1772. // return
  1773. // }
  1774. // }
  1775. //}
  1776. // 查询信息规挡的设置天数
  1777. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1778. if infor.ID > 0 && infor.WeekDay > 0 {
  1779. var cha_time int64
  1780. timeNowStr := time.Now().Format("2006-01-02")
  1781. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1782. //今日的日期减去设置的日期
  1783. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1784. if cha_time >= recordDate.Unix() {
  1785. //查询审核是否允许
  1786. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1787. //申请状态不允许的情况 拒绝修改
  1788. if infor.ApplicationStatus != 1 {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1790. return
  1791. }
  1792. }
  1793. }
  1794. if mode_id > 0 {
  1795. var str string
  1796. //查找该机构用的是什么透析器
  1797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1798. if filedConfig.ID > 0 {
  1799. str = dialyzerPerfusionApparatus
  1800. } else {
  1801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1802. }
  1803. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1804. }
  1805. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1806. var dialysis_dialyszers_id int64
  1807. var dialysis_strainer_id int64
  1808. var dialysis_irrigation_id int64
  1809. if len(goodList) > 0 {
  1810. for _, item := range goodList {
  1811. if item.SpecificationName == dialysis_dialyszers {
  1812. dialysis_dialyszers_id = item.ID
  1813. }
  1814. if item.SpecificationName == dialysis_irrigation {
  1815. dialysis_irrigation_id = item.ID
  1816. }
  1817. if item.SpecificationName == dialysis_strainer {
  1818. dialysis_strainer_id = item.ID
  1819. }
  1820. }
  1821. }
  1822. //TODO 需要根据角色去判断
  1823. prescription := models.DialysisPrescription{
  1824. UserOrgId: adminUserInfo.Org.Id,
  1825. PatientId: id,
  1826. RecordDate: recordDate.Unix(),
  1827. ModeId: mode_id,
  1828. DialysisDuration: dialysis_duration,
  1829. Dialyzer: dialyzer,
  1830. PerfusionApparatus: perfusion_apparatus,
  1831. BloodFlowVolume: blood_flow_volume,
  1832. DewaterAmount: dewater_amount,
  1833. DisplaceLiqui: displace_liqui,
  1834. ReplacementWay: replacement_way,
  1835. Anticoagulant: anticoagulant,
  1836. AnticoagulantShouji: anticoagulant_shouji,
  1837. AnticoagulantWeichi: anticoagulant_weichi,
  1838. AnticoagulantZongliang: anticoagulant_zongliang,
  1839. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1840. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1841. Kalium: kalium,
  1842. Sodium: sodium,
  1843. Calcium: calcium,
  1844. Bicarbonate: bicarbonate,
  1845. Glucose: glucose,
  1846. // DryWeight: dry_weight,
  1847. DialysateFlow: dialysate_flow,
  1848. DialysateTemperature: dialysate_temperature,
  1849. // PrescriptionDoctor: prescription_doctor,
  1850. ReplacementTotal: replacement_total,
  1851. Conductivity: conductivity,
  1852. Remark: remark,
  1853. Status: 1,
  1854. CreatedTime: time.Now().Unix(),
  1855. UpdatedTime: time.Now().Unix(),
  1856. DialysisDurationMinute: dialysisDurationMinute,
  1857. DialysisDurationHour: dialysisDurationHour,
  1858. TargetUltrafiltration: targetUltrafiltration,
  1859. DialysateFormulation: dialysateFormulation,
  1860. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1861. BodyFluid: body_fluid,
  1862. SpecialMedicine: special_medicine,
  1863. SpecialMedicineOther: special_medicine_other,
  1864. DisplaceLiquiPart: displace_liqui_part,
  1865. DisplaceLiquiValue: displace_liqui_value,
  1866. BloodAccess: blood_access,
  1867. Ultrafiltration: ultrafiltration,
  1868. BodyFluidOther: body_fluid_other,
  1869. Niprocart: niprocart,
  1870. Jms: jms,
  1871. FistulaNeedleSet: fistula_needle_set,
  1872. FistulaNeedleSet16: fistula_needle_set_16,
  1873. Hemoperfusion: hemoperfusion,
  1874. DialyserSterilised: dialyser_sterilised,
  1875. Filtryzer: filtryzer,
  1876. Dialyzers: dialyzers,
  1877. Injector: injector,
  1878. Bloodlines: bloodlines,
  1879. TubingHemodialysis: tubing_hemodialysis,
  1880. Package: safe_package,
  1881. ALiquid: a_liquid,
  1882. TargetKtv: target_ktv,
  1883. PreImpulse: pre_impulse,
  1884. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1885. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1886. Blood: blood,
  1887. DialysisDialyszers: dialysis_dialyszers,
  1888. DialysisIrrigation: dialysis_irrigation,
  1889. AntioxidantCommodityName: antioxidant_commodity_name,
  1890. DisplaceSpeed: displace_speed,
  1891. Illness: illness,
  1892. Amylaceum: amylaceum,
  1893. SingleTime: single_time,
  1894. SingleWater: single_water,
  1895. ReplacementFlow: replacement_flow,
  1896. PlasmaSeparator: plasma_separator,
  1897. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1898. OxygenUptake: oxygen_uptake,
  1899. OxygenFlow: oxygen_flow,
  1900. OxygenTime: oxygen_time,
  1901. HemodialysisPipelines: hemodialysis_pipelines,
  1902. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1903. PunctureNeedle: puncture_needle,
  1904. PunctureNeedleCount: puncture_needle_count,
  1905. Epo: epo,
  1906. EpoCount: epo_count,
  1907. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1908. AdminUserId: admin_user_id,
  1909. IsWater: is_war,
  1910. DrhyWater: drhy_water,
  1911. DryWaterHour: dry_water_hour,
  1912. WaterMachine: water_machine,
  1913. AddAmount: add_amount,
  1914. ReduceAmount: reduce_amount,
  1915. DialysisRemark: dialysis_remark,
  1916. PrescribingNumber: prescribing_number,
  1917. StartSodium: start_sodium,
  1918. SodiumCurve: sodium_curve,
  1919. TreatmentRemark: treatment_remark,
  1920. PrescriptionSodium: prescription_sodium,
  1921. DialysisFluidFlow: dialysis_fluid_flow,
  1922. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1923. PrescriptionWater: prescription_water,
  1924. DialysisStrainer: dialysis_strainer,
  1925. Chaptalization: chaptalization,
  1926. WashingTime: washing_time,
  1927. WarshCount: warsh_count,
  1928. BloodAccessPartId: blood_access_part_id,
  1929. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1930. Dialyzate: dialyzate,
  1931. DialysisDialyszersId: dialysis_dialyszers_id,
  1932. DialysisIrrigationId: dialysis_irrigation_id,
  1933. DialysisStrainerId: dialysis_strainer_id,
  1934. }
  1935. if adminUserInfo.Org.Id == 10721 {
  1936. if prescription.ModeId == 2 {
  1937. if prescription.ReplacementTotal == 0 {
  1938. prescription.ReplacementTotal = 15
  1939. }
  1940. }
  1941. }
  1942. //查询最近透析准备表里是否存在 透析器 灌流器
  1943. //
  1944. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1945. //
  1946. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1947. //
  1948. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1949. //if len(mation)>0{
  1950. // for _, item := range splitStr {
  1951. // for _,it := range mation{
  1952. // if(item == it.SpecificationName){
  1953. //
  1954. // //查询最近一次的透析器
  1955. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1956. //
  1957. // if errcode == gorm.ErrRecordNotFound{
  1958. // //插入数据
  1959. // prepare := models.DialysisBeforePrepare{
  1960. // UserOrgId: adminUserInfo.Org.Id,
  1961. // PatientId: id,
  1962. // RecordDate: recordDate.Unix(),
  1963. // GoodTypeId: it.GoodTypeId,
  1964. // GoodId: it.ID,
  1965. // Count: 1,
  1966. // Ctime: time.Now().Unix(),
  1967. // Creater: adminUserInfo.AdminUser.Id,
  1968. // Status:1,
  1969. //
  1970. // }
  1971. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1972. // fmt.Println("",errcode)
  1973. // }
  1974. // }
  1975. // }
  1976. //
  1977. // }
  1978. //
  1979. // for _, item := range splitIrrigation {
  1980. // for _,it := range mation{
  1981. // if(item == it.SpecificationName){
  1982. // //查询最近一次的透析器
  1983. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1984. // if errcode == gorm.ErrRecordNotFound{
  1985. // //插入数据
  1986. // prepare := models.DialysisBeforePrepare{
  1987. // UserOrgId: adminUserInfo.Org.Id,
  1988. // PatientId: id,
  1989. // RecordDate: recordDate.Unix(),
  1990. // GoodTypeId: it.GoodTypeId,
  1991. // GoodId: it.ID,
  1992. // Count: 1,
  1993. // Ctime: time.Now().Unix(),
  1994. // Creater: adminUserInfo.AdminUser.Id,
  1995. // Status:1,
  1996. //
  1997. // }
  1998. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1999. // fmt.Println(errcode)
  2000. // }
  2001. // }
  2002. // }
  2003. // }
  2004. //}
  2005. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2006. if dialysisPrescription.ID == 0 { //新增
  2007. if appRole.UserType == 2 || appRole.UserType == 1 {
  2008. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2009. }
  2010. prescription.Creater = adminUserInfo.AdminUser.Id
  2011. //针对河间咸得
  2012. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2013. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2014. prescription.DisplaceLiquiPart = 0
  2015. prescription.DisplaceLiquiValue = 0
  2016. }
  2017. }
  2018. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2019. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2020. }
  2021. err := service.AddSigleRecord(&prescription)
  2022. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2023. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2024. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2025. if len(monitorList) > 0 {
  2026. var ultrafiltration_rate float64
  2027. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2028. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2029. var replacement_rate float64
  2030. //乘10 除10是为了保留一位小数
  2031. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2032. var firstOpeateTime = monitorList[0].OperateTime
  2033. for _, item := range monitorList {
  2034. //超滤率
  2035. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2036. //置换率
  2037. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2038. //超滤量
  2039. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2040. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2041. //置换量
  2042. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2043. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2044. }
  2045. }
  2046. }
  2047. //记录日志
  2048. byterequest, _ := json.Marshal(prescription)
  2049. prescriptionLog := models.XtDialysisPrescriptionLog{
  2050. UserOrgId: prescription.UserOrgId,
  2051. Ctime: time.Now().Unix(),
  2052. Mtime: 0,
  2053. ErrLog: string(byterequest),
  2054. AdminUserId: adminUserInfo.AdminUser.Id,
  2055. RecordDate: prescription.RecordDate,
  2056. PatientId: prescription.PatientId,
  2057. Source: "手机端新增保存处方",
  2058. Status: 1,
  2059. }
  2060. service.CreatePrescriptionLog(prescriptionLog)
  2061. finish := models.XtDialysisFinish{
  2062. IsFinish: 1,
  2063. UserOrgId: adminUserInfo.Org.Id,
  2064. Status: 1,
  2065. Ctime: time.Now().Unix(),
  2066. Mtime: 0,
  2067. Module: 1,
  2068. RecordDate: recordDate.Unix(),
  2069. Sourse: 1,
  2070. PatientId: id,
  2071. }
  2072. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2073. if dialysisFinish.ID == 0 {
  2074. service.CreateDialysisFinish(finish)
  2075. }
  2076. //长沙南雅医院,自动生成抗凝剂的临时处方
  2077. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2078. if prescribing_number == 0 {
  2079. prescribing_number = 1
  2080. }
  2081. if prescribing_number == 0 && id == 14682 {
  2082. prescribing_number = 2
  2083. }
  2084. if prescribing_number == 0 && id == 18560 {
  2085. prescribing_number = 2
  2086. }
  2087. advice := models.DoctorAdvice{
  2088. UserOrgId: adminUserInfo.Org.Id,
  2089. PatientId: id,
  2090. GroupNo: 0,
  2091. AdviceType: 2,
  2092. RecordDate: recordDate.Unix(),
  2093. AdviceDate: recordDate.Unix(),
  2094. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2095. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2096. AdviceDesc: "",
  2097. ReminderDate: 0,
  2098. SingleDose: anticoagulant_zongliang,
  2099. SingleDoseUnit: "iu",
  2100. DrugSpec: 0,
  2101. DrugSpecUnit: "",
  2102. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2103. PrescribingNumberUnit: "支",
  2104. DeliveryWay: "静脉注射",
  2105. ExecutionFrequency: "上机前",
  2106. AdviceDoctor: 0,
  2107. Status: 1,
  2108. CreatedTime: time.Now().Unix(),
  2109. UpdatedTime: time.Now().Unix(),
  2110. IsPrescription: 1,
  2111. ExecutionState: 2,
  2112. StopState: 2,
  2113. IsSettle: 2,
  2114. }
  2115. // 查询排班信息
  2116. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2117. if schedulePatient.ID > 0 {
  2118. if schedulePatient.ScheduleType == 1 {
  2119. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2120. }
  2121. if schedulePatient.ScheduleType == 2 {
  2122. advice.StartTime = recordDate.Unix() + 9*60*60
  2123. }
  2124. }
  2125. // 抗凝剂名称
  2126. switch anticoagulant {
  2127. case 1:
  2128. advice.AdviceName = "无肝素"
  2129. break
  2130. case 2:
  2131. advice.AdviceName = "普通肝素"
  2132. break
  2133. case 3:
  2134. advice.AdviceName = "低分子肝素"
  2135. break
  2136. case 4:
  2137. advice.AdviceName = "阿加曲班"
  2138. break
  2139. case 5:
  2140. advice.AdviceName = "枸橼酸钠"
  2141. break
  2142. case 6:
  2143. advice.AdviceName = "低分子肝素钙"
  2144. break
  2145. case 7:
  2146. advice.AdviceName = "低分子肝素钠"
  2147. break
  2148. case 8:
  2149. advice.AdviceName = "依诺肝素"
  2150. break
  2151. case 9:
  2152. advice.AdviceName = "达肝素"
  2153. break
  2154. case 10:
  2155. advice.AdviceName = "体外抗凝"
  2156. break
  2157. case 11:
  2158. advice.AdviceName = "那曲肝素"
  2159. break
  2160. case 12:
  2161. advice.AdviceName = "无抗凝剂"
  2162. break
  2163. }
  2164. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2165. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2166. advice.AdviceDoctor = appRole.AdminUserId
  2167. }
  2168. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2169. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2171. advice.AdviceName = "低分子肝素钠注射液"
  2172. // 修改患者临时医嘱里的抗凝剂医嘱
  2173. advice.ID = advicePrescription.ID
  2174. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2175. } else {
  2176. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2177. advice.AdviceName = "低分子肝素钠注射液"
  2178. // 新增患者临时医嘱里的抗凝剂医嘱
  2179. service.CreateDoctorAdvice(&advice)
  2180. }
  2181. }
  2182. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2183. redis := service.RedisClient()
  2184. defer redis.Close()
  2185. //清空key 值
  2186. redis.Set(key, "", time.Second)
  2187. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2188. redis.Set(keyOne, "", time.Second)
  2189. }
  2190. //获取key,清空redis
  2191. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2192. redis := service.RedisClient()
  2193. //清空key 值
  2194. redis.Set(key, "", time.Second)
  2195. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2196. //清空key 值
  2197. redis.Set(keyOne, "", time.Second)
  2198. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2199. //清空key 值
  2200. redis.Set(keyTwo, "", time.Second)
  2201. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2202. redis.Set(keySix, "", time.Second)
  2203. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2204. redis.Set(keySeven, "", time.Second)
  2205. if err == nil {
  2206. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2207. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2208. //清空key 值
  2209. redis.Set(keyThree, "", time.Second)
  2210. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2211. //清空key 值
  2212. redis.Set(keyFour, "", time.Second)
  2213. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2214. redis.Set(keyFive, "", time.Second)
  2215. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2216. redis.Set(keySix, "", time.Second)
  2217. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2218. redis.Set(keySeven, "", time.Second)
  2219. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2220. //清空key 值
  2221. redis.Set(keyOne, "", time.Second)
  2222. if updateErr != nil {
  2223. utils.ErrorLog("%v", updateErr)
  2224. }
  2225. defer redis.Close()
  2226. c.ServeSuccessJSON(map[string]interface{}{
  2227. "prescription": prescription,
  2228. })
  2229. }
  2230. } else { //修改
  2231. //if mode_id > 0 {
  2232. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2233. //}
  2234. //if template.TemplateId == 1 {
  2235. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2236. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2237. // if getPermissionErr != nil {
  2238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2239. // return
  2240. // } else if headNursePermission == nil {
  2241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2242. // return
  2243. // }
  2244. // }
  2245. //}
  2246. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2247. prescription.Modifier = adminUserInfo.AdminUser.Id
  2248. if appRole.UserType == 2 || appRole.UserType == 1 {
  2249. prescription_doctor := adminUserInfo.AdminUser.Id
  2250. prescription.PrescriptionDoctor = prescription_doctor
  2251. } else {
  2252. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2253. }
  2254. if dialysisPrescription.Creater == 0 { //体重称
  2255. prescription.Creater = adminUserInfo.AdminUser.Id
  2256. } else {
  2257. prescription.Creater = dialysisPrescription.Creater
  2258. if adminUserInfo.Org.Id == 9882 {
  2259. if appRole.UserType == 2 || appRole.UserType == 1 {
  2260. prescription_doctor := adminUserInfo.AdminUser.Id
  2261. prescription.PrescriptionDoctor = prescription_doctor
  2262. prescription.Creater = prescription_doctor
  2263. }
  2264. }
  2265. }
  2266. prescription.ID = dialysisPrescription.ID
  2267. if adminUserInfo.Org.Id == 10721 {
  2268. if prescription.ModeId == 2 {
  2269. if prescription.ReplacementTotal == 0 {
  2270. prescription.ReplacementTotal = 15
  2271. }
  2272. }
  2273. }
  2274. service.UpDateDialysisPrescription(&prescription)
  2275. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2276. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2277. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2278. if len(monitorList) > 0 {
  2279. var ultrafiltration_rate float64
  2280. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2281. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2282. var replacement_rate float64
  2283. //乘10 除10是为了保留一位小数
  2284. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2285. var firstOpeateTime = monitorList[0].OperateTime
  2286. for _, item := range monitorList {
  2287. //超滤率
  2288. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2289. //置换率
  2290. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2291. //超滤量
  2292. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2293. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2294. //置换量
  2295. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2296. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2297. }
  2298. }
  2299. }
  2300. //记录日志
  2301. byterequest, _ := json.Marshal(prescription)
  2302. prescriptionLog := models.XtDialysisPrescriptionLog{
  2303. UserOrgId: prescription.UserOrgId,
  2304. Ctime: time.Now().Unix(),
  2305. Mtime: 0,
  2306. ErrLog: string(byterequest),
  2307. AdminUserId: adminUserInfo.AdminUser.Id,
  2308. RecordDate: prescription.RecordDate,
  2309. PatientId: prescription.PatientId,
  2310. Source: "手机端修改处方",
  2311. Status: 1,
  2312. }
  2313. service.CreatePrescriptionLog(prescriptionLog)
  2314. finish := models.XtDialysisFinish{
  2315. IsFinish: 1,
  2316. UserOrgId: adminUserInfo.Org.Id,
  2317. Status: 1,
  2318. Ctime: time.Now().Unix(),
  2319. Mtime: 0,
  2320. Module: 1,
  2321. RecordDate: recordDate.Unix(),
  2322. Sourse: 1,
  2323. PatientId: id,
  2324. }
  2325. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2326. if dialysisFinish.ID == 0 {
  2327. service.CreateDialysisFinish(finish)
  2328. }
  2329. //修改处方
  2330. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2331. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2332. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2333. if advicePrescription.ID > 0 {
  2334. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2336. redis := service.RedisClient()
  2337. defer redis.Close()
  2338. //清空key 值
  2339. redis.Set(key, "", time.Second)
  2340. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2341. redis.Set(keyOne, "", time.Second)
  2342. }
  2343. }
  2344. //获取key,清空redis
  2345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2346. redis := service.RedisClient()
  2347. //清空key 值
  2348. redis.Set(key, "", time.Second)
  2349. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2350. //清空key 值
  2351. redis.Set(keyOne, "", time.Second)
  2352. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2353. redis.Set(keySix, "", time.Second)
  2354. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2355. redis.Set(keySeven, "", time.Second)
  2356. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2357. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2358. //清空key 值
  2359. redis.Set(keyTwoOne, "", time.Second)
  2360. defer redis.Close()
  2361. if updateErr != nil {
  2362. utils.ErrorLog("%v", updateErr)
  2363. }
  2364. c.ServeSuccessJSON(map[string]interface{}{
  2365. "prescription": prescription,
  2366. })
  2367. }
  2368. }
  2369. func (c *DialysisAPIController) Finish() {
  2370. id, _ := c.GetInt64("patient", 0)
  2371. recordDateStr := c.GetString("record_date")
  2372. nurseID, _ := c.GetInt64("nurse")
  2373. end_time := c.GetString("end_time")
  2374. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2375. internal_fistula := c.GetString("blood_access_internal_fistula")
  2376. catheter := c.GetString("catheter")
  2377. cruor := c.GetString("cruor")
  2378. mission := c.GetString("mission")
  2379. condenser := c.GetString("condenser")
  2380. if id <= 0 || nurseID <= 0 {
  2381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2382. return
  2383. }
  2384. adminUserInfo := c.GetMobileAdminUserInfo()
  2385. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2386. if patient.ID == 0 {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2388. return
  2389. }
  2390. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2391. if getNurseErr != nil {
  2392. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2394. return
  2395. } else if nurse == nil {
  2396. c.ErrorLog("护士不存在")
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2398. return
  2399. }
  2400. if len(recordDateStr) == 0 {
  2401. recordDateStr = time.Now().Format("2006-01-02")
  2402. }
  2403. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2404. if parseDateErr != nil {
  2405. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2410. if parseEndDateErr != nil {
  2411. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. // 查询信息规挡的设置天数
  2416. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2417. if infor.ID > 0 && infor.WeekDay > 0 {
  2418. var cha_time int64
  2419. timeNowStr := time.Now().Format("2006-01-02")
  2420. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2421. //今日的日期减去设置的日期
  2422. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2423. if cha_time >= recordDate.Unix() {
  2424. //查询审核是否允许
  2425. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2426. //申请状态不允许的情况 拒绝修改
  2427. if infor.ApplicationStatus != 1 {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2429. return
  2430. }
  2431. }
  2432. }
  2433. //now := time.Now()
  2434. //year, month, day := now.Date()
  2435. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2436. //todayTimeStamp := today_time.Unix()
  2437. // 获取当天的第一条透析纪录
  2438. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2439. if getMonitorRecordsErr != nil {
  2440. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2442. return
  2443. }
  2444. // 获取当前的最后一条透析纪录
  2445. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2446. if getMonitorRecordsErr != nil {
  2447. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2449. return
  2450. }
  2451. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2452. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2453. if getAADErr != nil {
  2454. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2459. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2460. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2461. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2462. if assessmentAfterDislysis != nil {
  2463. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2464. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2465. } else {
  2466. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2467. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2468. tempassessmentAfterDislysis.Status = 1
  2469. tempassessmentAfterDislysis.PatientId = id
  2470. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2471. }
  2472. //长沙南雅
  2473. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2474. //获取最后一条透析处方数据
  2475. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2476. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2478. }
  2479. if dialysisOrder.Stage == 1 {
  2480. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2481. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2482. fmt.Println(value)
  2483. a, b := math.Modf(value)
  2484. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2485. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2486. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2487. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2488. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2489. }
  2490. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2491. //var num1 int64
  2492. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2493. //fmt.Println(num1)
  2494. //sub := float64(num1 / 3600)
  2495. //fmt.Println(sub)
  2496. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2497. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2498. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2499. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2500. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2501. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2502. if adminUserInfo.Org.Id != 10375 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2505. }
  2506. if adminUserInfo.Org.Id != 10445 {
  2507. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2508. }
  2509. //北方营口医院
  2510. if adminUserInfo.Org.Id == 10445 {
  2511. //获取最后一条透析处方数据
  2512. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2513. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2514. } else {
  2515. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2516. }
  2517. //新化博翔
  2518. if adminUserInfo.Org.Id == 10447 {
  2519. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2520. }
  2521. //阳春
  2522. if adminUserInfo.Org.Id == 10485 {
  2523. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2524. }
  2525. if adminUserInfo.Org.Id == 10551 {
  2526. //获取最后一条透析处方数据
  2527. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2528. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2529. }
  2530. if adminUserInfo.Org.Id == 10580 {
  2531. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2532. }
  2533. if adminUserInfo.Org.Id == 10612 {
  2534. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2535. }
  2536. //孝康
  2537. if adminUserInfo.Org.Id == 10693 {
  2538. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2539. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2540. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2541. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2542. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2543. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2544. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2545. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2546. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2547. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2548. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2549. }
  2550. if adminUserInfo.Org.Id == 10721 {
  2551. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2552. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2553. }
  2554. if adminUserInfo.Org.Id == 10697 {
  2555. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2556. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2557. lastWeightAfter.LastAfterWeight = floatAfeter
  2558. }
  2559. }
  2560. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 {
  2561. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. if evaluation.SystolicBloodPressure == 0 {
  2563. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2564. if adminUserInfo.Org.Id == 10693 {
  2565. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2566. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2567. }
  2568. pre := models.PredialysisEvaluation{
  2569. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2570. }
  2571. fmt.Println("prew", pre)
  2572. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2573. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2574. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2575. redis := service.RedisClient()
  2576. redis.Set(key, "", time.Second)
  2577. redis.Set(keyOne, "", time.Second)
  2578. defer redis.Close()
  2579. fmt.Println(getNurseErr)
  2580. }
  2581. if evaluation.DiastolicBloodPressure == 0 {
  2582. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2583. if adminUserInfo.Org.Id == 10693 {
  2584. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2585. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2586. }
  2587. pres := models.PredialysisEvaluation{
  2588. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2589. }
  2590. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2592. redis := service.RedisClient()
  2593. redis.Set(key, "", time.Second)
  2594. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2595. redis.Set(keyOne, "", time.Second)
  2596. defer redis.Close()
  2597. fmt.Println(getNurseErr)
  2598. }
  2599. if evaluation.PulseFrequency == 0 {
  2600. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2601. if adminUserInfo.Org.Id == 10693 {
  2602. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2603. evaluation.PulseFrequency = pulseFrequency
  2604. }
  2605. press := models.PredialysisEvaluation{
  2606. PulseFrequency: evaluation.PulseFrequency,
  2607. }
  2608. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2609. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2610. redis := service.RedisClient()
  2611. redis.Set(key, "", time.Second)
  2612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2613. redis.Set(keyOne, "", time.Second)
  2614. defer redis.Close()
  2615. fmt.Println(getNurseErr)
  2616. }
  2617. if evaluation.Temperature == 0 {
  2618. evaluation.Temperature = fmonitorRecords.Temperature
  2619. press := models.PredialysisEvaluation{
  2620. Temperature: evaluation.Temperature,
  2621. }
  2622. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2624. redis := service.RedisClient()
  2625. redis.Set(key, "", time.Second)
  2626. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2627. redis.Set(keyOne, "", time.Second)
  2628. defer redis.Close()
  2629. fmt.Println(getNurseErr)
  2630. }
  2631. }
  2632. if adminUserInfo.Org.Id == 9583 {
  2633. //获取透析处方的最后一条数据
  2634. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2635. if diaerr != nil {
  2636. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2638. return
  2639. }
  2640. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2641. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2642. }
  2643. }
  2644. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2645. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2646. }
  2647. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2648. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2649. }
  2650. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2651. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2652. }
  2653. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2654. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2655. }
  2656. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2657. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2658. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2659. }
  2660. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2661. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2662. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2663. }
  2664. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2665. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2666. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2667. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2668. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2669. }
  2670. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2671. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2672. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2673. }
  2674. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2675. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2676. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2677. }
  2678. if lastAssessmentAfterDislysis != nil {
  2679. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2680. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2681. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2682. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2683. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2684. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2685. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2686. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2687. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2688. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2689. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2690. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2691. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2692. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2693. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2694. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2695. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2696. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2697. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2698. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2699. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2700. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2701. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2702. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2703. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2704. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2705. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2706. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2707. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2708. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2709. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2710. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2711. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2712. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2713. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2714. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2715. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2716. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2717. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2718. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2719. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2720. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2721. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2722. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2723. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2724. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2725. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2726. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2727. if tempassessmentAfterDislysis.PatientId == 18695 {
  2728. tempassessmentAfterDislysis.ActualDisplacement = 0
  2729. }
  2730. if adminUserInfo.Org.Id != 10375 {
  2731. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2732. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2733. }
  2734. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2735. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2736. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2737. }
  2738. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2739. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2740. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2741. }
  2742. }
  2743. finish := models.XtDialysisFinish{
  2744. IsFinish: 1,
  2745. UserOrgId: adminUserInfo.Org.Id,
  2746. Status: 1,
  2747. Ctime: time.Now().Unix(),
  2748. Mtime: 0,
  2749. Module: 9,
  2750. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2751. Sourse: 1,
  2752. PatientId: tempassessmentAfterDislysis.PatientId,
  2753. }
  2754. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2755. if dialysisFinish.ID == 0 {
  2756. service.CreateDialysisFinish(finish)
  2757. }
  2758. //孝康
  2759. if adminUserInfo.Org.Id == 10693 {
  2760. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2761. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2762. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2763. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2764. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2765. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2766. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2767. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2768. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2769. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2770. }
  2771. if adminUserInfo.Org.Id == 10697 {
  2772. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2773. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2774. lastWeightAfter.LastAfterWeight = floatAfeter
  2775. }
  2776. if adminUserInfo.Org.Id == 10721 {
  2777. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. }
  2780. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2781. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2782. redis := service.RedisClient()
  2783. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2784. redis.Set(keyOne, "", time.Second)
  2785. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2786. redis.Set(keyTwo, "", time.Second)
  2787. defer redis.Close()
  2788. //清空key 值
  2789. redis.Set(key, "", time.Second)
  2790. if err != nil {
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2792. return
  2793. }
  2794. if dialysisOrder == nil {
  2795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2796. return
  2797. }
  2798. if dialysisOrder.Stage == 2 {
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2800. return
  2801. }
  2802. if dialysisOrder.Stage == 1 {
  2803. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2804. finish := models.XtDialysisFinish{
  2805. IsFinish: 1,
  2806. UserOrgId: adminUserInfo.Org.Id,
  2807. Status: 1,
  2808. Ctime: time.Now().Unix(),
  2809. Mtime: 0,
  2810. Module: 8,
  2811. RecordDate: recordDate.Unix(),
  2812. Sourse: 1,
  2813. PatientId: id,
  2814. }
  2815. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2816. if dialysisFinish.ID == 0 {
  2817. service.CreateDialysisFinish(finish)
  2818. }
  2819. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2820. redis := service.RedisClient()
  2821. defer redis.Close()
  2822. //清空key 值
  2823. redis.Set(key, "", time.Second)
  2824. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2825. redis.Set(keyOne, "", time.Second)
  2826. //结束时候透析次数加1
  2827. service.UpdateSolutionByPatientId(id)
  2828. //下机完自动消毒,针对长沙南雅
  2829. if dialysisOrder.Stage == 1 {
  2830. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2831. //根据床位号获取设备型号
  2832. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2833. //查询使用消毒最后一条消毒记录
  2834. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2835. fmt.Println("err", err)
  2836. if err == gorm.ErrRecordNotFound {
  2837. //查找排班
  2838. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2839. //查询改设备是否有消毒计划
  2840. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2841. //根据床位号获取设备id
  2842. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2843. //查询病人信息
  2844. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2845. var con = ""
  2846. if patients.IsInfectious == 0 {
  2847. con = ""
  2848. }
  2849. if patients.IsInfectious == 1 {
  2850. con = "无"
  2851. }
  2852. if patients.IsInfectious == 2 {
  2853. con = "有"
  2854. }
  2855. if errcode == nil {
  2856. var end_time int64
  2857. end_time = endDate.Unix() + plan.DisinfecTime*60
  2858. //新增消毒
  2859. information := models.DeviceInformation{
  2860. Date: dialysisOrder.DialysisDate,
  2861. Zone: dialysisOrder.ZoneId,
  2862. Class: dialysisOrder.SchedualType,
  2863. BedNumber: dialysisOrder.BedID,
  2864. PatientId: dialysisOrder.PatientId,
  2865. DialysisMode: scheduleByPatient.ModeId,
  2866. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2867. Disinfection: 1,
  2868. DialysisConcentration: 1,
  2869. DisinfectionStatus: 1,
  2870. Move: 1,
  2871. UserOrgId: dialysisOrder.UserOrgId,
  2872. DisinfectType: plan.Way,
  2873. DisinfectantType: plan.MachineDisinfectant,
  2874. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2875. Disinfectant: plan.Disinfectant,
  2876. Ctime: time.Now().Unix(),
  2877. Status: 1,
  2878. SignName: nurseID,
  2879. EquimentId: addmacher.ID,
  2880. DisinfectionResidue: 2,
  2881. Bed: addmacher.BedNumber,
  2882. StartTime: dialysisOrder.StartTime,
  2883. EndTime: dialysisOrder.EndTime,
  2884. Contagion: con,
  2885. WeightLoss: 0,
  2886. Hyperfiltratio: 0,
  2887. DialysisHour: "",
  2888. MachineRun: 1,
  2889. DisinfecStartime: endDate.Unix(),
  2890. DisinfecEndtime: end_time,
  2891. }
  2892. err := service.CreateInformationTwo(&information)
  2893. fmt.Println("报错", err)
  2894. }
  2895. }
  2896. }
  2897. }
  2898. dialysisOrder.Stage = 2
  2899. dialysisOrder.FinishNurse = nurseID
  2900. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2901. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2902. dialysisOrder.EndTime = endDate.Unix()
  2903. // 长沙南雅需求
  2904. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2905. //获取最后1条监测的数据
  2906. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2907. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2908. var accumulatedBloodVolume float64
  2909. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2910. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2911. fmt.Println(err)
  2912. // 查询未执行的医嘱
  2913. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2914. for _, item := range doctorAdvice {
  2915. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2917. redis := service.RedisClient()
  2918. //清空key 值
  2919. redis.Set(key, "", time.Second)
  2920. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2921. redis.Set(keyTwo, "", time.Second)
  2922. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2923. redis.Set(keyThree, "", time.Second)
  2924. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2925. theTime := toTime.Format("2006-01-02")
  2926. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2927. redis.Set(keyFour, "", time.Second)
  2928. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2929. redis.Set(keyFive, "", time.Second)
  2930. defer redis.Close()
  2931. }
  2932. }
  2933. go func() {
  2934. ssoDomain := beego.AppConfig.String("call_domain")
  2935. api := ssoDomain + "/index/downpatient"
  2936. values := make(url.Values)
  2937. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2938. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2939. values.Set("patient_id", strconv.FormatInt(id, 10))
  2940. http.PostForm(api, values)
  2941. }()
  2942. if err == nil {
  2943. c.ServeSuccessJSON(map[string]interface{}{
  2944. "dialysisOrder": dialysisOrder,
  2945. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2946. })
  2947. } else {
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2949. }
  2950. }
  2951. }
  2952. func (c *DialysisAPIController) GetAllZone() {
  2953. adminUserInfo := c.GetMobileAdminUserInfo()
  2954. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2955. if err == nil {
  2956. c.ServeSuccessJSON(map[string]interface{}{
  2957. "zone": zone,
  2958. })
  2959. }
  2960. }
  2961. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2962. adminUserInfo := c.GetMobileAdminUserInfo()
  2963. page, _ := c.GetInt64("page", 1)
  2964. limit, _ := c.GetInt64("limit", 10)
  2965. schedulType, _ := c.GetInt64("schedul_type", 0)
  2966. startTime, _ := c.GetInt64("schedul_time", 0)
  2967. partitionType, _ := c.GetInt64("partition_type", 0)
  2968. keywords := c.GetString("keywords")
  2969. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2970. if err == nil {
  2971. c.ServeSuccessJSON(map[string]interface{}{
  2972. "schedule": dialysisSchedule,
  2973. })
  2974. }
  2975. return
  2976. }
  2977. // /m/api/dialysis/start [post]
  2978. // @param patient_id:int
  2979. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2980. // @param nurse:int 上机护士
  2981. // @param bed:int 床位号
  2982. func (this *DialysisAPIController) StartDialysis() {
  2983. patientID, _ := this.GetInt64("patient_id")
  2984. recordDateStr := this.GetString("record_date")
  2985. nurseID, _ := this.GetInt64("start_nurse")
  2986. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2987. blood_drawing, _ := this.GetInt64("blood_drawing")
  2988. schedual_type, _ := this.GetInt64("schedual_type")
  2989. bedID, _ := this.GetInt64("bed")
  2990. start_time := this.GetString("start_time")
  2991. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2992. change_nurse, _ := this.GetInt64("change_nurse")
  2993. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2994. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2995. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2996. puncture_needle := this.GetString("puncture_needle")
  2997. puncture_way := this.GetString("puncture_way")
  2998. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2999. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3000. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3001. zone_id, _ := this.GetInt64("zone_id")
  3002. elecsign := this.GetString("url")
  3003. nuclein_date_str := this.GetString("nuclein_date_str")
  3004. schedule_remark := this.GetString("schedule_remark")
  3005. order_remark := this.GetString("order_remark")
  3006. catheter_operation := this.GetString("catheter_operation")
  3007. blood_flow_volume := this.GetString("blood_flow_volume")
  3008. dialysis_strainer := this.GetString("dialysis_strainer")
  3009. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3011. return
  3012. }
  3013. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3014. if parseStartDateErr != nil {
  3015. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3017. return
  3018. }
  3019. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3020. if parseErr != nil {
  3021. this.ErrorLog("时间解析失败:%v", parseErr)
  3022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3023. return
  3024. }
  3025. adminUserInfo := this.GetMobileAdminUserInfo()
  3026. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3027. if getPatientErr != nil {
  3028. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3030. return
  3031. } else if patient == nil {
  3032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3033. return
  3034. }
  3035. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3036. if getNurseErr != nil {
  3037. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3039. return
  3040. } else if nurse == nil {
  3041. this.ErrorLog("护士不存在")
  3042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3046. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3047. if getDeviceNumberErr != nil {
  3048. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3050. return
  3051. } else if deviceNumber == nil {
  3052. this.ErrorLog("床位号不存在")
  3053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3054. return
  3055. }
  3056. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3057. if getRecordErr != nil {
  3058. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3060. return
  3061. } else if dialysisRecord != nil {
  3062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3063. return
  3064. }
  3065. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3066. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3067. timeLayout := "2006-01-02 15:04:05"
  3068. loc, _ := time.LoadLocation("Local")
  3069. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3070. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3071. schedulestartTime := theStartTime.Unix()
  3072. scheduleendTime := theEndTime.Unix()
  3073. var theNucleinDate int64
  3074. timeLayoutOne := "2006-01-02"
  3075. if len(nuclein_date_str) > 0 {
  3076. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3077. if err != nil {
  3078. utils.ErrorLog(err.Error())
  3079. }
  3080. theNucleinDate = theTime.Unix()
  3081. }
  3082. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3083. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3084. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3085. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3086. //查询该床位是否有人用了
  3087. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3088. if err == gorm.ErrRecordNotFound { //空床位
  3089. // 修改了床位逻辑
  3090. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3091. if daySchedule.ID > 0 {
  3092. daySchedule.PartitionId = deviceNumber.ZoneID
  3093. daySchedule.BedId = bedID
  3094. daySchedule.ScheduleType = schedual_type
  3095. daySchedule.UpdatedTime = time.Now().Unix()
  3096. xtSchedule := models.Schedule{
  3097. PartitionId: deviceNumber.ZoneID,
  3098. BedId: bedID,
  3099. ScheduleType: schedual_type,
  3100. UpdatedTime: time.Now().Unix(),
  3101. }
  3102. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3103. if err != nil {
  3104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3105. return
  3106. }
  3107. }
  3108. } else if err == nil {
  3109. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3110. if order.ID > 0 { //该机位被其他人占用了
  3111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3112. return
  3113. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3114. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3115. if daySchedule.ID > 0 {
  3116. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3117. if err != nil {
  3118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3119. return
  3120. }
  3121. }
  3122. }
  3123. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3125. return
  3126. }
  3127. //else if order.ID == 0 { //该床位没被占用
  3128. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3129. // if daySchedule.ID > 0 {
  3130. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3131. // //daySchedule.BedId = bedID
  3132. // //daySchedule.ScheduleType = schedual_type
  3133. // //daySchedule.UpdatedTime = time.Now().Unix()
  3134. // //err := service.UpdateSchedule(&daySchedule)
  3135. // xtSchedule := models.Schedule{
  3136. // PartitionId: deviceNumber.ZoneID,
  3137. // BedId: bedID,
  3138. // ScheduleType: schedual_type,
  3139. // UpdatedTime: time.Now().Unix(),
  3140. // }
  3141. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3142. // if err != nil {
  3143. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3144. // return
  3145. // }
  3146. // }
  3147. //}
  3148. //}
  3149. } else if err != nil {
  3150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3151. return
  3152. }
  3153. // 查询信息规挡的设置天数
  3154. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3155. if infor.ID > 0 && infor.WeekDay > 0 {
  3156. var cha_time int64
  3157. timeNowStr := time.Now().Format("2006-01-02")
  3158. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3159. //今日的日期减去设置的日期
  3160. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3161. if cha_time >= recordDate.Unix() {
  3162. //查询审核是否允许
  3163. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3164. //申请状态不允许的情况 拒绝修改
  3165. if infor.ApplicationStatus != 1 {
  3166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3167. return
  3168. }
  3169. }
  3170. }
  3171. dialysisRecord = &models.DialysisOrder{
  3172. DialysisDate: recordDate.Unix(),
  3173. UserOrgId: adminUserInfo.Org.Id,
  3174. PatientId: patientID,
  3175. Stage: 1,
  3176. BedID: bedID,
  3177. StartNurse: nurseID,
  3178. Status: 1,
  3179. StartTime: startDate.Unix(),
  3180. CreatedTime: time.Now().Unix(),
  3181. UpdatedTime: time.Now().Unix(),
  3182. PunctureNurse: puncture_nurse,
  3183. Creator: adminUserInfo.AdminUser.Id,
  3184. Modifier: adminUserInfo.AdminUser.Id,
  3185. SchedualType: schedual_type,
  3186. WashpipeNurse: washpipe_nurse,
  3187. ChangeNurse: change_nurse,
  3188. DifficultPunctureNurse: difficult_puncture_nurse,
  3189. NewFistulaNurse: new_fistula_nurse,
  3190. ZoneId: zone_id,
  3191. QualityNurseId: quality_nurse_id,
  3192. PunctureNeedle: puncture_needle,
  3193. PunctureWay: puncture_way,
  3194. DialysisIrrigation: dialysis_irrigation,
  3195. DialysisDialyszers: dialysis_dialyszers,
  3196. BloodAccessId: blood_access_id,
  3197. Url: elecsign,
  3198. NucleinDate: theNucleinDate,
  3199. ScheduleRemark: schedule_remark,
  3200. OrderRemark: order_remark,
  3201. CatheterOperation: catheter_operation,
  3202. BloodFlowVolume: blood_flow_volume,
  3203. BloodDrawing: blood_drawing,
  3204. DialysisStrainer: dialysis_strainer,
  3205. }
  3206. //查询该床位是否有人用了
  3207. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3208. if errorscode == gorm.ErrRecordNotFound {
  3209. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3210. finish := models.XtDialysisFinish{
  3211. IsFinish: 1,
  3212. UserOrgId: adminUserInfo.Org.Id,
  3213. Status: 1,
  3214. Ctime: time.Now().Unix(),
  3215. Mtime: 0,
  3216. Module: 6,
  3217. RecordDate: schedulestartTime,
  3218. Sourse: 1,
  3219. PatientId: patientID,
  3220. }
  3221. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3222. if dialysisFinish.ID == 0 {
  3223. service.CreateDialysisFinish(finish)
  3224. }
  3225. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3226. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3227. //统计该患者总次数
  3228. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3229. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3230. }
  3231. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3232. //统计该患者总次数
  3233. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3234. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3235. }
  3236. redis := service.RedisClient()
  3237. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3238. redis.Set(key, "", time.Second)
  3239. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3240. //清空key 值
  3241. redis.Set(keyOne, "", time.Second)
  3242. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3243. //清空key 值
  3244. redis.Set(keyTwo, "", time.Second)
  3245. if createErr != nil {
  3246. this.ErrorLog("上机失败:%v", createErr)
  3247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3248. return
  3249. }
  3250. }
  3251. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3252. var tempdispose string
  3253. // 只针对中能建
  3254. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3255. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3256. }
  3257. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3258. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3259. }
  3260. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3261. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3262. //}
  3263. var ultrafiltration_rate float64
  3264. var ultrafiltration_rate_one string
  3265. var replacement_rate float64
  3266. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3267. //后期预增脱水量
  3268. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3269. if prescription.ID > 0 {
  3270. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3271. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3272. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3273. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3274. }
  3275. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3276. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3277. }
  3278. //针对医师汇
  3279. if adminUserInfo.Org.Id == 10121 {
  3280. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3281. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3282. }
  3283. //针对通道
  3284. if adminUserInfo.Org.Id == 10234 {
  3285. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3286. }
  3287. //针对监利大垸医院
  3288. if template.TemplateId == 41 {
  3289. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3290. }
  3291. //针对肇庆三鹤血液透析中心
  3292. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3293. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3294. }
  3295. if adminUserInfo.Org.Id == 10469 {
  3296. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3297. }
  3298. if adminUserInfo.Org.Id == 10667 {
  3299. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3300. }
  3301. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3302. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3303. }
  3304. // 只针对方济医院
  3305. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3306. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3307. ultrafiltration_rate = value
  3308. }
  3309. //针对
  3310. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3311. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3312. ultrafiltration_rate = ultrafiltration_rate / 1000
  3313. }
  3314. if adminUserInfo.Org.Id == 10551 {
  3315. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3316. ultrafiltration_rate = ultrafiltration_rate / 1000
  3317. }
  3318. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3319. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3320. ultrafiltration_rate = ultrafiltration_rate / 1000
  3321. }
  3322. if adminUserInfo.Org.Id == 10580 {
  3323. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3324. ultrafiltration_rate = ultrafiltration_rate / 1000
  3325. }
  3326. if adminUserInfo.Org.Id == 10629 {
  3327. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3328. ultrafiltration_rate = ultrafiltration_rate / 1000
  3329. }
  3330. if adminUserInfo.Org.Id == 10644 {
  3331. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3332. ultrafiltration_rate = ultrafiltration_rate / 1000
  3333. }
  3334. if adminUserInfo.Org.Id == 10667 {
  3335. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3336. ultrafiltration_rate = ultrafiltration_rate / 1000
  3337. }
  3338. if adminUserInfo.Org.Id == 10693 {
  3339. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3340. ultrafiltration_rate = ultrafiltration_rate
  3341. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3342. }
  3343. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 || adminUserInfo.Org.Id == 10731 {
  3344. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3345. ultrafiltration_rate = ultrafiltration_rate
  3346. }
  3347. if adminUserInfo.Org.Id == 10702 {
  3348. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3349. ultrafiltration_rate = ultrafiltration_rate / 1000
  3350. }
  3351. if adminUserInfo.Org.Id == 10723 {
  3352. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3353. ultrafiltration_rate = ultrafiltration_rate / 1000
  3354. }
  3355. if adminUserInfo.Org.Id == 10721 {
  3356. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3357. ultrafiltration_rate = ultrafiltration_rate / 1000
  3358. }
  3359. if adminUserInfo.Org.Id == 10721 {
  3360. if prescription.ModeId == 2 {
  3361. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3362. if totalMin == 0 {
  3363. totalMin = 240
  3364. }
  3365. if prescription.ReplacementTotal == 0 {
  3366. prescription.ReplacementTotal = 15
  3367. }
  3368. //乘10 除10是为了保留一位小数
  3369. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3370. }
  3371. }
  3372. if adminUserInfo.Org.Id == 10702 {
  3373. if prescription.ModeId == 2 {
  3374. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3375. if totalMin == 0 {
  3376. totalMin = 240
  3377. }
  3378. if prescription.DisplaceLiquiValue == 0 {
  3379. prescription.ReplacementTotal = 32
  3380. }
  3381. //乘10 除10是为了保留一位小数
  3382. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3383. }
  3384. }
  3385. }
  3386. }
  3387. if adminUserInfo.Org.Id == 10172 {
  3388. if prescription.ID == 0 {
  3389. if prescription.ModeId == 2 {
  3390. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3391. if totalMin == 0 {
  3392. totalMin = 240
  3393. }
  3394. if prescription.ReplacementTotal == 0 {
  3395. prescription.ReplacementTotal = 15
  3396. }
  3397. //乘10 除10是为了保留一位小数
  3398. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3399. }
  3400. }
  3401. }
  3402. record := models.MonitoringRecord{
  3403. UserOrgId: adminUserInfo.Org.Id,
  3404. PatientId: patientID,
  3405. DialysisOrderId: dialysisRecord.ID,
  3406. MonitoringDate: schedulestartTime,
  3407. OperateTime: startDate.Unix(),
  3408. // MonitoringTime: recordTime,
  3409. MonitoringNurse: nurseID,
  3410. Dispose: tempdispose,
  3411. UltrafiltrationRate: ultrafiltration_rate,
  3412. UltrafiltrationVolume: 0,
  3413. Status: 1,
  3414. CreatedTime: time.Now().Unix(),
  3415. UpdatedTime: time.Now().Unix(),
  3416. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3417. ReplacementRate: replacement_rate,
  3418. }
  3419. //只针对广慈医院
  3420. 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 {
  3421. // 查询病人是否有透前评估数据
  3422. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3423. //如果有数据就插入
  3424. if errcode == nil {
  3425. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3426. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3427. record.BreathingRate = befor.BreathingRate
  3428. record.PulseFrequency = befor.PulseFrequency
  3429. record.Temperature = befor.Temperature
  3430. }
  3431. }
  3432. //孝昌
  3433. if adminUserInfo.Org.Id == 10693 {
  3434. // 查询病人是否有透前评估数据
  3435. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3436. //如果有数据就插入
  3437. if errcode == nil {
  3438. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3439. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3440. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3441. record.BreathingRate = befor.BreathingRate
  3442. }
  3443. }
  3444. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3445. if newdialysisRecord.ID > 0 {
  3446. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3447. record.Temperature = 36.5
  3448. record.ArterialPressure = -100
  3449. record.DialysateTemperature = 36.5
  3450. record.Conductivity = 14
  3451. record.BreathingRate = "20"
  3452. record.VenousPressure = 80
  3453. record.TransmembranePressure = 60
  3454. record.Dispose = catheter_operation
  3455. }
  3456. //针对新化博翔
  3457. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3458. record.BloodOxygenSaturation = "99"
  3459. record.Conductivity = 14
  3460. record.DialysateTemperature = 36.5
  3461. record.BreathingRate = "20"
  3462. }
  3463. //针对兰溪人民医院的需求
  3464. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3465. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3466. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3467. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3468. record.Temperature = befor.Temperature
  3469. record.PulseFrequency = befor.PulseFrequency
  3470. record.BreathingRate = befor.BreathingRate
  3471. }
  3472. //针对乐山友谊医院的需求
  3473. if adminUserInfo.Org.Id == 10677 {
  3474. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3475. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3476. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3477. record.Temperature = befor.Temperature
  3478. record.PulseFrequency = befor.PulseFrequency
  3479. record.BreathingRate = befor.BreathingRate
  3480. }
  3481. //新化博翔
  3482. if adminUserInfo.Org.Id == 10447 {
  3483. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3484. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3485. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3486. record.BreathingRate = befor.BreathingRate
  3487. }
  3488. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3489. record.PulseFrequency = 80
  3490. record.Temperature = 36.5
  3491. }
  3492. //诊断灵山圣康
  3493. if adminUserInfo.Org.Id == 10375 {
  3494. record.Conductivity = 13.8
  3495. record.DialysateTemperature = 37
  3496. record.DialysateFlow = 500
  3497. record.BloodFlowVolume = 200
  3498. record.BreathingRate = "18"
  3499. record.SodiumConcentration = 140
  3500. }
  3501. //江成肾病医院
  3502. if adminUserInfo.Org.Id == 10517 {
  3503. record.SodiumConcentration = 138
  3504. record.DialysateTemperature = 36.5
  3505. }
  3506. //濉溪杏康血液透析中心
  3507. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3508. record.BloodFlowVolume = prescription.BloodFlowVolume
  3509. }
  3510. if adminUserInfo.Org.Id != 10683 {
  3511. err = service.CreateMonitor(&record)
  3512. }
  3513. //记录日志
  3514. byterequest, _ := json.Marshal(record)
  3515. monitorRecordLog := models.XtMonitorRecordLog{
  3516. RecordDate: record.MonitoringDate,
  3517. PatientId: record.PatientId,
  3518. Module: 1,
  3519. AdminUserId: adminUserInfo.AdminUser.Id,
  3520. Ctime: time.Now().Unix(),
  3521. Mtime: 0,
  3522. Status: 1,
  3523. UserOrgId: record.UserOrgId,
  3524. ErrLog: string(byterequest),
  3525. Source: "执行上机时新增监测",
  3526. }
  3527. service.CreateMonitorRecordLog(monitorRecordLog)
  3528. finish := models.XtDialysisFinish{
  3529. IsFinish: 1,
  3530. UserOrgId: adminUserInfo.Org.Id,
  3531. Status: 1,
  3532. Ctime: time.Now().Unix(),
  3533. Mtime: 0,
  3534. Module: 7,
  3535. RecordDate: schedulestartTime,
  3536. Sourse: 1,
  3537. PatientId: patientID,
  3538. }
  3539. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3540. if dialysisFinish.ID == 0 {
  3541. service.CreateDialysisFinish(finish)
  3542. }
  3543. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3544. redis := service.RedisClient()
  3545. //清空key 值
  3546. redis.Set(key, "", time.Second)
  3547. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3548. redis.Set(keyOne, "", time.Second)
  3549. defer redis.Close()
  3550. if err != nil {
  3551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3552. return
  3553. }
  3554. }
  3555. go func() {
  3556. ssoDomain := beego.AppConfig.String("call_domain")
  3557. api := ssoDomain + "/index/uppatient"
  3558. values := make(url.Values)
  3559. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3560. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3561. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3562. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3563. http.PostForm(api, values)
  3564. }()
  3565. this.ServeSuccessJSON(map[string]interface{}{
  3566. "dialysis_order": newdialysisRecord,
  3567. "monitor": record,
  3568. })
  3569. return
  3570. }
  3571. func (c *DialysisAPIController) PostSolution() {
  3572. id, _ := c.GetInt64("patient", 0)
  3573. recordDateStr := c.GetString("record_date")
  3574. if id <= 0 {
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3576. return
  3577. }
  3578. adminUserInfo := c.GetMobileAdminUserInfo()
  3579. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3580. if patient.ID == 0 {
  3581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3582. return
  3583. }
  3584. if len(recordDateStr) == 0 {
  3585. recordDateStr = time.Now().Format("2006-01-02")
  3586. }
  3587. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3588. if parseDateErr != nil {
  3589. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3591. return
  3592. }
  3593. mode_id, _ := c.GetInt64("mode_id", 0)
  3594. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3595. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3596. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3597. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3598. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3599. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3600. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3601. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3602. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3603. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3604. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3605. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3606. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3607. kalium, _ := c.GetFloat("kalium", 0)
  3608. sodium, _ := c.GetFloat("sodium", 0)
  3609. calcium, _ := c.GetFloat("calcium", 0)
  3610. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3611. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3612. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3613. glucose, _ := c.GetFloat("glucose", 0)
  3614. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3615. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3616. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3617. conductivity, _ := c.GetFloat("conductivity", 0)
  3618. remark := c.GetString("remark")
  3619. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3620. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3621. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3622. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3623. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3624. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3625. special_medicine_other := c.GetString("special_medicine_other")
  3626. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3627. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3628. blood_access, _ := c.GetInt64("blood_access", 0)
  3629. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3630. body_fluid_other := c.GetString("body_fluid_other")
  3631. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3632. niprocart, _ := c.GetInt64("niprocart", 0)
  3633. jms, _ := c.GetInt64("jms", 0)
  3634. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3635. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3636. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3637. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3638. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3639. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3640. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3641. injector, _ := c.GetInt64("injector", 0)
  3642. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3643. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3644. safe_package, _ := c.GetInt64("package", 0)
  3645. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3646. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3647. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3648. blood := c.GetString("blood")
  3649. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3650. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3651. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3652. displace_speed := c.GetString("displace_speed")
  3653. illness, _ := c.GetInt64("illness")
  3654. amylaceum := c.GetString("amylaceum")
  3655. single_time := c.GetString("single_time")
  3656. single_water := c.GetString("single_water")
  3657. replacement_flow := c.GetString("replacement_flow")
  3658. plasma_separator := c.GetString("plasma_separator")
  3659. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3660. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3661. oxygen_flow := c.GetString("oxygen_flow")
  3662. oxygen_time := c.GetString("oxygen_time")
  3663. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3664. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3665. puncture_needle := c.GetString("puncture_needle")
  3666. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3667. epo := c.GetString("epo")
  3668. epo_count, _ := c.GetFloat("epo_count", 0)
  3669. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3670. pre_impulse := c.GetString("pre_impulse")
  3671. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3672. admin_user_id, _ := c.GetInt64("admin_user_id")
  3673. is_water := c.GetString("is_water")
  3674. add_amount, _ := c.GetFloat("add_amount")
  3675. reduce_amount, _ := c.GetFloat("reduce_amount")
  3676. prescribing_number, _ := c.GetFloat("prescribing_number")
  3677. treatment_remark := c.GetString("treatment_remark")
  3678. prescription_sodium := c.GetString("prescription_sodium")
  3679. start_sodium := c.GetString("start_sodium")
  3680. sodium_curve := c.GetString("sodium_curve")
  3681. var is_war int64
  3682. if is_water == "是" {
  3683. is_war = 1
  3684. }
  3685. if is_water == "否" {
  3686. is_war = 2
  3687. }
  3688. if is_water == "请选择" {
  3689. is_war = 0
  3690. }
  3691. drhy_water := c.GetString("drhy_water")
  3692. dry_water_hour := c.GetString("dry_water_hour")
  3693. water_machine := c.GetString("water_machine")
  3694. dialysis_remark := c.GetString("dialysis_remark")
  3695. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3696. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3697. prescription_water, _ := c.GetFloat("prescription_water")
  3698. dialysis_strainer := c.GetString("dialysis_strainer")
  3699. chaptalization := c.GetString("chaptalization")
  3700. washing_time := c.GetString("washing_time")
  3701. warsh_count := c.GetString("warsh_count")
  3702. blood_access_part_id := c.GetString("blood_access_part_id")
  3703. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3704. dialyzate := c.GetString("dialyzate")
  3705. if mode_id > 0 {
  3706. var str string
  3707. //查找该机构用的是什么透析器
  3708. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3709. if filedConfig.ID > 0 {
  3710. str = dialyzerPerfusionApparatus
  3711. } else {
  3712. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3713. }
  3714. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3715. }
  3716. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3717. //
  3718. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3719. // if appRole.UserType == 3 {
  3720. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3721. // if getPermissionErr != nil {
  3722. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3723. // return
  3724. // } else if headNursePermission == nil {
  3725. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3726. // return
  3727. // }
  3728. // }
  3729. //}
  3730. // 查询信息规挡的设置天数
  3731. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3732. if infor.ID > 0 && infor.WeekDay > 0 {
  3733. var cha_time int64
  3734. timeNowStr := time.Now().Format("2006-01-02")
  3735. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3736. //今日的日期减去设置的日期
  3737. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3738. if cha_time >= recordDate.Unix() {
  3739. //查询审核是否允许
  3740. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3741. //申请状态不允许的情况 拒绝修改
  3742. if infor.ApplicationStatus != 1 {
  3743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3744. return
  3745. }
  3746. }
  3747. }
  3748. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3749. var dialysis_dialyszers_id int64
  3750. var dialysis_strainer_id int64
  3751. var dialysis_irrigation_id int64
  3752. if len(goodList) > 0 {
  3753. for _, item := range goodList {
  3754. if item.SpecificationName == dialysis_dialyszers {
  3755. dialysis_dialyszers_id = item.ID
  3756. }
  3757. if item.SpecificationName == dialysis_irrigation {
  3758. dialysis_irrigation_id = item.ID
  3759. }
  3760. if item.SpecificationName == dialysis_strainer {
  3761. dialysis_strainer_id = item.ID
  3762. }
  3763. }
  3764. }
  3765. prescription := models.DialysisPrescription{
  3766. UserOrgId: adminUserInfo.Org.Id,
  3767. PatientId: id,
  3768. RecordDate: recordDate.Unix(),
  3769. ModeId: mode_id,
  3770. DialysisDuration: dialysis_duration,
  3771. Dialyzer: dialyzer,
  3772. PerfusionApparatus: perfusion_apparatus,
  3773. BloodFlowVolume: blood_flow_volume,
  3774. DewaterAmount: dewater_amount,
  3775. DisplaceLiqui: displace_liqui,
  3776. ReplacementWay: replacement_way,
  3777. Anticoagulant: anticoagulant,
  3778. AnticoagulantShouji: anticoagulant_shouji,
  3779. AnticoagulantWeichi: anticoagulant_weichi,
  3780. AnticoagulantZongliang: anticoagulant_zongliang,
  3781. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3782. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3783. Kalium: kalium,
  3784. Sodium: sodium,
  3785. Calcium: calcium,
  3786. Bicarbonate: bicarbonate,
  3787. Glucose: glucose,
  3788. // DryWeight: dry_weight,
  3789. DialysateFlow: dialysate_flow,
  3790. DialysateTemperature: dialysate_temperature,
  3791. Conductivity: conductivity,
  3792. Remark: remark,
  3793. Status: 1,
  3794. CreatedTime: time.Now().Unix(),
  3795. UpdatedTime: time.Now().Unix(),
  3796. DialysisDurationMinute: dialysisDurationMinute,
  3797. DialysisDurationHour: dialysisDurationHour,
  3798. TargetUltrafiltration: targetUltrafiltration,
  3799. DialysateFormulation: dialysateFormulation,
  3800. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3801. BodyFluid: body_fluid,
  3802. SpecialMedicine: special_medicine,
  3803. SpecialMedicineOther: special_medicine_other,
  3804. DisplaceLiquiPart: displace_liqui_part,
  3805. DisplaceLiquiValue: displace_liqui_value,
  3806. BloodAccess: blood_access,
  3807. Ultrafiltration: ultrafiltration,
  3808. BodyFluidOther: body_fluid_other,
  3809. ReplacementTotal: replacement_total,
  3810. Niprocart: niprocart,
  3811. Jms: jms,
  3812. FistulaNeedleSet: fistula_needle_set,
  3813. FistulaNeedleSet16: fistula_needle_set_16,
  3814. Hemoperfusion: hemoperfusion,
  3815. DialyserSterilised: dialyser_sterilised,
  3816. Filtryzer: filtryzer,
  3817. TargetKtv: target_ktv,
  3818. Dialyzers: dialyzers,
  3819. Injector: injector,
  3820. Bloodlines: bloodlines,
  3821. TubingHemodialysis: tubing_hemodialysis,
  3822. Package: safe_package,
  3823. ALiquid: a_liquid,
  3824. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3825. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3826. Blood: blood,
  3827. DialysisDialyszers: dialysis_dialyszers,
  3828. DialysisIrrigation: dialysis_irrigation,
  3829. AntioxidantCommodityName: antioxidant_commodity_name,
  3830. DisplaceSpeed: displace_speed,
  3831. Illness: illness,
  3832. Amylaceum: amylaceum,
  3833. SingleWater: single_water,
  3834. SingleTime: single_time,
  3835. ReplacementFlow: replacement_flow,
  3836. PlasmaSeparator: plasma_separator,
  3837. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3838. OxygenUptake: oxygen_uptake,
  3839. OxygenTime: oxygen_time,
  3840. OxygenFlow: oxygen_flow,
  3841. HemodialysisPipelines: hemodialysis_pipelines,
  3842. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3843. PunctureNeedle: puncture_needle,
  3844. PunctureNeedleCount: puncture_needle_count,
  3845. Epo: epo,
  3846. EpoCount: epo_count,
  3847. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3848. PreImpulse: impulse,
  3849. AdminUserId: admin_user_id,
  3850. IsWater: is_war,
  3851. DrhyWater: drhy_water,
  3852. DryWaterHour: dry_water_hour,
  3853. WaterMachine: water_machine,
  3854. AddAmount: add_amount,
  3855. ReduceAmount: reduce_amount,
  3856. DialysisRemark: dialysis_remark,
  3857. PrescribingNumber: prescribing_number,
  3858. PrescriptionSodium: prescription_sodium,
  3859. StartSodium: start_sodium,
  3860. SodiumCurve: sodium_curve,
  3861. TreatmentRemark: treatment_remark,
  3862. DialysisFluidFlow: dialysis_fluid_flow,
  3863. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3864. PrescriptionWater: prescription_water,
  3865. DialysisStrainer: dialysis_strainer,
  3866. Chaptalization: chaptalization,
  3867. WashingTime: washing_time,
  3868. WarshCount: warsh_count,
  3869. BloodAccessPartId: blood_access_part_id,
  3870. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3871. Dialyzate: dialyzate,
  3872. DialysisDialyszersId: dialysis_dialyszers_id,
  3873. DialysisIrrigationId: dialysis_irrigation_id,
  3874. DialysisStrainerId: dialysis_strainer_id,
  3875. }
  3876. if adminUserInfo.Org.Id == 10721 {
  3877. if prescription.ModeId == 2 {
  3878. if prescription.ReplacementTotal == 0 {
  3879. prescription.ReplacementTotal = 15
  3880. }
  3881. }
  3882. }
  3883. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3884. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3885. //
  3886. if appRole.UserType == 2 || appRole.UserType == 1 {
  3887. prescription_doctor = adminUserInfo.AdminUser.Id
  3888. prescription.PrescriptionDoctor = prescription_doctor
  3889. }
  3890. if dialysisPrescription.ID == 0 { //新增
  3891. prescription.Creater = adminUserInfo.AdminUser.Id
  3892. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3893. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3894. }
  3895. } else { //修改
  3896. if dialysisPrescription.Creater == 0 {
  3897. prescription.Creater = adminUserInfo.AdminUser.Id
  3898. } else {
  3899. prescription.Creater = dialysisPrescription.Creater
  3900. if adminUserInfo.Org.Id == 9882 {
  3901. if appRole.UserType == 2 || appRole.UserType == 1 {
  3902. prescription.Creater = adminUserInfo.AdminUser.Id
  3903. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3904. }
  3905. }
  3906. }
  3907. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3908. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3909. }
  3910. //if/**/
  3911. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3912. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3913. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3914. // if getPermissionErr != nil {
  3915. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3916. // return
  3917. // } else if headNursePermission == nil {
  3918. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3919. // return
  3920. // }
  3921. //}
  3922. //prescription.Creater = dialysisPrescription.Creater
  3923. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3924. prescription.Modifier = adminUserInfo.AdminUser.Id
  3925. prescription.ID = dialysisPrescription.ID
  3926. }
  3927. solution := models.DialysisSolution{
  3928. RegistrarsId: adminUserInfo.AdminUser.Id,
  3929. UserOrgId: adminUserInfo.Org.Id,
  3930. Doctor: prescription_doctor,
  3931. PatientId: id,
  3932. ModeId: mode_id,
  3933. DialysisDuration: dialysis_duration,
  3934. PerfusionApparatus: perfusion_apparatus,
  3935. BloodFlowVolume: blood_flow_volume,
  3936. Dewater: dewater_amount,
  3937. DisplaceLiqui: displace_liqui,
  3938. ReplacementWay: replacement_way,
  3939. Anticoagulant: anticoagulant,
  3940. AnticoagulantShouji: anticoagulant_shouji,
  3941. AnticoagulantWeichi: anticoagulant_weichi,
  3942. AnticoagulantZongliang: anticoagulant_zongliang,
  3943. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3944. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3945. Kalium: kalium,
  3946. Sodium: sodium,
  3947. Calcium: calcium,
  3948. Bicarbonate: bicarbonate,
  3949. Glucose: glucose,
  3950. // DryWeight: dry_weight,
  3951. DialysateFlow: dialysate_flow,
  3952. DialysateTemperature: dialysate_temperature,
  3953. Conductivity: conductivity,
  3954. Remark: remark,
  3955. Status: 1,
  3956. CreatedTime: time.Now().Unix(),
  3957. UpdatedTime: time.Now().Unix(),
  3958. DialysisDurationMinute: dialysisDurationMinute,
  3959. DialysisDurationHour: dialysisDurationHour,
  3960. TargetUltrafiltration: targetUltrafiltration,
  3961. DialysateFormulation: dialysateFormulation,
  3962. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3963. BodyFluid: body_fluid,
  3964. SpecialMedicine: special_medicine,
  3965. SpecialMedicineOther: special_medicine_other,
  3966. DisplaceLiquiPart: displace_liqui_part,
  3967. DisplaceLiquiValue: displace_liqui_value,
  3968. BloodAccess: blood_access,
  3969. Ultrafiltration: ultrafiltration,
  3970. BodyFluidOther: body_fluid_other,
  3971. ReplacementTotal: replacement_total,
  3972. TargetKtv: target_ktv,
  3973. DialysisDialyszers: dialysis_dialyszers,
  3974. DialysisIrrigation: dialysis_irrigation,
  3975. HemodialysisPipelines: hemodialysis_pipelines,
  3976. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3977. PunctureNeedle: puncture_needle,
  3978. PunctureNeedleCount: puncture_needle_count,
  3979. Epo: epo,
  3980. EpoCount: epo_count,
  3981. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3982. PreImpulse: impulse,
  3983. SolutionStatus: 1,
  3984. DialysisRemark: dialysis_remark,
  3985. PrescribingNumber: prescribing_number,
  3986. PrescriptionSodium: prescription_sodium,
  3987. StartSodium: start_sodium,
  3988. SodiumCurve: sodium_curve,
  3989. TreatmentRemark: treatment_remark,
  3990. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3991. DialysisFluidFlow: dialysis_fluid_flow,
  3992. PrescriptionWater: prescription_water,
  3993. DialysisStrainer: dialysis_strainer,
  3994. Chaptalization: chaptalization,
  3995. WashingTime: washing_time,
  3996. WarshCount: warsh_count,
  3997. BloodAccessPartId: blood_access_part_id,
  3998. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3999. Dialyzate: dialyzate,
  4000. DialysisDialyszersId: dialysis_dialyszers_id,
  4001. DialysisIrrigationId: dialysis_irrigation_id,
  4002. DialysisStrainerId: dialysis_strainer_id,
  4003. }
  4004. //针对河间咸的
  4005. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4006. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4007. solution.DisplaceLiquiPart = 0
  4008. solution.DisplaceLiquiValue = 0
  4009. }
  4010. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4011. prescription.DisplaceLiquiPart = 0
  4012. prescription.DisplaceLiquiValue = 0
  4013. }
  4014. }
  4015. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4016. if solution.PrescribingNumber == 0 {
  4017. solution.PrescribingNumber = 1
  4018. }
  4019. if prescription.PrescribingNumber == 0 {
  4020. prescription.PrescribingNumber = 1
  4021. }
  4022. if solution.PrescribingNumber == 0 && id == 14682 {
  4023. solution.PrescribingNumber = 2
  4024. }
  4025. if solution.PrescribingNumber == 0 && id == 18560 {
  4026. solution.PrescribingNumber = 2
  4027. }
  4028. if prescription.PrescribingNumber == 0 && id == 14682 {
  4029. prescription.PrescribingNumber = 2
  4030. }
  4031. if prescription.PrescribingNumber == 0 && id == 18560 {
  4032. prescription.PrescribingNumber = 2
  4033. }
  4034. }
  4035. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4036. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4037. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4038. if len(monitorList) > 0 {
  4039. var ultrafiltration_rate float64
  4040. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4041. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4042. var replacement_rate float64
  4043. //乘10 除10是为了保留一位小数
  4044. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4045. var firstOpeateTime = monitorList[0].OperateTime
  4046. for _, item := range monitorList {
  4047. //超滤率
  4048. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4049. //置换率
  4050. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4051. //超滤量
  4052. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4053. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4054. //置换量
  4055. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4056. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4057. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4058. }
  4059. }
  4060. }
  4061. //记录日志
  4062. byterequest, _ := json.Marshal(prescription)
  4063. prescriptionLog := models.XtDialysisPrescriptionLog{
  4064. UserOrgId: prescription.UserOrgId,
  4065. Ctime: time.Now().Unix(),
  4066. Mtime: 0,
  4067. ErrLog: string(byterequest),
  4068. AdminUserId: adminUserInfo.AdminUser.Id,
  4069. RecordDate: prescription.RecordDate,
  4070. PatientId: prescription.PatientId,
  4071. Source: "手机端新增长期处方",
  4072. Status: 1,
  4073. }
  4074. service.CreatePrescriptionLog(prescriptionLog)
  4075. finish := models.XtDialysisFinish{
  4076. IsFinish: 1,
  4077. UserOrgId: adminUserInfo.Org.Id,
  4078. Status: 1,
  4079. Ctime: time.Now().Unix(),
  4080. Mtime: 0,
  4081. Module: 1,
  4082. RecordDate: recordDate.Unix(),
  4083. Sourse: 1,
  4084. PatientId: id,
  4085. }
  4086. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4087. if dialysisFinish.ID == 0 {
  4088. service.CreateDialysisFinish(finish)
  4089. }
  4090. //获取最新1条
  4091. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4092. //更新状态
  4093. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4094. //长沙南雅医院,自动生成抗凝剂的临时处方
  4095. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4096. if prescribing_number == 0 {
  4097. prescribing_number = 1
  4098. }
  4099. advice := models.DoctorAdvice{
  4100. UserOrgId: adminUserInfo.Org.Id,
  4101. PatientId: id,
  4102. GroupNo: 0,
  4103. AdviceType: 2,
  4104. RecordDate: recordDate.Unix(),
  4105. AdviceDate: recordDate.Unix(),
  4106. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4107. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4108. AdviceDesc: "",
  4109. ReminderDate: 0,
  4110. SingleDose: prescription.AnticoagulantZongliang,
  4111. SingleDoseUnit: "iu",
  4112. DrugSpec: 0,
  4113. DrugSpecUnit: "",
  4114. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4115. PrescribingNumberUnit: "支",
  4116. DeliveryWay: "静脉注射",
  4117. ExecutionFrequency: "上机前",
  4118. AdviceDoctor: 0,
  4119. Status: 1,
  4120. CreatedTime: time.Now().Unix(),
  4121. UpdatedTime: time.Now().Unix(),
  4122. IsPrescription: 1,
  4123. ExecutionState: 2,
  4124. StopState: 2,
  4125. IsSettle: 2,
  4126. }
  4127. // 查询排班信息
  4128. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4129. if schedulePatient.ID > 0 {
  4130. if schedulePatient.ScheduleType == 1 {
  4131. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4132. }
  4133. if schedulePatient.ScheduleType == 2 {
  4134. advice.StartTime = recordDate.Unix() + 9*60*60
  4135. }
  4136. }
  4137. // 抗凝剂名称
  4138. switch anticoagulant {
  4139. case 1:
  4140. advice.AdviceName = "无肝素"
  4141. break
  4142. case 2:
  4143. advice.AdviceName = "普通肝素"
  4144. break
  4145. case 3:
  4146. advice.AdviceName = "低分子肝素"
  4147. break
  4148. case 4:
  4149. advice.AdviceName = "阿加曲班"
  4150. break
  4151. case 5:
  4152. advice.AdviceName = "枸橼酸钠"
  4153. break
  4154. case 6:
  4155. advice.AdviceName = "低分子肝素钙"
  4156. break
  4157. case 7:
  4158. advice.AdviceName = "低分子肝素钠"
  4159. break
  4160. case 8:
  4161. advice.AdviceName = "依诺肝素"
  4162. break
  4163. case 9:
  4164. advice.AdviceName = "达肝素"
  4165. break
  4166. case 10:
  4167. advice.AdviceName = "体外抗凝"
  4168. break
  4169. case 11:
  4170. advice.AdviceName = "那曲肝素"
  4171. break
  4172. case 12:
  4173. advice.AdviceName = "无抗凝剂"
  4174. break
  4175. }
  4176. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4177. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4178. advice.AdviceDoctor = appRole.AdminUserId
  4179. }
  4180. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4181. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4182. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4183. advice.AdviceName = "低分子肝素钠注射液"
  4184. // 修改患者临时医嘱里的抗凝剂医嘱
  4185. advice.ID = advicePrescription.ID
  4186. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4187. } else {
  4188. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4189. advice.AdviceName = "低分子肝素钠注射液"
  4190. service.CreateDoctorAdvice(&advice)
  4191. }
  4192. }
  4193. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4194. redis := service.RedisClient()
  4195. defer redis.Close()
  4196. //清空key 值
  4197. redis.Set(key, "", time.Second)
  4198. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4199. redis.Set(keyOne, "", time.Second)
  4200. }
  4201. //获取key,清空redis
  4202. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4203. redis := service.RedisClient()
  4204. defer redis.Close()
  4205. //清空key 值
  4206. redis.Set(key, "", time.Second)
  4207. //清空长期医嘱的key
  4208. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4209. redis.Set(soulution_key, "", time.Second)
  4210. //查询最近透析准备表里是否存在 透析器 灌流器
  4211. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4212. redis.Set(keyOne, "", time.Second)
  4213. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4214. redis.Set(keyTwo, "", time.Second)
  4215. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4216. redis.Set(keyThree, "", time.Second)
  4217. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4218. redis.Set(keyFour, "", time.Second)
  4219. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4220. //
  4221. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4222. //
  4223. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4224. //if len(mation)>0{
  4225. // for _, item := range splitStr {
  4226. // for _,it := range mation{
  4227. // if(item == it.SpecificationName){
  4228. //
  4229. // //查询最近一次的透析器
  4230. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4231. //
  4232. // if errcode == gorm.ErrRecordNotFound{
  4233. // //插入数据
  4234. // prepare := models.DialysisBeforePrepare{
  4235. // UserOrgId: adminUserInfo.Org.Id,
  4236. // PatientId: id,
  4237. // RecordDate: recordDate.Unix(),
  4238. // GoodTypeId: it.GoodTypeId,
  4239. // GoodId: it.ID,
  4240. // Count: 1,
  4241. // Ctime: time.Now().Unix(),
  4242. // Creater: adminUserInfo.AdminUser.Id,
  4243. // Status:1,
  4244. //
  4245. // }
  4246. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4247. // fmt.Println("",errcode)
  4248. // }
  4249. // }
  4250. // }
  4251. //
  4252. // }
  4253. //
  4254. // for _, item := range splitIrrigation {
  4255. // for _,it := range mation{
  4256. // if(item == it.SpecificationName){
  4257. // //查询最近一次的透析器
  4258. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4259. // if errcode == gorm.ErrRecordNotFound{
  4260. // //插入数据
  4261. // prepare := models.DialysisBeforePrepare{
  4262. // UserOrgId: adminUserInfo.Org.Id,
  4263. // PatientId: id,
  4264. // RecordDate: recordDate.Unix(),
  4265. // GoodTypeId: it.GoodTypeId,
  4266. // GoodId: it.ID,
  4267. // Count: 1,
  4268. // Ctime: time.Now().Unix(),
  4269. // Creater: adminUserInfo.AdminUser.Id,
  4270. // Status:1,
  4271. //
  4272. // }
  4273. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4274. // fmt.Println(errcode)
  4275. // }
  4276. // }
  4277. // }
  4278. // }
  4279. //}
  4280. c.ServeSuccessJSON(map[string]interface{}{
  4281. "solution": &solution,
  4282. "prescription": &prescription,
  4283. })
  4284. }
  4285. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4286. patient, _ := c.GetInt64("patient", 0)
  4287. adminUserInfo := c.GetMobileAdminUserInfo()
  4288. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4289. c.ServeSuccessJSON(map[string]interface{}{
  4290. "receiveTreatmentAsses": receiveTreatmentAsses,
  4291. })
  4292. }
  4293. func (this *DialysisAPIController) PostSignInfo() {
  4294. patientID, _ := this.GetInt64("patient_id")
  4295. recordDateStr := this.GetString("date")
  4296. if patientID <= 0 {
  4297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4298. return
  4299. }
  4300. if len(recordDateStr) == 0 {
  4301. recordDateStr = time.Now().Format("2006-01-02")
  4302. }
  4303. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4304. if parseDateErr != nil {
  4305. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4307. return
  4308. }
  4309. adminInfo := this.GetMobileAdminUserInfo()
  4310. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4311. if err != nil {
  4312. this.ErrorLog("签名失败:%v", err)
  4313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4314. return
  4315. }
  4316. this.ServeSuccessJSON(map[string]interface{}{
  4317. "doctor_id": adminInfo.AdminUser.Id,
  4318. })
  4319. }
  4320. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4321. patientID, _ := this.GetInt64("patient_id")
  4322. adminInfo := this.GetMobileAdminUserInfo()
  4323. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4324. this.ServeSuccessJSON(map[string]interface{}{
  4325. "monitor": record,
  4326. })
  4327. }
  4328. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4329. thisTime := time.Now()
  4330. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4331. timeLayout := "2006-01-02 15:04:05"
  4332. loc, _ := time.LoadLocation("Local")
  4333. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4334. theAssessmentDateTime := theStartTime.Unix()
  4335. patientID, _ := this.GetInt64("patient_id")
  4336. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4337. adminInfo := this.GetMobileAdminUserInfo()
  4338. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4339. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4340. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4341. var ultrafiltration_rate float64
  4342. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4343. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4344. fmt.Println(evaluation)
  4345. fmt.Println("prescription.ID", prescription.ID)
  4346. if prescription.ID > 0 {
  4347. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4348. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4349. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4350. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4351. record.UltrafiltrationRate = ultrafiltration_rate
  4352. }
  4353. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4354. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4355. record.UltrafiltrationRate = ultrafiltration_rate
  4356. }
  4357. if adminInfo.Org.Id == 10510 {
  4358. record.UltrafiltrationRate = 0
  4359. }
  4360. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4361. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4362. record.UltrafiltrationRate = ultrafiltration_rate
  4363. }
  4364. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4365. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4366. record.UltrafiltrationRate = ultrafiltration_rate
  4367. }
  4368. // 只针对方济医院
  4369. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4370. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4371. ultrafiltration_rate = value
  4372. record.UltrafiltrationRate = ultrafiltration_rate
  4373. }
  4374. if template.TemplateId == 41 || template.TemplateId == 47 {
  4375. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4376. record.UltrafiltrationRate = ultrafiltration_rate
  4377. }
  4378. if template.TemplateId == 43 {
  4379. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4380. record.UltrafiltrationRate = ultrafiltration_rate
  4381. }
  4382. if template.TemplateId == 46 || template.TemplateId == 54 {
  4383. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4384. record.UltrafiltrationRate = ultrafiltration_rate
  4385. }
  4386. 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 {
  4387. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4388. record.UltrafiltrationRate = ultrafiltration_rate
  4389. }
  4390. if adminInfo.Org.Id == 10469 {
  4391. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4392. record.UltrafiltrationRate = ultrafiltration_rate
  4393. }
  4394. if adminInfo.Org.Id == 10667 {
  4395. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4396. record.UltrafiltrationRate = ultrafiltration_rate
  4397. }
  4398. if adminInfo.Org.Id == 10471 {
  4399. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4400. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4401. }
  4402. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4403. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4404. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4405. }
  4406. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4407. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4408. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4409. }
  4410. if adminInfo.Org.Id == 10721 {
  4411. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4412. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4413. }
  4414. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4415. record.UltrafiltrationRate = 0
  4416. }
  4417. //if template.TemplateId == 47 {
  4418. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4419. // record.UltrafiltrationRate = ultrafiltration_rate
  4420. //}
  4421. }
  4422. }
  4423. // record.UltrafiltrationRate = ultrafiltration_rate
  4424. record.UltrafiltrationVolume = 0
  4425. 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
  4426. if ultrafiltration_rate > 0 {
  4427. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4428. record.UltrafiltrationVolume = value
  4429. }
  4430. }
  4431. 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
  4432. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4433. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4434. record.UltrafiltrationVolume = ultrafiltration_volume
  4435. }
  4436. }
  4437. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4438. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4439. record.UltrafiltrationVolume = ultrafiltration_volume
  4440. }
  4441. //长沙南雅
  4442. 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 {
  4443. if ultrafiltration_rate > 0 {
  4444. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4445. record.UltrafiltrationVolume = ultrafiltration_volume
  4446. }
  4447. }
  4448. if adminInfo.Org.Id == 10471 {
  4449. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4450. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4451. }
  4452. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4453. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4454. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4455. }
  4456. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4457. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4458. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4459. }
  4460. //长沙南雅累计血容量自动计算
  4461. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4462. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4463. //}
  4464. if template.TemplateId == 47 || template.TemplateId == 54 {
  4465. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4466. }
  4467. if adminInfo.Org.Id == 10510 {
  4468. record.UltrafiltrationVolume = 0
  4469. }
  4470. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4471. if ultrafiltration_rate > 0 {
  4472. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4473. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4474. }
  4475. }
  4476. if adminInfo.Org.Id == 10721 {
  4477. var replacement_rate float64
  4478. var displacement_quantity float64
  4479. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4480. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4481. fmt.Println("replacement_rate--------------------------", replacement_rate)
  4482. record.ReplacementRate = replacement_rate
  4483. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4484. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4485. record.DisplacementQuantity = displacement_quantity
  4486. }
  4487. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4488. this.ServeSuccessJSON(map[string]interface{}{
  4489. "monitor": record,
  4490. "lastMonitorRecordList": lastMonitorRecordList,
  4491. })
  4492. }
  4493. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4494. record_id, _ := this.GetInt64("id")
  4495. nurseID, _ := this.GetInt64("start_nurse")
  4496. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4497. bedID, _ := this.GetInt64("bed")
  4498. start_time := this.GetString("start_time")
  4499. schedual_type, _ := this.GetInt64("schedual_type")
  4500. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4501. change_nurse, _ := this.GetInt64("change_nurse")
  4502. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4503. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4504. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4505. patient_id, _ := this.GetInt64("patient_id")
  4506. record_date, _ := this.GetInt64("record_date")
  4507. puncture_needle := this.GetString("puncture_needle")
  4508. puncture_way := this.GetString("puncture_way")
  4509. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4510. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4511. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4512. nuclein_date_str := this.GetString("nuclein_date_str")
  4513. order_remark := this.GetString("order_remark")
  4514. schedule_remark := this.GetString("schedule_remark")
  4515. catheter_operation := this.GetString("catheter_operation")
  4516. blood_flow_volume := this.GetString("blood_flow_volume")
  4517. blood_drawing, _ := this.GetInt64("blood_drawing")
  4518. dialysis_strainer := this.GetString("dialysis_strainer")
  4519. if record_id == 0 {
  4520. this.ErrorLog("id:%v", record_id)
  4521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4522. return
  4523. }
  4524. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4525. if parseStartDateErr != nil {
  4526. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4528. return
  4529. }
  4530. adminUserInfo := this.GetMobileAdminUserInfo()
  4531. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4532. if getNurseErr != nil {
  4533. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4535. return
  4536. } else if nurse == nil {
  4537. this.ErrorLog("护士不存在")
  4538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4539. return
  4540. }
  4541. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4542. //if getNurseErr != nil {
  4543. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4544. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4545. // return
  4546. //} else if nurse == nil {
  4547. // this.ErrorLog("护士不存在")
  4548. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4549. // return
  4550. //}
  4551. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4552. if getDeviceNumberErr != nil {
  4553. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4555. return
  4556. } else if deviceNumber == nil {
  4557. this.ErrorLog("床位号不存在")
  4558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4559. return
  4560. }
  4561. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4562. //
  4563. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4564. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4565. // if getPermissionErr != nil {
  4566. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4567. // return
  4568. // } else if headNursePermission == nil {
  4569. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4570. // return
  4571. // }
  4572. //}
  4573. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4574. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4575. timeLayout := "2006-01-02 15:04:05"
  4576. loc, _ := time.LoadLocation("Local")
  4577. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4578. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4579. schedulestartTime := theStartTime.Unix()
  4580. scheduleendTime := theEndTime.Unix()
  4581. var theNucleinDate int64
  4582. timeLayoutOne := "2006-01-02"
  4583. if len(nuclein_date_str) > 0 {
  4584. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4585. if err != nil {
  4586. utils.ErrorLog(err.Error())
  4587. }
  4588. theNucleinDate = theTime.Unix()
  4589. }
  4590. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4591. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4592. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4593. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4594. if err == gorm.ErrRecordNotFound { //空床位
  4595. // 修改了床位逻辑
  4596. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4597. if daySchedule.ID > 0 {
  4598. //daySchedule.BedId = bedID
  4599. //daySchedule.PartitionId = deviceNumber.ZoneID
  4600. //daySchedule.ScheduleType = schedual_type
  4601. //daySchedule.UpdatedTime = time.Now().Unix()
  4602. //err := service.UpdateSchedule(&daySchedule)
  4603. xtSchedule := models.Schedule{
  4604. PartitionId: deviceNumber.ZoneID,
  4605. BedId: bedID,
  4606. ScheduleType: schedual_type,
  4607. UpdatedTime: time.Now().Unix(),
  4608. }
  4609. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4610. if err != nil {
  4611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4612. return
  4613. }
  4614. }
  4615. } else if err == nil {
  4616. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4617. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4618. if daySchedule.ID > 0 {
  4619. //daySchedule.BedId = bedID
  4620. //daySchedule.PartitionId = deviceNumber.ZoneID
  4621. //
  4622. //daySchedule.ScheduleType = schedual_type
  4623. //daySchedule.UpdatedTime = time.Now().Unix()
  4624. //err := service.UpdateSchedule(&daySchedule)
  4625. xtSchedule := models.Schedule{
  4626. PartitionId: deviceNumber.ZoneID,
  4627. BedId: bedID,
  4628. ScheduleType: schedual_type,
  4629. UpdatedTime: time.Now().Unix(),
  4630. }
  4631. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4632. if err != nil {
  4633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4634. return
  4635. }
  4636. }
  4637. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4639. return
  4640. }
  4641. } else if err != nil {
  4642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4643. return
  4644. }
  4645. }
  4646. dialysisRecord := &models.DialysisOrder{
  4647. ID: record_id,
  4648. UserOrgId: adminUserInfo.Org.Id,
  4649. BedID: bedID,
  4650. StartNurse: nurseID,
  4651. StartTime: startDate.Unix(),
  4652. PunctureNurse: puncture_nurse,
  4653. Creator: adminUserInfo.AdminUser.Id,
  4654. Modifier: adminUserInfo.AdminUser.Id,
  4655. WashpipeNurse: washpipe_nurse,
  4656. SchedualType: schedual_type,
  4657. ChangeNurse: change_nurse,
  4658. DifficultPunctureNurse: difficult_puncture_nurse,
  4659. NewFistulaNurse: new_fistula_nurse,
  4660. QualityNurseId: quality_nurse_id,
  4661. PunctureNeedle: puncture_needle,
  4662. PunctureWay: puncture_way,
  4663. DialysisDialyszers: dialysis_dialyszers,
  4664. DialysisIrrigation: dialysis_irrigation,
  4665. BloodAccessId: blood_access_id,
  4666. NucleinDate: theNucleinDate,
  4667. OrderRemark: order_remark,
  4668. ScheduleRemark: schedule_remark,
  4669. CatheterOperation: catheter_operation,
  4670. BloodFlowVolume: blood_flow_volume,
  4671. BloodDrawing: blood_drawing,
  4672. DialysisStrainer: dialysis_strainer,
  4673. }
  4674. //修改床位号需要重新消毒
  4675. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4676. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4677. //查询第一条监测
  4678. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4679. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4681. redis := service.RedisClient()
  4682. //清空key 值
  4683. redis.Set(key, "", time.Second)
  4684. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4685. redis.Set(keyOne, "", time.Second)
  4686. defer redis.Close()
  4687. }
  4688. // 查询信息规挡的设置天数
  4689. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4690. if infor.ID > 0 && infor.WeekDay > 0 {
  4691. var cha_time int64
  4692. timeNowStr := time.Now().Format("2006-01-02")
  4693. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4694. //今日的日期减去设置的日期
  4695. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4696. if cha_time >= record_date {
  4697. //查询审核是否允许
  4698. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4699. //申请状态不允许的情况 拒绝修改
  4700. if infor.ApplicationStatus != 1 {
  4701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4702. return
  4703. }
  4704. }
  4705. }
  4706. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4707. //修改床位后重新生成消毒计划
  4708. if adminUserInfo.Org.Id == 10340 {
  4709. //根据床位号获取设备型号
  4710. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4711. //查询使用消毒最后一条消毒记录
  4712. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4713. fmt.Println("err", err)
  4714. if err == gorm.ErrRecordNotFound {
  4715. //查找排班
  4716. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4717. //查询改设备是否有消毒计划
  4718. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4719. //根据床位号获取设备id
  4720. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4721. //查询病人信息
  4722. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4723. var con = ""
  4724. if patients.IsInfectious == 0 {
  4725. con = ""
  4726. }
  4727. if patients.IsInfectious == 1 {
  4728. con = "无"
  4729. }
  4730. if patients.IsInfectious == 2 {
  4731. con = "有"
  4732. }
  4733. if errcode == nil {
  4734. var end_time int64
  4735. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4736. //新增消毒
  4737. information := models.DeviceInformation{
  4738. Date: dialysisRecord.DialysisDate,
  4739. Zone: dialysisRecord.ZoneId,
  4740. Class: dialysisRecord.SchedualType,
  4741. BedNumber: dialysisRecord.BedID,
  4742. PatientId: dialysisRecord.PatientId,
  4743. DialysisMode: scheduleByPatient.ModeId,
  4744. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4745. Disinfection: 1,
  4746. DialysisConcentration: 1,
  4747. DisinfectionStatus: 1,
  4748. Move: 1,
  4749. UserOrgId: dialysisRecord.UserOrgId,
  4750. DisinfectType: plan.Way,
  4751. DisinfectantType: plan.MachineDisinfectant,
  4752. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4753. Disinfectant: plan.Disinfectant,
  4754. Ctime: time.Now().Unix(),
  4755. Status: 1,
  4756. SignName: nurseID,
  4757. EquimentId: addmacher.ID,
  4758. DisinfectionResidue: 2,
  4759. Bed: addmacher.BedNumber,
  4760. StartTime: dialysisRecord.StartTime,
  4761. EndTime: dialysisRecord.EndTime,
  4762. Contagion: con,
  4763. WeightLoss: 0,
  4764. Hyperfiltratio: 0,
  4765. DialysisHour: "",
  4766. MachineRun: 1,
  4767. DisinfecStartime: dialysisRecord.EndTime,
  4768. DisinfecEndtime: end_time,
  4769. }
  4770. err := service.CreateInformationTwo(&information)
  4771. fmt.Println("报错", err)
  4772. }
  4773. }
  4774. }
  4775. order, _ := service.GetLastPatientOrder(record_id)
  4776. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4777. redis := service.RedisClient()
  4778. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4779. redis.Set(key, "", time.Second)
  4780. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4781. //清空key 值
  4782. redis.Set(keyOne, "", time.Second)
  4783. scheduleDateStartOne := startDate.Format("2006-01-02")
  4784. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4785. redis.Set(keyTwo, "", time.Second)
  4786. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4787. redis.Set(keyThree, "", time.Second)
  4788. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4789. redis.Set(keyFour, "", time.Second)
  4790. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4791. redis.Set(keyFive, "", time.Second)
  4792. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4793. redis.Set(keySix, "", time.Second)
  4794. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4795. redis.Set(keySeven, "", time.Second)
  4796. if updateErr != nil {
  4797. this.ErrorLog("修改上机失败:%v", updateErr)
  4798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4799. return
  4800. }
  4801. if updateErr == nil {
  4802. if tempDialysisRecord.Stage == 2 {
  4803. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4804. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4805. fmt.Println(value)
  4806. a, b := math.Modf(value)
  4807. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4808. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4809. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4810. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4811. redis := service.RedisClient()
  4812. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4813. redis.Set(key, "", time.Second)
  4814. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4815. redis.Set(keyOne, "", time.Second)
  4816. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4817. //清空key 值
  4818. redis.Set(keySix, "", time.Second)
  4819. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4820. redis.Set(keySeven, "", time.Second)
  4821. redis.Close()
  4822. if updateAssessmentErr != nil {
  4823. utils.ErrorLog("%v", updateAssessmentErr)
  4824. }
  4825. }
  4826. }
  4827. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4828. this.ServeSuccessJSON(map[string]interface{}{
  4829. "dialysis_order": dialysisRecords,
  4830. })
  4831. }
  4832. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4833. record_id, _ := c.GetInt64("id")
  4834. nurseID, _ := c.GetInt64("nurse")
  4835. end_time := c.GetString("end_time")
  4836. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4837. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4838. catheter := c.GetString("catheter")
  4839. cruor := c.GetString("cruor")
  4840. mission := c.GetString("mission")
  4841. condenser := c.GetString("condenser")
  4842. if record_id <= 0 || nurseID <= 0 {
  4843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4844. return
  4845. }
  4846. adminUserInfo := c.GetMobileAdminUserInfo()
  4847. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4848. if getNurseErr != nil {
  4849. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4851. return
  4852. } else if nurse == nil {
  4853. c.ErrorLog("护士不存在")
  4854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4855. return
  4856. }
  4857. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4858. if parseEndDateErr != nil {
  4859. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4861. return
  4862. }
  4863. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4864. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4865. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4866. // if getPermissionErr != nil {
  4867. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4868. // return
  4869. // } else if headNursePermission == nil {
  4870. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4871. // return
  4872. // }
  4873. //}
  4874. // 查询信息规挡的设置天数
  4875. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4876. if infor.ID > 0 {
  4877. var cha_time int64
  4878. timeNowStr := time.Now().Format("2006-01-02")
  4879. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4880. //今日的日期减去设置的日期
  4881. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4882. if cha_time >= tempDialysisRecords.DialysisDate {
  4883. //查询审核是否允许
  4884. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4885. //申请状态不允许的情况 拒绝修改
  4886. if infor.ApplicationStatus != 1 {
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4888. return
  4889. }
  4890. }
  4891. }
  4892. dialysisRecord := &models.DialysisOrder{
  4893. ID: record_id,
  4894. UserOrgId: adminUserInfo.Org.Id,
  4895. EndTime: endDate.Unix(),
  4896. FinishNurse: nurseID,
  4897. FinishModifier: adminUserInfo.AdminUser.Id,
  4898. PuncturePointHaematoma: puncture_point_haematoma,
  4899. BloodAccessInternalFistula: blood_access_internal_fistula,
  4900. Catheter: catheter,
  4901. Cruor: cruor,
  4902. Mission: mission,
  4903. Condenser: condenser,
  4904. }
  4905. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4906. redis := service.RedisClient()
  4907. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4908. //清空key 值
  4909. redis.Set(key, "", time.Second)
  4910. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4911. //清空key 值
  4912. redis.Set(keyOne, "", time.Second)
  4913. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4914. redis.Set(keySeven, "", time.Second)
  4915. redis.Close()
  4916. if updateErr != nil {
  4917. c.ErrorLog("修改下机失败:%v", updateErr)
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4919. return
  4920. }
  4921. if updateErr == nil {
  4922. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4923. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4924. a, b := math.Modf(value)
  4925. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4926. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4927. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4928. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4929. redis := service.RedisClient()
  4930. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4931. redis.Set(keyTen, "", time.Second)
  4932. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4933. redis.Set(keyTwo, "", time.Second)
  4934. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4935. redis.Set(key, "", time.Second)
  4936. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4937. redis.Set(keyThree, "", time.Second)
  4938. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4939. redis.Set(keySeven, "", time.Second)
  4940. defer redis.Close()
  4941. if updateAssessmentErr != nil {
  4942. utils.ErrorLog("%v", updateAssessmentErr)
  4943. }
  4944. }
  4945. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4946. c.ServeSuccessJSON(map[string]interface{}{
  4947. "dialysis_order": dialysisRecords,
  4948. })
  4949. }
  4950. func (c *DialysisAPIController) GetLongAdvice() {
  4951. patient_id, _ := c.GetInt64("id")
  4952. adminUserInfo := c.GetMobileAdminUserInfo()
  4953. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4954. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4955. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4956. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4957. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4958. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4959. c.ServeSuccessJSON(map[string]interface{}{
  4960. "status": "1",
  4961. })
  4962. return
  4963. } else { //开启推送提醒
  4964. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4965. var advice_three []*models.DoctorAdvice
  4966. recordDateStr := time.Now().Format("2006-01-02")
  4967. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4968. nowtime := recordDate.Unix()
  4969. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4970. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4971. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4972. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4973. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4974. for _, advice := range advices {
  4975. if advice.FrequencyType == 3 {
  4976. t := time.Now()
  4977. week := int(t.Weekday())
  4978. fmt.Println(t.Weekday())
  4979. fmt.Println(week)
  4980. switch week {
  4981. case 1:
  4982. if strings.Index(advice.WeekDay, "周一") == -1 {
  4983. advice_three = append(advice_three, advice)
  4984. }
  4985. break
  4986. case 2:
  4987. if strings.Index(advice.WeekDay, "周二") == -1 {
  4988. advice_three = append(advice_three, advice)
  4989. }
  4990. break
  4991. case 3:
  4992. if strings.Index(advice.WeekDay, "周三") == -1 {
  4993. advice_three = append(advice_three, advice)
  4994. }
  4995. break
  4996. case 4:
  4997. if strings.Index(advice.WeekDay, "周四") == -1 {
  4998. advice_three = append(advice_three, advice)
  4999. }
  5000. break
  5001. case 5:
  5002. if strings.Index(advice.WeekDay, "周五") == -1 {
  5003. advice_three = append(advice_three, advice)
  5004. }
  5005. break
  5006. case 6:
  5007. if strings.Index(advice.WeekDay, "周六") == -1 {
  5008. advice_three = append(advice_three, advice)
  5009. }
  5010. break
  5011. case 0:
  5012. if strings.Index(advice.WeekDay, "周日") == -1 {
  5013. advice_three = append(advice_three, advice)
  5014. }
  5015. break
  5016. }
  5017. }
  5018. }
  5019. for _, advice := range advices_two {
  5020. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5021. now := p.Unix()
  5022. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5023. dayStr2 := "-" + dayStr
  5024. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5025. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5026. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5027. for _, ad := range advices {
  5028. advice_three = append(advice_three, ad)
  5029. }
  5030. }
  5031. if err == nil {
  5032. c.ServeSuccessJSON(map[string]interface{}{
  5033. "status": "2",
  5034. "advices": advices,
  5035. "advices_two": RemoveRepeatedElement(advice_three),
  5036. "is_open_remind": config.IsOpenRemind,
  5037. "his_config_open": hisConfig.IsOpen,
  5038. "is_advice_open": is_advice_open.IsAdviceOpen,
  5039. "prescription_open": prescription_open.IsOpen,
  5040. })
  5041. }
  5042. }
  5043. }
  5044. func (c *DialysisAPIController) GetLongAdviceOne() {
  5045. patient_id, _ := c.GetInt64("id")
  5046. startTime := c.GetString("schedule_date")
  5047. timeLayout := "2006-01-02"
  5048. loc, _ := time.LoadLocation("Local")
  5049. var theStartTime int64
  5050. if len(startTime) > 0 {
  5051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5052. if err != nil {
  5053. utils.ErrorLog(err.Error())
  5054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5055. return
  5056. }
  5057. theStartTime = theTime.Unix()
  5058. }
  5059. adminUserInfo := c.GetMobileAdminUserInfo()
  5060. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5061. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5062. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5063. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5064. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5065. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5066. c.ServeSuccessJSON(map[string]interface{}{
  5067. "status": "1",
  5068. })
  5069. return
  5070. } else { //开启推送提醒
  5071. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5072. var advice_three []*models.DoctorAdvice
  5073. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5074. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5075. for _, advice := range advices {
  5076. if advice.FrequencyType == 3 {
  5077. t := time.Now()
  5078. week := int(t.Weekday())
  5079. fmt.Println(t.Weekday())
  5080. fmt.Println(week)
  5081. switch week {
  5082. case 1:
  5083. if strings.Index(advice.WeekDay, "周一") == -1 {
  5084. advice_three = append(advice_three, advice)
  5085. }
  5086. break
  5087. case 2:
  5088. if strings.Index(advice.WeekDay, "周二") == -1 {
  5089. advice_three = append(advice_three, advice)
  5090. }
  5091. break
  5092. case 3:
  5093. if strings.Index(advice.WeekDay, "周三") == -1 {
  5094. advice_three = append(advice_three, advice)
  5095. }
  5096. break
  5097. case 4:
  5098. if strings.Index(advice.WeekDay, "周四") == -1 {
  5099. advice_three = append(advice_three, advice)
  5100. }
  5101. break
  5102. case 5:
  5103. if strings.Index(advice.WeekDay, "周五") == -1 {
  5104. advice_three = append(advice_three, advice)
  5105. }
  5106. break
  5107. case 6:
  5108. if strings.Index(advice.WeekDay, "周六") == -1 {
  5109. advice_three = append(advice_three, advice)
  5110. }
  5111. break
  5112. case 0:
  5113. if strings.Index(advice.WeekDay, "周日") == -1 {
  5114. advice_three = append(advice_three, advice)
  5115. }
  5116. break
  5117. }
  5118. }
  5119. }
  5120. for _, advice := range advices_two {
  5121. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5122. now := p.Unix()
  5123. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5124. dayStr2 := "-" + dayStr
  5125. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5126. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5127. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5128. for _, ad := range advices {
  5129. advice_three = append(advice_three, ad)
  5130. }
  5131. }
  5132. if err == nil {
  5133. c.ServeSuccessJSON(map[string]interface{}{
  5134. "status": "2",
  5135. "advices": advices,
  5136. "advices_two": RemoveRepeatedElement(advice_three),
  5137. "is_open_remind": config.IsOpenRemind,
  5138. "his_config_open": hisConfig.IsOpen,
  5139. "is_advice_open": is_advice_open.IsAdviceOpen,
  5140. "prescription_open": prescription_open.IsOpen,
  5141. })
  5142. }
  5143. }
  5144. }
  5145. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5146. newArr = make([]*models.DoctorAdvice, 0)
  5147. for i := 0; i < len(arr); i++ {
  5148. repeat := false
  5149. for j := i + 1; j < len(arr); j++ {
  5150. if arr[i].ID == arr[j].ID {
  5151. repeat = true
  5152. break
  5153. }
  5154. }
  5155. if !repeat {
  5156. newArr = append(newArr, arr[i])
  5157. }
  5158. }
  5159. return
  5160. }
  5161. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5162. patient, _ := c.GetInt64("id", 0)
  5163. groupNo, _ := c.GetInt64("groupno", 0)
  5164. if patient <= 0 {
  5165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5166. return
  5167. }
  5168. adminUserInfo := c.GetMobileAdminUserInfo()
  5169. dataBody := make(map[string]interface{}, 0)
  5170. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5171. if err != nil {
  5172. utils.ErrorLog(err.Error())
  5173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5174. return
  5175. }
  5176. utils.ErrorLog("%v", dataBody)
  5177. timeLayout := "2006-01-02 15:04"
  5178. loc, _ := time.LoadLocation("Local")
  5179. timeLayout2 := "2006-01-02"
  5180. loc2, _ := time.LoadLocation("Local")
  5181. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5182. utils.ErrorLog("advice_type")
  5183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5184. return
  5185. }
  5186. adviceType := int64(2)
  5187. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5188. utils.ErrorLog("advice_date")
  5189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5190. return
  5191. }
  5192. adviceDate, _ := dataBody["advice_date"].(string)
  5193. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5194. AdviceDate := theTime.Unix()
  5195. RecordDate := theTime.Unix()
  5196. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5197. utils.ErrorLog("start_time")
  5198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5199. return
  5200. }
  5201. startTime, _ := dataBody["start_time"].(string)
  5202. if len(startTime) == 0 {
  5203. utils.ErrorLog("len(start_time) == 0")
  5204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5205. return
  5206. }
  5207. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5208. if err != nil {
  5209. utils.ErrorLog(err.Error())
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5211. return
  5212. }
  5213. StartTime := theTime.Unix()
  5214. Remark := ""
  5215. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5216. remark, _ := dataBody["remark"].(string)
  5217. Remark = remark
  5218. }
  5219. var advices []*models.GroupAdvice
  5220. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5221. utils.ErrorLog("advices")
  5222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5223. return
  5224. }
  5225. adviceNames := dataBody["advices"].([]interface{})
  5226. for _, adviceNameMap := range adviceNames {
  5227. adviceNameM := adviceNameMap.(map[string]interface{})
  5228. var advice models.GroupAdvice
  5229. advice.Remark = Remark
  5230. advice.AdviceType = adviceType
  5231. advice.StartTime = StartTime
  5232. advice.AdviceDate = AdviceDate
  5233. advice.RecordDate = RecordDate
  5234. advice.Status = 1
  5235. advice.CreatedTime = time.Now().Unix()
  5236. advice.UpdatedTime = time.Now().Unix()
  5237. advice.StopState = 2
  5238. advice.ExecutionState = 2
  5239. advice.UserOrgId = adminUserInfo.Org.Id
  5240. advice.PatientId = patient
  5241. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5242. advice.IsSettle = 2
  5243. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5244. utils.ErrorLog("advice_name")
  5245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5246. return
  5247. }
  5248. adviceName, _ := adviceNameM["advice_name"].(string)
  5249. if len(adviceName) == 0 {
  5250. utils.ErrorLog("len(advice_name) == 0")
  5251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5252. return
  5253. }
  5254. advice.AdviceName = adviceName
  5255. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5256. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5257. advice.DrugSpec = drugSpec
  5258. }
  5259. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5260. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5261. advice.AdviceDesc = adviceDesc
  5262. }
  5263. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5264. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5265. advice.DrugSpecUnit = drugSpecUnit
  5266. }
  5267. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5268. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5269. // advice.SingleDose = singleDose
  5270. //}
  5271. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5272. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5273. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5274. }
  5275. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5276. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5277. advice.SingleDoseUnit = singleDoseUnit
  5278. }
  5279. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5280. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5281. // advice.PrescribingNumber = prescribingNumber
  5282. //}
  5283. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5284. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5285. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5286. }
  5287. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5288. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5289. advice.PrescribingNumberUnit = prescribingNumberUnit
  5290. }
  5291. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5292. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5293. advice.DeliveryWay = deliveryWay
  5294. }
  5295. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5296. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5297. advice.ExecutionFrequency = executionFrequency
  5298. }
  5299. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5300. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5301. advice.FrequencyType = frequency_type
  5302. }
  5303. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5304. day_count := int64(adviceNameM["day_count"].(float64))
  5305. advice.DayCount = day_count
  5306. }
  5307. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5308. week_day, _ := adviceNameM["week_day"].(string)
  5309. advice.WeekDay = week_day
  5310. }
  5311. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5312. way := int64(adviceNameM["way"].(float64))
  5313. advice.Way = way
  5314. }
  5315. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5316. drug_id := int64(adviceNameM["drug_id"].(float64))
  5317. advice.DrugId = drug_id
  5318. }
  5319. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5320. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5321. advice.DrugNameId = drug_name_id
  5322. }
  5323. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5324. remark, _ := adviceNameM["remark"].(string)
  5325. advice.Remark = remark
  5326. }
  5327. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5328. groupno := int64(adviceNameM["groupno"].(float64))
  5329. advice.GroupNo = groupno
  5330. }
  5331. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5332. template_id, _ := adviceNameM["template_id"].(string)
  5333. advice.TemplateId = template_id
  5334. }
  5335. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5336. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5337. advice.ExecutionFrequency = executionFrequency
  5338. }
  5339. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5340. children := adviceNameM["child"].([]interface{})
  5341. if len(children) > 0 {
  5342. for _, childrenMap := range children {
  5343. childMap := childrenMap.(map[string]interface{})
  5344. var child models.GroupAdvice
  5345. child.Remark = Remark
  5346. child.AdviceType = adviceType
  5347. child.StartTime = StartTime
  5348. child.AdviceDate = AdviceDate
  5349. child.RecordDate = RecordDate
  5350. child.Status = 1
  5351. child.CreatedTime = time.Now().Unix()
  5352. child.UpdatedTime = time.Now().Unix()
  5353. child.StopState = 2
  5354. child.ExecutionState = 2
  5355. child.UserOrgId = adminUserInfo.Org.Id
  5356. child.PatientId = patient
  5357. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5358. child.IsSettle = 1
  5359. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5360. utils.ErrorLog("child advice_name")
  5361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5362. return
  5363. }
  5364. childAdviceName, _ := childMap["advice_name"].(string)
  5365. if len(childAdviceName) == 0 {
  5366. utils.ErrorLog("len(child advice_name) == 0")
  5367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5368. return
  5369. }
  5370. child.AdviceName = childAdviceName
  5371. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5372. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5373. child.AdviceDesc = childAdviceDesc
  5374. }
  5375. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5376. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5377. child.DrugSpec = childDrugSpec
  5378. }
  5379. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5380. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5381. child.DrugSpecUnit = childDrugSpecUnit
  5382. }
  5383. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5384. child.SingleDose = childMap["single_dose"].(float64)
  5385. }
  5386. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5387. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5388. child.SingleDoseUnit = childSingleDoseUnit
  5389. }
  5390. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5391. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5392. }
  5393. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5394. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5395. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5396. }
  5397. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5398. groupno := int64(childMap["groupno"].(float64))
  5399. advice.GroupNo = groupno
  5400. }
  5401. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5402. remark, _ := childMap["remark"].(string)
  5403. child.Remark = remark
  5404. }
  5405. child.DeliveryWay = advice.DeliveryWay
  5406. child.ExecutionFrequency = advice.ExecutionFrequency
  5407. advice.Children = append(advice.Children, &child)
  5408. }
  5409. }
  5410. }
  5411. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5412. if temp_advice.ID == 0 {
  5413. advices = append(advices, &advice)
  5414. }
  5415. }
  5416. if len(advices) > 0 {
  5417. finish := models.XtDialysisFinish{
  5418. IsFinish: 1,
  5419. UserOrgId: adminUserInfo.Org.Id,
  5420. Status: 1,
  5421. Ctime: time.Now().Unix(),
  5422. Mtime: 0,
  5423. Module: 4,
  5424. RecordDate: AdviceDate,
  5425. Sourse: 1,
  5426. PatientId: patient,
  5427. }
  5428. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5429. if dialysisFinish.ID == 0 {
  5430. service.CreateDialysisFinish(finish)
  5431. }
  5432. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5433. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5434. for _, item := range advices {
  5435. byterequest, _ := json.Marshal(item)
  5436. adviceLog := models.XtDoctorAdviceLog{
  5437. UserOrgId: adminUserInfo.Org.Id,
  5438. PatientId: patient,
  5439. AdminUserId: adminUserInfo.AdminUser.Id,
  5440. Module: 1,
  5441. ErrLog: string(byterequest),
  5442. Status: 1,
  5443. Ctime: time.Now().Unix(),
  5444. Mtime: 0,
  5445. Source: "手机端医嘱推送",
  5446. RecordDate: item.AdviceDate,
  5447. }
  5448. service.CreateDoctorAdviceLog(adviceLog)
  5449. }
  5450. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5451. redis := service.RedisClient()
  5452. //清空key 值
  5453. redis.Set(key, "", time.Second)
  5454. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5455. redis.Set(keyOne, "", time.Second)
  5456. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5457. defer redis.Close()
  5458. redis.Set(keyThree, "", time.Second)
  5459. if err != nil {
  5460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5461. return
  5462. }
  5463. c.ServeSuccessJSON(map[string]interface{}{
  5464. "msg": "ok",
  5465. "advices": list,
  5466. })
  5467. } else {
  5468. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5469. for _, item := range advices {
  5470. byterequest, _ := json.Marshal(item)
  5471. adviceLog := models.XtDoctorAdviceLog{
  5472. UserOrgId: adminUserInfo.Org.Id,
  5473. PatientId: patient,
  5474. AdminUserId: adminUserInfo.AdminUser.Id,
  5475. Module: 1,
  5476. ErrLog: string(byterequest),
  5477. Status: 1,
  5478. Ctime: time.Now().Unix(),
  5479. Mtime: 0,
  5480. Source: "手机端医嘱推送",
  5481. RecordDate: item.AdviceDate,
  5482. }
  5483. service.CreateDoctorAdviceLog(adviceLog)
  5484. }
  5485. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5486. redis := service.RedisClient()
  5487. //清空key 值
  5488. redis.Set(key, "", time.Second)
  5489. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5490. redis.Set(keyOne, "", time.Second)
  5491. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5492. defer redis.Close()
  5493. redis.Set(keyThree, "", time.Second)
  5494. if err != nil {
  5495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5496. return
  5497. }
  5498. c.ServeSuccessJSON(map[string]interface{}{
  5499. "msg": "ok",
  5500. "advices": list,
  5501. })
  5502. }
  5503. } else {
  5504. c.ServeSuccessJSON(map[string]interface{}{
  5505. "msg": "ok",
  5506. })
  5507. }
  5508. return
  5509. }
  5510. func (c *DialysisAPIController) UploadDryWeight() {
  5511. patient_id, _ := c.GetInt64("id")
  5512. dry_weight, _ := c.GetFloat("dry_weight")
  5513. doctor_id, _ := c.GetInt64("doctor_id")
  5514. remark := c.GetString("remark")
  5515. adminUserInfo := c.GetMobileAdminUserInfo()
  5516. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5517. if err == gorm.ErrRecordNotFound {
  5518. dryWeight := &models.SgjPatientDryweight{
  5519. PatientId: patient_id,
  5520. DryWeight: dry_weight,
  5521. Remakes: remark,
  5522. Ctime: time.Now().Unix(),
  5523. Mtime: time.Now().Unix(),
  5524. Creator: doctor_id,
  5525. Status: 1,
  5526. UserOrgId: adminUserInfo.Org.Id,
  5527. AdjustedValue: "/",
  5528. UserId: adminUserInfo.AdminUser.Id,
  5529. }
  5530. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5531. redis := service.RedisClient()
  5532. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5533. redis.Set(keyOne, "", time.Second)
  5534. loc, _ := time.LoadLocation("Local")
  5535. nowTime := time.Now()
  5536. nowDay := nowTime.Format("2006-01-02")
  5537. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5539. redis.Set(key, "", time.Second)
  5540. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5541. redis.Set(keyTwo, "", time.Second)
  5542. redis.Close()
  5543. if createErr == nil {
  5544. c.ServeSuccessJSON(map[string]interface{}{
  5545. "msg": "提交成功",
  5546. "weight": dryWeight,
  5547. })
  5548. }
  5549. } else {
  5550. dryWeight := &models.SgjPatientDryweight{
  5551. PatientId: patient_id,
  5552. DryWeight: dry_weight,
  5553. Remakes: remark,
  5554. Ctime: time.Now().Unix(),
  5555. Mtime: time.Now().Unix(),
  5556. Creator: doctor_id,
  5557. Status: 1,
  5558. UserOrgId: adminUserInfo.Org.Id,
  5559. AdjustedValue: "/",
  5560. UserId: adminUserInfo.AdminUser.Id,
  5561. }
  5562. var value float64
  5563. value = dry_weight - weightAdjust.DryWeight
  5564. if value < 0 {
  5565. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5566. } else if value == 0 {
  5567. dryWeight.AdjustedValue = "/"
  5568. } else if value > 0 {
  5569. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5570. }
  5571. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5572. //康桥
  5573. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5574. timeNowStr := time.Now().Format("2006-01-02")
  5575. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5576. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5577. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5578. if beforAssesment.ID > 0 {
  5579. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5580. var dewater_amount float64
  5581. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5582. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5583. //获取key,清空redis
  5584. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5585. redis := service.RedisClient()
  5586. //清空key 值
  5587. redis.Set(key, "", time.Second)
  5588. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5589. //清空key 值
  5590. redis.Set(keyOne, "", time.Second)
  5591. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5592. //清空key 值
  5593. redis.Set(keyTwo, "", time.Second)
  5594. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5595. redis.Set(keySix, "", time.Second)
  5596. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5597. redis.Set(keySeven, "", time.Second)
  5598. }
  5599. }
  5600. redis := service.RedisClient()
  5601. loc, _ := time.LoadLocation("Local")
  5602. nowTime := time.Now()
  5603. nowDay := nowTime.Format("2006-01-02")
  5604. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5605. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5606. redis.Set(keyOne, "", time.Second)
  5607. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5608. redis.Set(key, "", time.Second)
  5609. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5610. redis.Set(keyTwo, "", time.Second)
  5611. redis.Close()
  5612. if createErr == nil {
  5613. c.ServeSuccessJSON(map[string]interface{}{
  5614. "msg": "提交成功",
  5615. "weight": dryWeight,
  5616. })
  5617. }
  5618. }
  5619. }
  5620. func (c *DialysisAPIController) GetSolution() {
  5621. patient_id, _ := c.GetInt64("patient_id")
  5622. mode_id, _ := c.GetInt64("mode_id")
  5623. adminUserInfo := c.GetMobileAdminUserInfo()
  5624. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5625. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5626. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5627. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5628. if err != nil {
  5629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5630. return
  5631. }
  5632. c.ServeSuccessJSON(map[string]interface{}{
  5633. "solution": solution,
  5634. "prescription": prescription,
  5635. "system_prescription": system_prescription,
  5636. "dialysisPrescription": dialysisPrescription,
  5637. })
  5638. }
  5639. func (c *DialysisAPIController) GetSchedule() {
  5640. schedual_type, _ := c.GetInt64("schedual_type")
  5641. adminUserInfo := c.GetMobileAdminUserInfo()
  5642. scheduleTime, _ := c.GetInt64("record_date")
  5643. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5644. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5645. c.ServeSuccessJSON(map[string]interface{}{
  5646. "number": deviceNumber,
  5647. "list": list,
  5648. })
  5649. }
  5650. func (c *DialysisAPIController) GetPatientId() {
  5651. id, _ := c.GetInt64("id")
  5652. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5653. patientId, _ := service.GetPatientId(id)
  5654. //获取该患者的所有传染病
  5655. list, _ := service.GetPatientInfectious(id)
  5656. c.ServeSuccessJSON(map[string]interface{}{
  5657. "patient": patientId,
  5658. "infectioulist": list,
  5659. })
  5660. }
  5661. func (this *DialysisAPIController) GetDialysisSchedule() {
  5662. schedualDate := this.GetString("date")
  5663. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5664. if parseDateErr != nil {
  5665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. return
  5667. }
  5668. adminInfo := this.GetMobileAdminUserInfo()
  5669. orgID := adminInfo.Org.Id
  5670. redis := service.RedisClient()
  5671. defer redis.Close()
  5672. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5673. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5674. if len(scheduals) > 0 {
  5675. //缓存数据
  5676. scheduals_json, err := json.Marshal(scheduals)
  5677. if err == nil {
  5678. redis.Set(key, scheduals_json, time.Second*30)
  5679. }
  5680. }
  5681. this.ServeSuccessJSON(map[string]interface{}{
  5682. "scheduals": scheduals,
  5683. })
  5684. }
  5685. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5686. change_type, _ := this.GetInt64("type", 0)
  5687. record_date := this.GetString("record_time")
  5688. patient_id, _ := this.GetInt64("patient_id", 0)
  5689. timeLayout := "2006-01-02"
  5690. loc, _ := time.LoadLocation("Local")
  5691. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5692. record_time := theAdviceRecordTime.Unix()
  5693. adminUserInfo := this.GetMobileAdminUserInfo()
  5694. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5695. if err == nil {
  5696. if len(advices) == 0 {
  5697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5698. return
  5699. } else {
  5700. this.ServeSuccessJSON(map[string]interface{}{
  5701. "advices": advices,
  5702. "schedule": sch,
  5703. })
  5704. return
  5705. }
  5706. } else {
  5707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5708. return
  5709. }
  5710. }
  5711. func (c *DialysisAPIController) CreateConsumables() {
  5712. record_date := c.GetString("record_time")
  5713. patient_id, _ := c.GetInt64("patient_id", 0)
  5714. active, _ := c.GetInt64("active")
  5715. adminUser := c.GetMobileAdminUserInfo()
  5716. timeLayout := "2006-01-02"
  5717. loc, _ := time.LoadLocation("Local")
  5718. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5719. record_time := theRecordTime.Unix()
  5720. // 查询信息规挡的设置天数
  5721. orgid := c.GetMobileAdminUserInfo().Org.Id
  5722. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5723. if infor.ID > 0 {
  5724. var cha_time int64
  5725. timeNowStr := time.Now().Format("2006-01-02")
  5726. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5727. //今日的日期减去设置的日期
  5728. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5729. if cha_time >= record_time {
  5730. //查询审核是否允许
  5731. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5732. //申请状态不允许的情况 拒绝修改
  5733. if infor.ApplicationStatus != 1 {
  5734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5735. return
  5736. }
  5737. }
  5738. }
  5739. dataBody := make(map[string]interface{}, 0)
  5740. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5741. if err != nil {
  5742. utils.ErrorLog(err.Error())
  5743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5744. return
  5745. }
  5746. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5747. var beforePrepares []*models.DialysisBeforePrepareGoods
  5748. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5749. var dialysisBefor []*models.DialysisBeforePrepare
  5750. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5751. goods, _ := dataBody["goods"].([]interface{})
  5752. if len(goods) > 0 {
  5753. for _, item := range goods {
  5754. items := item.(map[string]interface{})
  5755. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5756. utils.ErrorLog("good_id")
  5757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5758. return
  5759. }
  5760. good_id := int64(items["good_id"].(float64))
  5761. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5762. utils.ErrorLog("good_type_id")
  5763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5764. return
  5765. }
  5766. good_type_id := int64(items["good_type_id"].(float64))
  5767. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5768. utils.ErrorLog("count")
  5769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5770. return
  5771. }
  5772. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5773. commdity_code := items["commdity_code"].(string)
  5774. fmt.Println("commdity", commdity_code)
  5775. prepareGoods := &models.DialysisBeforePrepareGoods{
  5776. GoodTypeId: good_type_id,
  5777. GoodId: good_id,
  5778. Count: count,
  5779. StorehouseId: houseConfig.StorehouseOutInfo,
  5780. }
  5781. beforePrepares = append(beforePrepares, prepareGoods)
  5782. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5783. GoodTypeId: good_type_id,
  5784. GoodId: good_id,
  5785. Count: count,
  5786. StorehouseId: houseConfig.StorehouseOutInfo,
  5787. }
  5788. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5789. prepare := &models.DialysisBeforePrepare{
  5790. GoodTypeId: good_type_id,
  5791. GoodId: good_id,
  5792. Count: count,
  5793. PatientId: patient_id,
  5794. RecordDate: record_time,
  5795. UserOrgId: adminUser.Org.Id,
  5796. Status: 1,
  5797. Ctime: time.Now().Unix(),
  5798. Creater: adminUser.AdminUser.Id,
  5799. CommdityCode: commdity_code,
  5800. StorehouseId: houseConfig.StorehouseOutInfo,
  5801. }
  5802. dialysisBefor = append(dialysisBefor, prepare)
  5803. }
  5804. }
  5805. //查询是否有库存
  5806. for _, item := range dialysisBefor {
  5807. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5808. if err == gorm.ErrRecordNotFound {
  5809. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5810. c.ServeSuccessJSON(map[string]interface{}{
  5811. "message": "1",
  5812. "good_name": goodObj.GoodName,
  5813. "specification_name": goodObj.SpecificationName,
  5814. })
  5815. return
  5816. }
  5817. if err != nil {
  5818. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5819. c.ServeSuccessJSON(map[string]interface{}{
  5820. "message": "1",
  5821. "good_name": goodObj.GoodName,
  5822. "specification_name": goodObj.SpecificationName,
  5823. })
  5824. return
  5825. }
  5826. }
  5827. fmt.Println("active-----------------------", active)
  5828. fmt.Println("len(goods)-----------------------", len(goods))
  5829. //新增
  5830. if active == 1 && len(goods) > 0 {
  5831. for _, item := range dialysisBefor {
  5832. dialyPrepareOne := models.DialysisBeforePrepare{
  5833. GoodTypeId: item.GoodTypeId,
  5834. GoodId: item.GoodId,
  5835. PatientId: item.PatientId,
  5836. RecordDate: item.RecordDate,
  5837. UserOrgId: item.UserOrgId,
  5838. Count: item.Count,
  5839. Ctime: time.Now().Unix(),
  5840. Creater: item.Creater,
  5841. CommdityCode: item.CommdityCode,
  5842. Status: 1,
  5843. StorehouseId: houseConfig.StorehouseOutInfo,
  5844. }
  5845. //先清除再插入
  5846. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5847. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5848. //查询默认仓库
  5849. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5850. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5851. var total_count int64
  5852. for _, it := range stockList {
  5853. total_count += it.StockCount
  5854. }
  5855. //基础库插入数据
  5856. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5857. //更新库存
  5858. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5859. var flush_count int64
  5860. for _, it := range goodList {
  5861. flush_count += it.StockCount
  5862. }
  5863. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5864. }
  5865. if err == nil {
  5866. c.ServeSuccessJSON(map[string]interface{}{
  5867. "msg": "保存成功",
  5868. "message": "2",
  5869. })
  5870. return
  5871. } else {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5873. return
  5874. }
  5875. }
  5876. if len(beforePrepares) > 0 && active == 2 {
  5877. for _, item := range beforePrepares {
  5878. //1.查看该患者该耗材型号最后一次出库数量
  5879. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5880. //判断当前出库数量和最后一次出库数量的大小
  5881. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5882. if item.Count <= goodInfo.Count {
  5883. //退库
  5884. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5885. //查询今日出库数据
  5886. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5887. for _, it := range list {
  5888. prepare := models.DialysisBeforePrepare{
  5889. UserOrgId: it.OrgId,
  5890. PatientId: patient_id,
  5891. RecordDate: it.RecordTime,
  5892. GoodId: it.GoodId,
  5893. GoodTypeId: it.GoodTypeId,
  5894. Count: it.Count,
  5895. Ctime: time.Now().Unix(),
  5896. Creater: adminUser.AdminUser.Id,
  5897. Status: 1,
  5898. StorehouseId: houseConfig.StorehouseOutInfo,
  5899. }
  5900. //删除准备表数据
  5901. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5902. service.CreateDialysisBeforePrepareOne(&prepare)
  5903. }
  5904. }
  5905. var last_total int64
  5906. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5907. if item.Count >= goodInfo.Count {
  5908. //查询当前批次当前耗材最后一条出库数据
  5909. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5910. //计算当前出库和最后一次出库数据相差数据
  5911. last_total = item.Count - lastOutInfo.Count
  5912. //查询该批次剩余库存
  5913. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5914. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5915. if lastInfo.StockCount >= last_total {
  5916. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5917. //查询今日出库数据
  5918. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5919. for _, it := range list {
  5920. prepare := models.DialysisBeforePrepare{
  5921. UserOrgId: it.OrgId,
  5922. PatientId: patient_id,
  5923. RecordDate: it.RecordTime,
  5924. GoodId: it.GoodId,
  5925. GoodTypeId: it.GoodTypeId,
  5926. Count: it.Count,
  5927. Ctime: time.Now().Unix(),
  5928. Creater: adminUser.AdminUser.Id,
  5929. Status: 1,
  5930. StorehouseId: houseConfig.StorehouseOutInfo,
  5931. }
  5932. //删除准备表数据
  5933. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5934. service.CreateDialysisBeforePrepareOne(&prepare)
  5935. //查询默认仓库
  5936. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5937. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5938. var total_count int64
  5939. for _, it := range stockList {
  5940. total_count += it.StockCount
  5941. }
  5942. //基础库插入数据
  5943. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5944. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5945. var flush_count int64
  5946. for _, it := range goodList {
  5947. flush_count += it.StockCount
  5948. }
  5949. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5950. }
  5951. }
  5952. //如果库存不够,则出库到下一个批次
  5953. if lastInfo.StockCount < last_total {
  5954. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5955. //查询今日出库数据
  5956. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5957. for _, it := range list {
  5958. prepare := models.DialysisBeforePrepare{
  5959. UserOrgId: it.OrgId,
  5960. PatientId: patient_id,
  5961. RecordDate: it.RecordTime,
  5962. GoodId: it.GoodId,
  5963. GoodTypeId: it.GoodTypeId,
  5964. Count: it.Count,
  5965. Ctime: time.Now().Unix(),
  5966. Creater: adminUser.AdminUser.Id,
  5967. Status: 1,
  5968. StorehouseId: houseConfig.StorehouseOutInfo,
  5969. }
  5970. //删除准备表数据
  5971. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5972. service.CreateDialysisBeforePrepareOne(&prepare)
  5973. //查询默认仓库
  5974. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5975. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5976. var total_count int64
  5977. for _, it := range stockList {
  5978. total_count += it.StockCount
  5979. }
  5980. //基础库插入数据
  5981. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5982. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5983. var flush_count int64
  5984. for _, it := range goodList {
  5985. flush_count += it.StockCount
  5986. }
  5987. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5988. }
  5989. if err != nil {
  5990. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5991. c.ServeSuccessJSON(map[string]interface{}{
  5992. "message": "1",
  5993. "good_name": goodObj.GoodName,
  5994. "specification_name": goodObj.SpecificationName,
  5995. })
  5996. return
  5997. }
  5998. }
  5999. }
  6000. if err != nil {
  6001. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6002. c.ServeSuccessJSON(map[string]interface{}{
  6003. "message": "1",
  6004. "good_name": goodObj.GoodName,
  6005. "specification_name": goodObj.SpecificationName,
  6006. })
  6007. return
  6008. }
  6009. }
  6010. }
  6011. }
  6012. var errs error
  6013. if errs == nil {
  6014. c.ServeSuccessJSON(map[string]interface{}{
  6015. "msg": "提交成功",
  6016. "message": "2",
  6017. "good_name": "",
  6018. "specification_name": "",
  6019. })
  6020. return
  6021. } else {
  6022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6023. return
  6024. }
  6025. }
  6026. func (c *DialysisAPIController) CreateStockOutInfo() {
  6027. patient_id, _ := c.GetInt64("patient_id", 0)
  6028. record_date := c.GetString("record_time")
  6029. if patient_id <= 0 {
  6030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6031. return
  6032. }
  6033. adminInfo := c.GetMobileAdminUserInfo()
  6034. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6035. timeLayout := "2006-01-02"
  6036. loc, _ := time.LoadLocation("Local")
  6037. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6038. record_time := theRecordTime.Unix()
  6039. // 查询信息规挡的设置天数
  6040. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6041. if infor.ID > 0 && infor.WeekDay > 0 {
  6042. var cha_time int64
  6043. timeNowStr := time.Now().Format("2006-01-02")
  6044. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6045. //今日的日期减去设置的日期
  6046. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6047. if cha_time >= record_time {
  6048. //查询审核是否允许
  6049. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6050. //申请状态不允许的情况 拒绝修改
  6051. if infor.ApplicationStatus != 1 {
  6052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6053. return
  6054. }
  6055. }
  6056. }
  6057. //创建步骤表
  6058. finish := models.XtDialysisFinish{
  6059. IsFinish: 1,
  6060. UserOrgId: adminInfo.Org.Id,
  6061. Status: 1,
  6062. Ctime: time.Now().Unix(),
  6063. Mtime: 0,
  6064. Module: 11,
  6065. RecordDate: record_time,
  6066. Sourse: 1,
  6067. PatientId: patient_id,
  6068. }
  6069. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6070. if dialysisFinish.ID == 0 {
  6071. service.CreateDialysisFinish(finish)
  6072. }
  6073. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6074. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6075. //去重
  6076. consumables = RemoveRepeatedGood(consumables)
  6077. if adminInfo.Org.Id == 9919 {
  6078. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6079. //查询是否有库存
  6080. for _, item := range consumables {
  6081. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6082. if item.Count > warehouse.Count {
  6083. goodErrcode := models.XtGoodErrcode{
  6084. UserOrgId: item.UserOrgId,
  6085. Errcode: "自动出库库存不足",
  6086. GoodId: item.GoodId,
  6087. Status: 1,
  6088. Ctime: time.Now().Unix(),
  6089. Mtime: 0,
  6090. Count: 0,
  6091. StockCount: 0,
  6092. Creater: creator,
  6093. BatchNumberId: warehouse.ID,
  6094. WarehouseOutId: 0,
  6095. }
  6096. service.CreateGoodErrcode(goodErrcode)
  6097. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6098. c.ServeSuccessJSON(map[string]interface{}{
  6099. "message": "1",
  6100. "good_name": goodObj.GoodName,
  6101. "specification_name": goodObj.SpecificationName,
  6102. })
  6103. return
  6104. }
  6105. }
  6106. //查询是否有出库单
  6107. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6108. if err == gorm.ErrRecordNotFound {
  6109. //没有记录,则创建出库单
  6110. timeStr := time.Now().Format("2006-01-02")
  6111. timeArr := strings.Split(timeStr, "-")
  6112. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6113. total = total + 1
  6114. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6115. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6116. number = number + total
  6117. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6118. creater := adminInfo.AdminUser.Id
  6119. warehouseOut := models.WarehouseOut{
  6120. WarehouseOutOrderNumber: warehousing_out_order,
  6121. OperationTime: time.Now().Unix(),
  6122. OrgId: adminInfo.Org.Id,
  6123. Creater: creater,
  6124. Ctime: time.Now().Unix(),
  6125. Status: 1,
  6126. WarehouseOutTime: record_time,
  6127. Dealer: 0,
  6128. Manufacturer: 0,
  6129. Type: 1,
  6130. IsSys: 1,
  6131. StorehouseId: houseConfig.StorehouseOutInfo,
  6132. IsCheck: 1,
  6133. }
  6134. err := service.AddSigleWarehouseOut(&warehouseOut)
  6135. if err != nil {
  6136. goodErrcode := models.XtGoodErrcode{
  6137. UserOrgId: adminInfo.Org.Id,
  6138. Errcode: "创建出库单失败",
  6139. GoodId: 0,
  6140. Status: 1,
  6141. Ctime: time.Now().Unix(),
  6142. Mtime: 0,
  6143. Count: 0,
  6144. StockCount: 0,
  6145. Creater: creator,
  6146. BatchNumberId: 0,
  6147. WarehouseOutId: 0,
  6148. }
  6149. service.CreateGoodErrcode(goodErrcode)
  6150. utils.TraceLog("创建出库单失败 err = %v", err)
  6151. } else {
  6152. for _, item := range consumables {
  6153. //出库
  6154. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6155. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6156. if err == nil {
  6157. goodErrcode := models.XtGoodErrcode{
  6158. UserOrgId: adminInfo.Org.Id,
  6159. Errcode: "自动出库接口报错",
  6160. GoodId: 0,
  6161. Status: 1,
  6162. Ctime: time.Now().Unix(),
  6163. Mtime: 0,
  6164. Count: 0,
  6165. StockCount: 0,
  6166. Creater: creator,
  6167. BatchNumberId: 0,
  6168. WarehouseOutId: 0,
  6169. }
  6170. service.CreateGoodErrcode(goodErrcode)
  6171. utils.TraceLog("创建出库单失败 err = %v", err)
  6172. }
  6173. //查询
  6174. //出库数量相加
  6175. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6176. if errs != nil {
  6177. goodErrcode := models.XtGoodErrcode{
  6178. UserOrgId: item.UserOrgId,
  6179. Errcode: "创建剩余库存字段报错",
  6180. GoodId: item.GoodId,
  6181. Status: 1,
  6182. Ctime: time.Now().Unix(),
  6183. Mtime: 0,
  6184. Count: 0,
  6185. StockCount: 0,
  6186. Creater: creater,
  6187. BatchNumberId: 0,
  6188. WarehouseOutId: 0,
  6189. }
  6190. service.CreateGoodErrcode(goodErrcode)
  6191. }
  6192. }
  6193. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6194. if len(list) == 0 {
  6195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6196. return
  6197. }
  6198. for _, item := range list {
  6199. prepare := models.DialysisBeforePrepare{
  6200. UserOrgId: adminInfo.Org.Id,
  6201. PatientId: patient_id,
  6202. RecordDate: record_time,
  6203. GoodId: item.GoodId,
  6204. GoodTypeId: item.GoodTypeId,
  6205. Count: item.Count,
  6206. Creater: adminInfo.AdminUser.Id,
  6207. Status: 1,
  6208. Ctime: time.Now().Unix(),
  6209. StorehouseId: houseConfig.StorehouseOutInfo,
  6210. }
  6211. //清空准备表数据
  6212. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6213. if err != nil {
  6214. goodErrcode := models.XtGoodErrcode{
  6215. UserOrgId: item.OrgId,
  6216. Errcode: "自动出库清空准备表数据报错",
  6217. GoodId: item.GoodId,
  6218. Status: 1,
  6219. Ctime: time.Now().Unix(),
  6220. Mtime: 0,
  6221. Count: 0,
  6222. StockCount: 0,
  6223. Creater: creater,
  6224. BatchNumberId: 0,
  6225. WarehouseOutId: 0,
  6226. }
  6227. service.CreateGoodErrcode(goodErrcode)
  6228. }
  6229. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6230. if errs != nil {
  6231. goodErrcode := models.XtGoodErrcode{
  6232. UserOrgId: item.OrgId,
  6233. Errcode: "自动出库创建准备表数据报错",
  6234. GoodId: item.GoodId,
  6235. Status: 1,
  6236. Ctime: time.Now().Unix(),
  6237. Mtime: 0,
  6238. Count: 0,
  6239. StockCount: 0,
  6240. Creater: creater,
  6241. BatchNumberId: 0,
  6242. WarehouseOutId: 0,
  6243. }
  6244. service.CreateGoodErrcode(goodErrcode)
  6245. }
  6246. //查询默认仓库
  6247. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6248. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6249. var total_count int64
  6250. for _, it := range stockList {
  6251. total_count += it.StockCount
  6252. }
  6253. //基础库插入数据
  6254. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6255. if errcodes != nil {
  6256. goodErrcode := models.XtGoodErrcode{
  6257. UserOrgId: item.OrgId,
  6258. Errcode: "自动出库基础库插入数据",
  6259. GoodId: item.GoodId,
  6260. Status: 1,
  6261. Ctime: time.Now().Unix(),
  6262. Mtime: 0,
  6263. Count: 0,
  6264. StockCount: 0,
  6265. Creater: creater,
  6266. BatchNumberId: 0,
  6267. WarehouseOutId: 0,
  6268. }
  6269. service.CreateGoodErrcode(goodErrcode)
  6270. }
  6271. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6272. var flush_count int64
  6273. for _, it := range goodList {
  6274. flush_count += it.StockCount
  6275. }
  6276. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6277. if errsss != nil {
  6278. goodErrcode := models.XtGoodErrcode{
  6279. UserOrgId: item.OrgId,
  6280. Errcode: "自动出库剩余库存更新数据",
  6281. GoodId: item.GoodId,
  6282. Status: 1,
  6283. Ctime: time.Now().Unix(),
  6284. Mtime: 0,
  6285. Count: 0,
  6286. StockCount: 0,
  6287. Creater: creater,
  6288. BatchNumberId: 0,
  6289. WarehouseOutId: 0,
  6290. }
  6291. service.CreateGoodErrcode(goodErrcode)
  6292. }
  6293. }
  6294. }
  6295. //
  6296. } else if err == nil {
  6297. for _, item := range consumables {
  6298. //出库
  6299. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6300. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6301. if err != nil {
  6302. goodErrcode := models.XtGoodErrcode{
  6303. UserOrgId: adminInfo.Org.Id,
  6304. Errcode: "自动出库接口报错",
  6305. GoodId: 0,
  6306. Status: 1,
  6307. Ctime: time.Now().Unix(),
  6308. Mtime: 0,
  6309. Count: 0,
  6310. StockCount: 0,
  6311. Creater: creator,
  6312. BatchNumberId: 0,
  6313. WarehouseOutId: 0,
  6314. }
  6315. service.CreateGoodErrcode(goodErrcode)
  6316. }
  6317. //出库数量相加
  6318. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6319. if errss != nil {
  6320. goodErrcode := models.XtGoodErrcode{
  6321. UserOrgId: item.UserOrgId,
  6322. Errcode: "创建剩余库存字段报错",
  6323. GoodId: item.GoodId,
  6324. Status: 1,
  6325. Ctime: time.Now().Unix(),
  6326. Mtime: time.Now().Unix(),
  6327. Count: 0,
  6328. StockCount: 0,
  6329. Creater: item.Creater,
  6330. BatchNumberId: 0,
  6331. WarehouseOutId: 0,
  6332. }
  6333. service.CreateGoodErrcode(goodErrcode)
  6334. }
  6335. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6336. if len(list) == 0 {
  6337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6338. return
  6339. }
  6340. for _, item := range list {
  6341. prepare := models.DialysisBeforePrepare{
  6342. UserOrgId: adminInfo.Org.Id,
  6343. PatientId: patient_id,
  6344. RecordDate: record_time,
  6345. GoodId: item.GoodId,
  6346. GoodTypeId: item.GoodTypeId,
  6347. Count: item.Count,
  6348. Creater: adminInfo.AdminUser.Id,
  6349. Status: 1,
  6350. Ctime: time.Now().Unix(),
  6351. StorehouseId: houseConfig.StorehouseOutInfo,
  6352. }
  6353. //清空准备表数据
  6354. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6355. if errs != nil {
  6356. goodErrcode := models.XtGoodErrcode{
  6357. UserOrgId: adminInfo.Org.Id,
  6358. Errcode: "自动出库清空准备表数据报错",
  6359. GoodId: 0,
  6360. Status: 1,
  6361. Ctime: time.Now().Unix(),
  6362. Mtime: 0,
  6363. Count: 0,
  6364. StockCount: 0,
  6365. Creater: creator,
  6366. BatchNumberId: 0,
  6367. WarehouseOutId: 0,
  6368. }
  6369. service.CreateGoodErrcode(goodErrcode)
  6370. }
  6371. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6372. if errcodes != nil {
  6373. goodErrcode := models.XtGoodErrcode{
  6374. UserOrgId: adminInfo.Org.Id,
  6375. Errcode: "自动出库创建准备表数据报错",
  6376. GoodId: 0,
  6377. Status: 1,
  6378. Ctime: time.Now().Unix(),
  6379. Mtime: 0,
  6380. Count: 0,
  6381. StockCount: 0,
  6382. Creater: creator,
  6383. BatchNumberId: 0,
  6384. WarehouseOutId: 0,
  6385. }
  6386. service.CreateGoodErrcode(goodErrcode)
  6387. }
  6388. //查询默认仓库
  6389. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6390. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6391. var total_count int64
  6392. for _, it := range stockList {
  6393. total_count += it.StockCount
  6394. }
  6395. //基础库插入数据
  6396. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6397. if errcodes != nil {
  6398. goodErrcode := models.XtGoodErrcode{
  6399. UserOrgId: adminInfo.Org.Id,
  6400. Errcode: "自动出库基础库插入数据报错",
  6401. GoodId: 0,
  6402. Status: 1,
  6403. Ctime: time.Now().Unix(),
  6404. Mtime: 0,
  6405. Count: 0,
  6406. StockCount: 0,
  6407. Creater: creator,
  6408. BatchNumberId: 0,
  6409. WarehouseOutId: 0,
  6410. }
  6411. service.CreateGoodErrcode(goodErrcode)
  6412. }
  6413. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6414. var flush_count int64
  6415. for _, it := range goodList {
  6416. flush_count += it.StockCount
  6417. }
  6418. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6419. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6420. if errss != nil {
  6421. goodErrcode := models.XtGoodErrcode{
  6422. UserOrgId: item.OrgId,
  6423. Errcode: "自动出库剩余库存更新数据",
  6424. GoodId: item.GoodId,
  6425. Status: 1,
  6426. Ctime: time.Now().Unix(),
  6427. Mtime: 0,
  6428. Count: 0,
  6429. StockCount: 0,
  6430. Creater: creater,
  6431. BatchNumberId: 0,
  6432. WarehouseOutId: 0,
  6433. }
  6434. service.CreateGoodErrcode(goodErrcode)
  6435. }
  6436. }
  6437. }
  6438. }
  6439. c.ServeSuccessJSON(map[string]interface{}{
  6440. "msg": "提交成功",
  6441. "message": "2",
  6442. "good_name": "",
  6443. "specification_name": "",
  6444. })
  6445. return
  6446. }
  6447. if record.IsOpen == 1 {
  6448. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6449. //查询是否有库存
  6450. for _, item := range consumables {
  6451. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6452. if item.Count > warehouse.Count {
  6453. goodErrcode := models.XtGoodErrcode{
  6454. UserOrgId: item.UserOrgId,
  6455. Errcode: "自动出库库存不足",
  6456. GoodId: item.GoodId,
  6457. Status: 1,
  6458. Ctime: time.Now().Unix(),
  6459. Mtime: 0,
  6460. Count: 0,
  6461. StockCount: 0,
  6462. Creater: creator,
  6463. BatchNumberId: warehouse.ID,
  6464. WarehouseOutId: 0,
  6465. }
  6466. service.CreateGoodErrcode(goodErrcode)
  6467. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6468. c.ServeSuccessJSON(map[string]interface{}{
  6469. "message": "1",
  6470. "good_name": goodObj.GoodName,
  6471. "specification_name": goodObj.SpecificationName,
  6472. })
  6473. return
  6474. }
  6475. }
  6476. //查询是否有出库单
  6477. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6478. if err == gorm.ErrRecordNotFound {
  6479. //没有记录,则创建出库单
  6480. timeStr := time.Now().Format("2006-01-02")
  6481. timeArr := strings.Split(timeStr, "-")
  6482. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6483. total = total + 1
  6484. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6485. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6486. number = number + total
  6487. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6488. creater := adminInfo.AdminUser.Id
  6489. warehouseOut := models.WarehouseOut{
  6490. WarehouseOutOrderNumber: warehousing_out_order,
  6491. OperationTime: time.Now().Unix(),
  6492. OrgId: adminInfo.Org.Id,
  6493. Creater: creater,
  6494. Ctime: time.Now().Unix(),
  6495. Status: 1,
  6496. WarehouseOutTime: record_time,
  6497. Dealer: 0,
  6498. Manufacturer: 0,
  6499. Type: 1,
  6500. IsSys: 1,
  6501. StorehouseId: houseConfig.StorehouseOutInfo,
  6502. IsCheck: 1,
  6503. }
  6504. err := service.AddSigleWarehouseOut(&warehouseOut)
  6505. if err != nil {
  6506. goodErrcode := models.XtGoodErrcode{
  6507. UserOrgId: adminInfo.Org.Id,
  6508. Errcode: "创建出库单失败",
  6509. GoodId: 0,
  6510. Status: 1,
  6511. Ctime: time.Now().Unix(),
  6512. Mtime: 0,
  6513. Count: 0,
  6514. StockCount: 0,
  6515. Creater: creator,
  6516. BatchNumberId: 0,
  6517. WarehouseOutId: 0,
  6518. }
  6519. service.CreateGoodErrcode(goodErrcode)
  6520. utils.TraceLog("创建出库单失败 err = %v", err)
  6521. } else {
  6522. for _, item := range consumables {
  6523. //出库
  6524. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6525. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6526. if err == nil {
  6527. goodErrcode := models.XtGoodErrcode{
  6528. UserOrgId: adminInfo.Org.Id,
  6529. Errcode: "自动出库接口报错",
  6530. GoodId: 0,
  6531. Status: 1,
  6532. Ctime: time.Now().Unix(),
  6533. Mtime: 0,
  6534. Count: 0,
  6535. StockCount: 0,
  6536. Creater: creator,
  6537. BatchNumberId: 0,
  6538. WarehouseOutId: 0,
  6539. }
  6540. service.CreateGoodErrcode(goodErrcode)
  6541. utils.TraceLog("创建出库单失败 err = %v", err)
  6542. }
  6543. //查询
  6544. //出库数量相加
  6545. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6546. if errs != nil {
  6547. goodErrcode := models.XtGoodErrcode{
  6548. UserOrgId: item.UserOrgId,
  6549. Errcode: "创建剩余库存字段报错",
  6550. GoodId: item.GoodId,
  6551. Status: 1,
  6552. Ctime: time.Now().Unix(),
  6553. Mtime: 0,
  6554. Count: 0,
  6555. StockCount: 0,
  6556. Creater: creater,
  6557. BatchNumberId: 0,
  6558. WarehouseOutId: 0,
  6559. }
  6560. service.CreateGoodErrcode(goodErrcode)
  6561. }
  6562. }
  6563. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6564. if len(list) == 0 {
  6565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6566. return
  6567. }
  6568. for _, item := range list {
  6569. prepare := models.DialysisBeforePrepare{
  6570. UserOrgId: adminInfo.Org.Id,
  6571. PatientId: patient_id,
  6572. RecordDate: record_time,
  6573. GoodId: item.GoodId,
  6574. GoodTypeId: item.GoodTypeId,
  6575. Count: item.Count,
  6576. Creater: adminInfo.AdminUser.Id,
  6577. Status: 1,
  6578. Ctime: time.Now().Unix(),
  6579. StorehouseId: houseConfig.StorehouseOutInfo,
  6580. }
  6581. //清空准备表数据
  6582. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6583. if err != nil {
  6584. goodErrcode := models.XtGoodErrcode{
  6585. UserOrgId: item.OrgId,
  6586. Errcode: "自动出库清空准备表数据报错",
  6587. GoodId: item.GoodId,
  6588. Status: 1,
  6589. Ctime: time.Now().Unix(),
  6590. Mtime: 0,
  6591. Count: 0,
  6592. StockCount: 0,
  6593. Creater: creater,
  6594. BatchNumberId: 0,
  6595. WarehouseOutId: 0,
  6596. }
  6597. service.CreateGoodErrcode(goodErrcode)
  6598. }
  6599. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6600. if errs != nil {
  6601. goodErrcode := models.XtGoodErrcode{
  6602. UserOrgId: item.OrgId,
  6603. Errcode: "自动出库创建准备表数据报错",
  6604. GoodId: item.GoodId,
  6605. Status: 1,
  6606. Ctime: time.Now().Unix(),
  6607. Mtime: 0,
  6608. Count: 0,
  6609. StockCount: 0,
  6610. Creater: creater,
  6611. BatchNumberId: 0,
  6612. WarehouseOutId: 0,
  6613. }
  6614. service.CreateGoodErrcode(goodErrcode)
  6615. }
  6616. //查询默认仓库
  6617. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6618. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6619. var total_count int64
  6620. for _, it := range stockList {
  6621. total_count += it.StockCount
  6622. }
  6623. //基础库插入数据
  6624. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6625. if errcodes != nil {
  6626. goodErrcode := models.XtGoodErrcode{
  6627. UserOrgId: item.OrgId,
  6628. Errcode: "自动出库基础库插入数据",
  6629. GoodId: item.GoodId,
  6630. Status: 1,
  6631. Ctime: time.Now().Unix(),
  6632. Mtime: 0,
  6633. Count: 0,
  6634. StockCount: 0,
  6635. Creater: creater,
  6636. BatchNumberId: 0,
  6637. WarehouseOutId: 0,
  6638. }
  6639. service.CreateGoodErrcode(goodErrcode)
  6640. }
  6641. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6642. var flush_count int64
  6643. for _, it := range goodList {
  6644. flush_count += it.StockCount
  6645. }
  6646. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6647. if errsss != nil {
  6648. goodErrcode := models.XtGoodErrcode{
  6649. UserOrgId: item.OrgId,
  6650. Errcode: "自动出库剩余库存更新数据",
  6651. GoodId: item.GoodId,
  6652. Status: 1,
  6653. Ctime: time.Now().Unix(),
  6654. Mtime: 0,
  6655. Count: 0,
  6656. StockCount: 0,
  6657. Creater: creater,
  6658. BatchNumberId: 0,
  6659. WarehouseOutId: 0,
  6660. }
  6661. service.CreateGoodErrcode(goodErrcode)
  6662. }
  6663. }
  6664. }
  6665. //
  6666. } else if err == nil {
  6667. for _, item := range consumables {
  6668. //出库
  6669. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6670. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6671. if err != nil {
  6672. goodErrcode := models.XtGoodErrcode{
  6673. UserOrgId: adminInfo.Org.Id,
  6674. Errcode: "自动出库接口报错",
  6675. GoodId: 0,
  6676. Status: 1,
  6677. Ctime: time.Now().Unix(),
  6678. Mtime: 0,
  6679. Count: 0,
  6680. StockCount: 0,
  6681. Creater: creator,
  6682. BatchNumberId: 0,
  6683. WarehouseOutId: 0,
  6684. }
  6685. service.CreateGoodErrcode(goodErrcode)
  6686. }
  6687. //出库数量相加
  6688. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6689. if errss != nil {
  6690. goodErrcode := models.XtGoodErrcode{
  6691. UserOrgId: item.UserOrgId,
  6692. Errcode: "创建剩余库存字段报错",
  6693. GoodId: item.GoodId,
  6694. Status: 1,
  6695. Ctime: time.Now().Unix(),
  6696. Mtime: time.Now().Unix(),
  6697. Count: 0,
  6698. StockCount: 0,
  6699. Creater: item.Creater,
  6700. BatchNumberId: 0,
  6701. WarehouseOutId: 0,
  6702. }
  6703. service.CreateGoodErrcode(goodErrcode)
  6704. }
  6705. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6706. if len(list) == 0 {
  6707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6708. return
  6709. }
  6710. for _, item := range list {
  6711. prepare := models.DialysisBeforePrepare{
  6712. UserOrgId: adminInfo.Org.Id,
  6713. PatientId: patient_id,
  6714. RecordDate: record_time,
  6715. GoodId: item.GoodId,
  6716. GoodTypeId: item.GoodTypeId,
  6717. Count: item.Count,
  6718. Creater: adminInfo.AdminUser.Id,
  6719. Status: 1,
  6720. Ctime: time.Now().Unix(),
  6721. StorehouseId: houseConfig.StorehouseOutInfo,
  6722. }
  6723. //清空准备表数据
  6724. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6725. if errs != nil {
  6726. goodErrcode := models.XtGoodErrcode{
  6727. UserOrgId: adminInfo.Org.Id,
  6728. Errcode: "自动出库清空准备表数据报错",
  6729. GoodId: 0,
  6730. Status: 1,
  6731. Ctime: time.Now().Unix(),
  6732. Mtime: 0,
  6733. Count: 0,
  6734. StockCount: 0,
  6735. Creater: creator,
  6736. BatchNumberId: 0,
  6737. WarehouseOutId: 0,
  6738. }
  6739. service.CreateGoodErrcode(goodErrcode)
  6740. }
  6741. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6742. if errcodes != nil {
  6743. goodErrcode := models.XtGoodErrcode{
  6744. UserOrgId: adminInfo.Org.Id,
  6745. Errcode: "自动出库创建准备表数据报错",
  6746. GoodId: 0,
  6747. Status: 1,
  6748. Ctime: time.Now().Unix(),
  6749. Mtime: 0,
  6750. Count: 0,
  6751. StockCount: 0,
  6752. Creater: creator,
  6753. BatchNumberId: 0,
  6754. WarehouseOutId: 0,
  6755. }
  6756. service.CreateGoodErrcode(goodErrcode)
  6757. }
  6758. //查询默认仓库
  6759. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6760. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6761. var total_count int64
  6762. for _, it := range stockList {
  6763. total_count += it.StockCount
  6764. }
  6765. //基础库插入数据
  6766. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6767. if errcodes != nil {
  6768. goodErrcode := models.XtGoodErrcode{
  6769. UserOrgId: adminInfo.Org.Id,
  6770. Errcode: "自动出库基础库插入数据报错",
  6771. GoodId: 0,
  6772. Status: 1,
  6773. Ctime: time.Now().Unix(),
  6774. Mtime: 0,
  6775. Count: 0,
  6776. StockCount: 0,
  6777. Creater: creator,
  6778. BatchNumberId: 0,
  6779. WarehouseOutId: 0,
  6780. }
  6781. service.CreateGoodErrcode(goodErrcode)
  6782. }
  6783. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6784. var flush_count int64
  6785. for _, it := range goodList {
  6786. flush_count += it.StockCount
  6787. }
  6788. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6789. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6790. if errss != nil {
  6791. goodErrcode := models.XtGoodErrcode{
  6792. UserOrgId: item.OrgId,
  6793. Errcode: "自动出库剩余库存更新数据",
  6794. GoodId: item.GoodId,
  6795. Status: 1,
  6796. Ctime: time.Now().Unix(),
  6797. Mtime: 0,
  6798. Count: 0,
  6799. StockCount: 0,
  6800. Creater: creater,
  6801. BatchNumberId: 0,
  6802. WarehouseOutId: 0,
  6803. }
  6804. service.CreateGoodErrcode(goodErrcode)
  6805. }
  6806. }
  6807. }
  6808. }
  6809. c.ServeSuccessJSON(map[string]interface{}{
  6810. "msg": "提交成功",
  6811. "message": "2",
  6812. "good_name": "",
  6813. "specification_name": "",
  6814. })
  6815. return
  6816. } else {
  6817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6818. return
  6819. }
  6820. }
  6821. func (c *DialysisAPIController) EditConsumables() {
  6822. patient_id, _ := c.GetInt64("patient_id", 0)
  6823. record_date := c.GetString("record_time")
  6824. if patient_id <= 0 {
  6825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6826. return
  6827. }
  6828. adminInfo := c.GetMobileAdminUserInfo()
  6829. timeLayout := "2006-01-02"
  6830. loc, _ := time.LoadLocation("Local")
  6831. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6832. record_time := theRecordTime.Unix()
  6833. // 查询信息规挡的设置天数
  6834. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6835. if infor.ID > 0 && infor.WeekDay > 0 {
  6836. var cha_time int64
  6837. timeNowStr := time.Now().Format("2006-01-02")
  6838. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6839. //今日的日期减去设置的日期
  6840. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6841. if cha_time >= record_time {
  6842. //查询审核是否允许
  6843. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6844. //申请状态不允许的情况 拒绝修改
  6845. if infor.ApplicationStatus != 1 {
  6846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6847. return
  6848. }
  6849. }
  6850. }
  6851. dataBody := make(map[string]interface{}, 0)
  6852. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6853. if err != nil {
  6854. utils.ErrorLog(err.Error())
  6855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6856. return
  6857. }
  6858. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6859. var beforePrepares []*models.DialysisBeforePrepareGoods
  6860. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6861. var cancelbefor []*models.DialysisBeforePrepareGoods
  6862. var outbefor []*models.DialysisBeforePrepareGoods
  6863. //判断是否开启自动出库
  6864. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6865. if record.IsOpen == 1 {
  6866. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6867. goods, _ := dataBody["goods"].([]interface{})
  6868. if len(goods) > 0 {
  6869. for _, item := range goods {
  6870. items := item.(map[string]interface{})
  6871. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6872. utils.ErrorLog("good_id")
  6873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6874. return
  6875. }
  6876. good_id := int64(items["good_id"].(float64))
  6877. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6878. utils.ErrorLog("good_type_id")
  6879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6880. return
  6881. }
  6882. good_type_id := int64(items["good_type_id"].(float64))
  6883. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6884. utils.ErrorLog("count")
  6885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6886. return
  6887. }
  6888. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6889. commdity_code := items["commdity_code"].(string)
  6890. fmt.Println(commdity_code)
  6891. prepareGoods := &models.DialysisBeforePrepareGoods{
  6892. GoodTypeId: good_type_id,
  6893. GoodId: good_id,
  6894. Count: count,
  6895. StorehouseId: houseConfig.StorehouseOutInfo,
  6896. }
  6897. beforePrepares = append(beforePrepares, prepareGoods)
  6898. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6899. GoodTypeId: good_type_id,
  6900. GoodId: good_id,
  6901. Count: count,
  6902. StorehouseId: houseConfig.StorehouseOutInfo,
  6903. }
  6904. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6905. }
  6906. for _, item := range beforePrepares {
  6907. //1.查看该患者该耗材型号最后一次出库数量
  6908. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6909. //判断当前出库数量和最后一次出库数量的大小
  6910. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6911. if item.Count < goodInfo.Count {
  6912. cancelbefor = append(cancelbefor, item)
  6913. }
  6914. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6915. if item.Count > goodInfo.Count {
  6916. outbefor = append(outbefor, item)
  6917. }
  6918. //处理编辑耗材新增不了的问题
  6919. if goodInfo.Count == item.Count {
  6920. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6921. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6922. }
  6923. }
  6924. if len(cancelbefor) > 0 {
  6925. //退库
  6926. for _, item := range cancelbefor {
  6927. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6928. creater := adminInfo.AdminUser.Id
  6929. //查询该患者当天已经出库的耗材信息
  6930. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6931. var delete_count int64 = 0
  6932. delete_count = warehouseOutInfos.Count - item.Count
  6933. //增加库存数量
  6934. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6935. //减少实际出库库存数量
  6936. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6937. // 删除出库完成后,要增加对应批次的库存数量
  6938. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6939. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6940. //更新剩余库存
  6941. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6942. var flush_count int64
  6943. for _, it := range goodListOne {
  6944. flush_count += it.StockCount
  6945. }
  6946. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6947. //查询剩余库存
  6948. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6949. var sum_count int64
  6950. for _, item := range goodList {
  6951. sum_count += item.StockCount
  6952. }
  6953. // 在出库记录表里记录退库详情
  6954. warehouseOutInfo := &models.WarehouseOutInfo{
  6955. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6956. WarehouseOutId: warehouseOut.ID,
  6957. Status: 1,
  6958. Ctime: time.Now().Unix(),
  6959. OrgId: adminInfo.Org.Id,
  6960. Type: 1,
  6961. IsSys: 1,
  6962. SysRecordTime: record_time,
  6963. GoodTypeId: item.GoodTypeId,
  6964. GoodId: item.GoodId,
  6965. PatientId: patient_id,
  6966. ConsumableType: 2,
  6967. StorehouseId: houseConfig.StorehouseOutInfo,
  6968. IsCheck: 1,
  6969. OverCount: sum_count,
  6970. }
  6971. warehouseOutInfo.Count = item.Count
  6972. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6973. warehouseOutInfo.Price = stockInInfo.Price
  6974. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6975. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6976. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6977. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6978. warehouseOutInfo.Number = warehouseOutInfos.Number
  6979. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6980. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6981. //查找当天是否存在出库记录
  6982. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6983. if errcod == gorm.ErrRecordNotFound {
  6984. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6985. //插入详情明细表
  6986. stockFlow := models.VmStockFlow{
  6987. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6988. WarehouseOutId: warehouseOut.ID,
  6989. GoodId: item.GoodId,
  6990. Number: warehouseOutInfos.Number,
  6991. ProductDate: stockInInfo.ProductDate,
  6992. ExpireDate: stockInInfo.ExpiryDate,
  6993. Count: item.Count,
  6994. Price: stockInInfo.Price,
  6995. Status: 1,
  6996. Ctime: record_time,
  6997. UserOrgId: adminInfo.Org.Id,
  6998. Manufacturer: stockInInfo.Manufacturer,
  6999. Dealer: stockInInfo.Dealer,
  7000. LicenseNumber: stockInInfo.LicenseNumber,
  7001. IsEdit: 2,
  7002. Creator: creater,
  7003. SystemTime: record_time,
  7004. ConsumableType: 3,
  7005. WarehousingDetailId: 0,
  7006. IsSys: 1,
  7007. UpdateCreator: creater,
  7008. PatientId: patient_id,
  7009. StorehouseId: houseConfig.StorehouseOutInfo,
  7010. }
  7011. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7012. if errflow == gorm.ErrRecordNotFound {
  7013. //创建流水表
  7014. err := service.CreateStockFlowOne(stockFlow)
  7015. fmt.Println("err", err)
  7016. } else if errflow == nil {
  7017. //插入详情明细表
  7018. stockFlow := models.VmStockFlow{
  7019. ID: exsit.ID,
  7020. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7021. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7022. WarehouseOutId: warehouseOut.ID,
  7023. GoodId: item.GoodId,
  7024. Number: warehouseOutInfos.Number,
  7025. ProductDate: stockInInfo.ProductDate,
  7026. ExpireDate: stockInInfo.ExpiryDate,
  7027. Count: exsit.Count - delete_count,
  7028. Price: stockInInfo.Price,
  7029. Status: 1,
  7030. Ctime: record_time,
  7031. UserOrgId: adminInfo.Org.Id,
  7032. Manufacturer: stockInInfo.Manufacturer,
  7033. Dealer: stockInInfo.Dealer,
  7034. LicenseNumber: stockInInfo.LicenseNumber,
  7035. IsEdit: 2,
  7036. Creator: creater,
  7037. SystemTime: record_time,
  7038. ConsumableType: 3,
  7039. WarehousingDetailId: 0,
  7040. IsSys: 1,
  7041. UpdateCreator: creater,
  7042. PatientId: patient_id,
  7043. StorehouseId: houseConfig.StorehouseOutInfo,
  7044. }
  7045. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7046. }
  7047. } else if errcod == nil {
  7048. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7049. //查询剩余库存
  7050. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7051. var sum_count int64
  7052. for _, item := range goodList {
  7053. sum_count += item.StockCount
  7054. }
  7055. //创建退库单,生成退库数据
  7056. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7057. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7058. operation_time := time.Now().Unix()
  7059. creater := adminInfo.AdminUser.Id
  7060. //创建退库单
  7061. timeStr := time.Now().Format("2006-01-02")
  7062. timeArr := strings.Split(timeStr, "-")
  7063. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7064. total = total + 1
  7065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7066. cancelStock := models.CancelStock{
  7067. OrderNumber: orderNumber,
  7068. OperaTime: operation_time,
  7069. OrgId: adminInfo.Org.Id,
  7070. Creater: creater,
  7071. Ctime: time.Now().Unix(),
  7072. Status: 1,
  7073. ReturnTime: record_time,
  7074. Type: 1,
  7075. StorehouseId: houseConfig.StorehouseOutInfo,
  7076. IsCheck: 1,
  7077. }
  7078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7079. if msgerrkonde == gorm.ErrRecordNotFound {
  7080. service.AddSigleCancelStock(&cancelStock)
  7081. }
  7082. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7083. //查询是否有出库
  7084. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7085. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7086. deaerler, _ := service.GetDealerById(info.Dealer)
  7087. if info.ID > 0 {
  7088. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7089. cancelStockInfo := models.CancelStockInfo{
  7090. GoodId: item.GoodId,
  7091. CancelStockId: cancel.ID,
  7092. GoodTypeId: good.GoodTypeId,
  7093. Count: delete_count,
  7094. Price: info.Price,
  7095. Total: 0,
  7096. ProductDate: info.ProductDate,
  7097. ExpiryDate: info.ExpiryDate,
  7098. Ctime: time.Now().Unix(),
  7099. Status: 1,
  7100. OrgId: adminInfo.Org.Id,
  7101. OrderNumber: cancel.OrderNumber,
  7102. Type: 0,
  7103. Dealer: deaerler.DealerName,
  7104. Manufacturer: manufacturer.ManufacturerName,
  7105. Number: info.Number,
  7106. RegisterAccount: "",
  7107. Remark: "",
  7108. WarehouseInfoId: info.WarehouseInfotId,
  7109. PatientId: info.PatientId,
  7110. RecordDate: info.SysRecordTime,
  7111. StorehouseId: houseConfig.StorehouseOutInfo,
  7112. IsCheck: 1,
  7113. }
  7114. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7115. //退库数量增加
  7116. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7117. //查询剩余库存
  7118. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7119. var over_count int64
  7120. for _, it := range goodList {
  7121. over_count += it.StockCount
  7122. }
  7123. flow := models.VmStockFlow{
  7124. WarehousingId: info.WarehouseInfotId,
  7125. GoodId: item.GoodId,
  7126. Number: info.Number,
  7127. LicenseNumber: info.LicenseNumber,
  7128. Count: delete_count,
  7129. UserOrgId: adminInfo.Org.Id,
  7130. PatientId: patient_id,
  7131. SystemTime: info.SysRecordTime,
  7132. ConsumableType: 7,
  7133. IsSys: 0,
  7134. WarehousingOrder: "",
  7135. WarehouseOutId: info.WarehouseOutId,
  7136. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7137. IsEdit: 0,
  7138. CancelStockId: cancel.ID,
  7139. CancelOrderNumber: cancel.OrderNumber,
  7140. Manufacturer: manufacturer.ID,
  7141. Dealer: 0,
  7142. Creator: adminInfo.AdminUser.Id,
  7143. UpdateCreator: 0,
  7144. Status: 1,
  7145. Ctime: record_time,
  7146. Mtime: 0,
  7147. Price: info.Price,
  7148. WarehousingDetailId: info.WarehouseInfotId,
  7149. WarehouseOutDetailId: info.ID,
  7150. CancelOutDetailId: cancelInfo.ID,
  7151. ProductDate: info.ProductDate,
  7152. ExpireDate: info.ExpiryDate,
  7153. StorehouseId: houseConfig.StorehouseOutInfo,
  7154. OverCount: over_count,
  7155. }
  7156. service.CreateStockFlowOne(flow)
  7157. }
  7158. }
  7159. //更改自动出库的表格
  7160. details := models.BloodAutomaticReduceDetail{
  7161. WarehouseOutId: warehouseOutInfo.ID,
  7162. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7163. PatientId: patient_id,
  7164. Ctime: time.Now().Unix(),
  7165. Mtime: time.Now().Unix(),
  7166. Status: 1,
  7167. RecordTime: record_time,
  7168. OrgId: adminInfo.Org.Id,
  7169. GoodId: item.GoodId,
  7170. GoodTypeId: item.GoodTypeId,
  7171. Count: item.Count,
  7172. StorehouseId: houseConfig.StorehouseOutInfo,
  7173. }
  7174. //查询当天耗材是否已经存在数据
  7175. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7176. if errcode == gorm.ErrRecordNotFound {
  7177. service.CreateAutoReduceRecord(&details)
  7178. } else if errcode == nil {
  7179. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7180. service.CreateAutoReduceRecord(&details)
  7181. }
  7182. //查询默认仓库
  7183. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7184. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7185. var total_count int64
  7186. for _, it := range stockList {
  7187. total_count += it.StockCount
  7188. }
  7189. //基础库插入数据
  7190. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7191. }
  7192. }
  7193. if len(outbefor) > 0 {
  7194. //出库
  7195. for _, item := range outbefor {
  7196. var last_total int64
  7197. //1.查看该患者该耗材型号最后一次出库数量
  7198. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7199. //计算当前出库和最后一次出库数据相差数据
  7200. last_total = item.Count - goodInfoOne.Count
  7201. //查询该耗材的总库存
  7202. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7203. // 如果库存差大于剩余库存则提示库存不足
  7204. if last_total > wareinfo.StockCount {
  7205. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7206. c.ServeSuccessJSON(map[string]interface{}{
  7207. "message": "1",
  7208. "good_name": goodObj.GoodName,
  7209. "specification_name": goodObj.SpecificationName,
  7210. })
  7211. return
  7212. } else {
  7213. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7214. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7215. if err == gorm.ErrRecordNotFound {
  7216. //没有记录,则创建出库单
  7217. timeStr := time.Now().Format("2006-01-02")
  7218. timeArr := strings.Split(timeStr, "-")
  7219. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7220. total = total + 1
  7221. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7222. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7223. number = number + total
  7224. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7225. warehouseOut := models.WarehouseOut{
  7226. WarehouseOutOrderNumber: warehousing_out_order,
  7227. OperationTime: time.Now().Unix(),
  7228. OrgId: adminInfo.Org.Id,
  7229. Creater: adminInfo.AdminUser.Id,
  7230. Ctime: time.Now().Unix(),
  7231. Status: 1,
  7232. WarehouseOutTime: record_time,
  7233. Dealer: 0,
  7234. Manufacturer: 0,
  7235. Type: 1,
  7236. IsSys: 1,
  7237. StorehouseId: houseConfig.StorehouseOutInfo,
  7238. IsCheck: 1,
  7239. }
  7240. service.AddSigleWarehouseOut(&warehouseOut)
  7241. }
  7242. //出库
  7243. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7244. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7245. //1.查看该患者该耗材型号最后一次出库数量
  7246. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7247. prepare := models.DialysisBeforePrepare{
  7248. UserOrgId: adminInfo.Org.Id,
  7249. PatientId: patient_id,
  7250. RecordDate: record_time,
  7251. GoodId: item.GoodId,
  7252. GoodTypeId: item.GoodTypeId,
  7253. Count: item.Count - goodInfoTwo.Count,
  7254. Ctime: time.Now().Unix(),
  7255. Mtime: 0,
  7256. Creater: adminInfo.AdminUser.Id,
  7257. Modifier: adminInfo.AdminUser.Id,
  7258. Status: 1,
  7259. CommdityCode: "",
  7260. NewCount: 0,
  7261. ProjectId: 0,
  7262. StorehouseId: houseConfig.StorehouseOutInfo,
  7263. }
  7264. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7265. //增加出库数量
  7266. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7267. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7268. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7269. var total_count int64
  7270. for _, it := range stockList {
  7271. total_count += it.StockCount
  7272. }
  7273. //基础库插入数据
  7274. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7275. //剩余库存
  7276. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7277. var flush_count int64
  7278. for _, it := range goodList {
  7279. flush_count += it.StockCount
  7280. }
  7281. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7282. }
  7283. }
  7284. }
  7285. //查询今日出库数据
  7286. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7287. for _, it := range list {
  7288. prepare := models.DialysisBeforePrepare{
  7289. UserOrgId: it.OrgId,
  7290. PatientId: patient_id,
  7291. RecordDate: it.RecordTime,
  7292. GoodId: it.GoodId,
  7293. GoodTypeId: it.GoodTypeId,
  7294. Count: it.Count,
  7295. Ctime: time.Now().Unix(),
  7296. Creater: adminInfo.AdminUser.Id,
  7297. Status: 1,
  7298. StorehouseId: houseConfig.StorehouseOutInfo,
  7299. ProjectId: it.ProjectId,
  7300. }
  7301. //删除准备表数据
  7302. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7303. service.CreateDialysisBeforePrepareOne(&prepare)
  7304. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7305. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7306. var total_count int64
  7307. for _, it := range stockList {
  7308. total_count += it.StockCount
  7309. }
  7310. //基础库插入数据
  7311. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7312. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7313. var flush_count int64
  7314. for _, it := range goodList {
  7315. flush_count += it.StockCount
  7316. }
  7317. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7318. }
  7319. }
  7320. }
  7321. //更新自动出库的地方
  7322. var errs error
  7323. if errs == nil {
  7324. c.ServeSuccessJSON(map[string]interface{}{
  7325. "msg": "修改成功",
  7326. "message": "2",
  7327. "good_name": "",
  7328. "specification_name": "",
  7329. })
  7330. return
  7331. } else {
  7332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7333. return
  7334. }
  7335. }
  7336. }
  7337. func (c *DialysisAPIController) GetDialysisGoods() {
  7338. schedualDate := c.GetString("schedule_date")
  7339. schedule_type, _ := c.GetInt64("schedule_type")
  7340. partition_id, _ := c.GetInt64("partition_id")
  7341. page, _ := c.GetInt("page")
  7342. patient_id, _ := c.GetInt64("patient_id")
  7343. schedualEndDate := int64(0)
  7344. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7345. if parseDateErr != nil && len(schedualDate) != 0 {
  7346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7347. return
  7348. }
  7349. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7350. if parseDateErr != nil && len(schedualDate) != 0 {
  7351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7352. return
  7353. }
  7354. schedualEndDate = endDate.Unix()
  7355. adminUser := c.GetMobileAdminUserInfo()
  7356. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7357. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7358. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7359. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7360. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7361. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7362. //获取当天该病人的透析处方
  7363. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7364. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7365. if err == gorm.ErrRecordNotFound {
  7366. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7367. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7368. if patient_id != 0 {
  7369. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7370. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7371. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7372. //获取患者总的出库数据
  7373. item.LastAutomaticReduceDetail = goodUser
  7374. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7375. item.Project = project
  7376. for _, it := range item.AutomaticReduceDetail {
  7377. var total int64
  7378. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7379. for _, its := range auto {
  7380. total += its.Count
  7381. }
  7382. it.Count = total
  7383. }
  7384. }
  7385. }
  7386. c.ServeSuccessJSON(map[string]interface{}{
  7387. "dialysis_goods": dialysisGoods,
  7388. "good_type": goodTypes,
  7389. "total": total,
  7390. "prescribe": prescribe,
  7391. "good_info": good_info,
  7392. "warehouseOutList": warehouseOutList,
  7393. "config": config,
  7394. "outConfig": outConfig,
  7395. "settleConfig": settleConfig,
  7396. })
  7397. return
  7398. } else if err == nil {
  7399. //获取当天排班的每个患者的库存使用情况
  7400. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7401. //获取患者总的出库数据
  7402. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7403. if patient_id != 0 {
  7404. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7405. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7406. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7407. item.Project = project
  7408. item.LastAutomaticReduceDetail = goodUser
  7409. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7410. for _, it := range item.AutomaticReduceDetail {
  7411. var total int64
  7412. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7413. for _, its := range auto {
  7414. total += its.Count
  7415. }
  7416. it.Count = total
  7417. }
  7418. }
  7419. }
  7420. if err == nil {
  7421. c.ServeSuccessJSON(map[string]interface{}{
  7422. "dialysis_goods": dialysisGoods,
  7423. "good_type": goodTypes,
  7424. "total": total,
  7425. "prescribe": prescribe,
  7426. "good_info": good_info,
  7427. "project": project,
  7428. "warehouseOutList": warehouseOutList,
  7429. "config": config,
  7430. "outConfig": outConfig,
  7431. "settleConfig": settleConfig,
  7432. })
  7433. return
  7434. } else {
  7435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7436. return
  7437. }
  7438. } else if err != nil {
  7439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7440. return
  7441. }
  7442. }
  7443. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7444. start_time := c.GetString("start_time")
  7445. end_time := c.GetString("end_time")
  7446. timeLayout := "2006-01-02"
  7447. loc, _ := time.LoadLocation("Local")
  7448. var theStartTime int64
  7449. if len(start_time) > 0 {
  7450. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7451. if err != nil {
  7452. utils.ErrorLog(err.Error())
  7453. }
  7454. theStartTime = theTime.Unix()
  7455. }
  7456. var theEndtTime int64
  7457. if len(end_time) > 0 {
  7458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7459. if err != nil {
  7460. utils.ErrorLog(err.Error())
  7461. }
  7462. theEndtTime = theTime.Unix()
  7463. }
  7464. adminUser := c.GetMobileAdminUserInfo()
  7465. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7466. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7467. if err == nil {
  7468. c.ServeSuccessJSON(map[string]interface{}{
  7469. "stock_out": outInfo,
  7470. "stockCount": stockCount,
  7471. })
  7472. return
  7473. } else {
  7474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7475. return
  7476. }
  7477. }
  7478. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7479. patient_id, _ := c.GetInt64("patient_id", 0)
  7480. record_time := c.GetString("record_time")
  7481. adminUser := c.GetMobileAdminUserInfo()
  7482. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7483. if parseDateErr != nil && len(record_time) != 0 {
  7484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7485. return
  7486. }
  7487. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7488. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7489. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7490. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7491. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7492. //获取今日患者的透析处方参数
  7493. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7494. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7495. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7496. c.ServeSuccessJSON(map[string]interface{}{
  7497. "good_type": goodTypes,
  7498. "good_user": goodUser,
  7499. "good_info": good_info,
  7500. "last_good_user": lastGoodUserDetial,
  7501. "project": project,
  7502. "prescription": prescribe,
  7503. "outInfo": outInfo,
  7504. "configs": configs,
  7505. })
  7506. return
  7507. }
  7508. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7509. patient_id, _ := c.GetInt64("patient_id", 0)
  7510. record_date := c.GetString("record_time")
  7511. timeLayout := "2006-01-02"
  7512. loc, _ := time.LoadLocation("Local")
  7513. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7514. record_time := theRecordTime.Unix()
  7515. adminInfo := c.GetMobileAdminUserInfo()
  7516. dataBody := make(map[string]interface{}, 0)
  7517. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7518. if err != nil {
  7519. utils.ErrorLog(err.Error())
  7520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7521. return
  7522. }
  7523. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7524. var beforePrepares []*models.DialysisBeforePrepareGoods
  7525. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7526. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7527. goods, _ := dataBody["goods"].([]interface{})
  7528. if len(goods) > 0 {
  7529. for _, item := range goods {
  7530. items := item.(map[string]interface{})
  7531. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7532. utils.ErrorLog("good_id")
  7533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7534. return
  7535. }
  7536. good_id := int64(items["good_id"].(float64))
  7537. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7538. utils.ErrorLog("good_type_id")
  7539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7540. return
  7541. }
  7542. good_type_id := int64(items["good_type_id"].(float64))
  7543. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7544. utils.ErrorLog("count")
  7545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7546. return
  7547. }
  7548. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7549. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7550. utils.ErrorLog("project_id")
  7551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7552. return
  7553. }
  7554. project_id := int64(items["project_id"].(float64))
  7555. new_count := int64(items["new_count"].(float64))
  7556. old_count := int64(items["old_count"].(float64))
  7557. prepare := &models.DialysisBeforePrepareGoods{
  7558. GoodId: good_id,
  7559. GoodTypeId: good_type_id,
  7560. Count: count,
  7561. ProjectId: project_id,
  7562. StorehouseId: houseConfig.StorehouseOutInfo,
  7563. NewCount: new_count,
  7564. OldCount: old_count,
  7565. }
  7566. beforePrepares = append(beforePrepares, prepare)
  7567. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7568. GoodId: good_id,
  7569. GoodTypeId: good_type_id,
  7570. Count: count,
  7571. ProjectId: project_id,
  7572. StorehouseId: houseConfig.StorehouseOutInfo,
  7573. NewCount: new_count,
  7574. OldCount: old_count,
  7575. }
  7576. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7577. }
  7578. }
  7579. }
  7580. //查询是否有库存
  7581. for _, item := range beforePrepares {
  7582. if item.NewCount > 0 {
  7583. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7584. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7585. if item.Count > warehouse.Count {
  7586. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7587. c.ServeSuccessJSON(map[string]interface{}{
  7588. "message": "1",
  7589. "good_name": goodObj.GoodName,
  7590. "specification_name": goodObj.SpecificationName,
  7591. })
  7592. return
  7593. }
  7594. }
  7595. }
  7596. // 查询信息规挡的设置天数
  7597. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7598. if infor.ID > 0 && infor.WeekDay > 0 {
  7599. var cha_time int64
  7600. timeNowStr := time.Now().Format("2006-01-02")
  7601. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7602. //今日的日期减去设置的日期
  7603. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7604. if cha_time >= record_time {
  7605. //查询审核是否允许
  7606. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7607. //申请状态不允许的情况 拒绝修改
  7608. if infor.ApplicationStatus != 1 {
  7609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7610. return
  7611. }
  7612. }
  7613. }
  7614. //出库逻辑
  7615. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7616. if err != nil {
  7617. utils.ErrorLog(err.Error())
  7618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7619. return
  7620. }
  7621. finish := models.XtDialysisFinish{
  7622. IsFinish: 1,
  7623. UserOrgId: adminInfo.Org.Id,
  7624. Status: 1,
  7625. Ctime: time.Now().Unix(),
  7626. Mtime: 0,
  7627. Module: 11,
  7628. RecordDate: record_time,
  7629. Sourse: 1,
  7630. PatientId: patient_id,
  7631. }
  7632. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7633. if dialysisFinish.ID == 0 {
  7634. service.CreateDialysisFinish(finish)
  7635. }
  7636. //查询当天出库的数据
  7637. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7638. for _, item := range list {
  7639. prepare := models.DialysisBeforePrepare{
  7640. UserOrgId: item.OrgId,
  7641. PatientId: item.PatientId,
  7642. RecordDate: item.RecordTime,
  7643. GoodId: item.GoodId,
  7644. GoodTypeId: item.GoodTypeId,
  7645. Count: item.Count,
  7646. Creater: adminInfo.AdminUser.Id,
  7647. Status: 1,
  7648. Ctime: time.Now().Unix(),
  7649. ProjectId: item.ProjectId,
  7650. StorehouseId: houseConfig.StorehouseOutInfo,
  7651. }
  7652. //清空准备表的数据
  7653. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7654. //插入准备表数据
  7655. service.CreateDialysisBeforePrepareOne(&prepare)
  7656. //查询默认仓库
  7657. //查询默认仓库
  7658. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7659. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7660. var total_count int64
  7661. for _, it := range stockList {
  7662. total_count += it.StockCount
  7663. }
  7664. //基础库插入数据
  7665. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7666. ////更新剩余库存
  7667. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7668. var flush_count int64
  7669. for _, it := range goodList {
  7670. flush_count += it.StockCount
  7671. }
  7672. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7673. if errs != nil {
  7674. goodErrcode := models.XtGoodErrcode{
  7675. UserOrgId: item.OrgId,
  7676. Errcode: "手动出库更新剩余出库失败",
  7677. GoodId: item.GoodId,
  7678. Status: 1,
  7679. Ctime: time.Now().Unix(),
  7680. Mtime: 0,
  7681. Count: 0,
  7682. StockCount: 0,
  7683. Creater: adminInfo.AdminUser.Id,
  7684. BatchNumberId: 0,
  7685. WarehouseOutId: 0,
  7686. }
  7687. service.CreateGoodErrcode(goodErrcode)
  7688. }
  7689. }
  7690. //更新自动出库的地方
  7691. var errs error
  7692. if errs == nil {
  7693. c.ServeSuccessJSON(map[string]interface{}{
  7694. "msg": "修改成功",
  7695. "message": "2",
  7696. "good_name": "",
  7697. "specification_name": "",
  7698. })
  7699. return
  7700. } else {
  7701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7702. return
  7703. }
  7704. }
  7705. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7706. newArr = make([]*models.DialysisBeforePrepare, 0)
  7707. for i := 0; i < len(arr); i++ {
  7708. repeat := false
  7709. for j := i + 1; j < len(arr); j++ {
  7710. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7711. repeat = true
  7712. break
  7713. }
  7714. }
  7715. if !repeat {
  7716. newArr = append(newArr, arr[i])
  7717. }
  7718. }
  7719. return
  7720. }
  7721. func (c *DialysisAPIController) GetAllDrug() {
  7722. patient_id, _ := c.GetInt64("patient_id", 0)
  7723. adminInfo := c.GetMobileAdminUserInfo()
  7724. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7725. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7726. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7727. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7728. c.ServeSuccessJSON(map[string]interface{}{
  7729. "base_drug_config": drugStockConfig,
  7730. "private_drug_config": privateDrugConfig,
  7731. "base_drug_list": drugList,
  7732. "private_drug_list": privateDrugList,
  7733. })
  7734. }
  7735. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7736. newArr = make([]*models.DialysisBeforePrepare, 0)
  7737. for i := 0; i < len(arr); i++ {
  7738. repeat := false
  7739. for j := i + 1; j < len(arr); j++ {
  7740. if arr[i].GoodId == arr[j].GoodId {
  7741. repeat = true
  7742. break
  7743. }
  7744. }
  7745. if !repeat {
  7746. newArr = append(newArr, arr[i])
  7747. }
  7748. }
  7749. return
  7750. }
  7751. func (c *DialysisAPIController) GetDepartment() {
  7752. adminInfo := c.GetMobileAdminUserInfo()
  7753. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7754. if err == nil {
  7755. c.ServeSuccessJSON(map[string]interface{}{
  7756. "departments": departments,
  7757. })
  7758. } else {
  7759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7760. return
  7761. }
  7762. }
  7763. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7764. types, _ := c.GetInt("type", 0)
  7765. start_time := c.GetString("start_time")
  7766. end_time := c.GetString("end_time")
  7767. orgId := c.GetMobileAdminUserInfo().Org.Id
  7768. timeLayout := "2006-01-02"
  7769. loc, _ := time.LoadLocation("Local")
  7770. var startTime int64
  7771. if len(start_time) > 0 {
  7772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7773. if err != nil {
  7774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7775. return
  7776. }
  7777. startTime = theTime.Unix()
  7778. }
  7779. var endTime int64
  7780. if len(end_time) > 0 {
  7781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7782. if err != nil {
  7783. utils.ErrorLog(err.Error())
  7784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7785. return
  7786. }
  7787. endTime = theTime.Unix()
  7788. }
  7789. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7790. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7791. if err != nil {
  7792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7793. } else {
  7794. c.ServeSuccessJSON(map[string]interface{}{
  7795. "list": list,
  7796. "type": types,
  7797. "stockTotal": stockTotal,
  7798. })
  7799. }
  7800. }
  7801. func (c *DialysisAPIController) GetPrescriptionList() {
  7802. start_time := c.GetString("start_time")
  7803. end_time := c.GetString("end_time")
  7804. schedule_type, _ := c.GetInt64("schedule_type")
  7805. partion_id, _ := c.GetInt64("partion_id")
  7806. orgId := c.GetMobileAdminUserInfo().Org.Id
  7807. timeLayout := "2006-01-02"
  7808. loc, _ := time.LoadLocation("Local")
  7809. var startTime int64
  7810. if len(start_time) > 0 {
  7811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7812. if err != nil {
  7813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7814. return
  7815. }
  7816. startTime = theTime.Unix()
  7817. }
  7818. var endTime int64
  7819. if len(end_time) > 0 {
  7820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7821. if err != nil {
  7822. utils.ErrorLog(err.Error())
  7823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7824. return
  7825. }
  7826. endTime = theTime.Unix()
  7827. }
  7828. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7829. fmt.Println("schedulelist22222222", schedulelist)
  7830. c.ServeSuccessJSON(map[string]interface{}{
  7831. "list": schedulelist,
  7832. })
  7833. return
  7834. }
  7835. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7836. ids := c.GetString("ids")
  7837. //patient_id, _ := c.GetInt64("patient_id")
  7838. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7839. idArray := strings.Split(ids, ",")
  7840. err := service.BatchDeleteMonitor(idArray)
  7841. fmt.Print("err", err)
  7842. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7843. //redis := service.RedisClient()
  7844. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7845. //redis.Set(key, "", time.Second)
  7846. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7847. //redis.Set(keyOne, "", time.Second)
  7848. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7849. //redis.Close()
  7850. c.ServeSuccessJSON(map[string]interface{}{
  7851. "msg": "批量删除成功",
  7852. })
  7853. return
  7854. }
  7855. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7856. id, _ := c.GetInt64("id")
  7857. timeLayout := "2006-01-02"
  7858. loc, _ := time.LoadLocation("Local")
  7859. //start_time := time.Now().Format("2006-01-02")
  7860. start_time := c.GetString("start_time")
  7861. end_time := c.GetString("end_time")
  7862. var startdateunix int64
  7863. if len(start_time) > 0 {
  7864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7865. if err != nil {
  7866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7867. return
  7868. }
  7869. startdateunix = theTime.Unix()
  7870. }
  7871. var enddateunix int64
  7872. if len(end_time) > 0 {
  7873. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7874. if err != nil {
  7875. utils.ErrorLog(err.Error())
  7876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7877. return
  7878. }
  7879. enddateunix = theTime.Unix()
  7880. }
  7881. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7882. //nowTime := time.Now()
  7883. //endTime := nowTime.AddDate(-30, 0, 0)
  7884. //endTimes := endTime.Format("2006-01-02")
  7885. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7886. org_id := c.GetMobileAdminUserInfo().Org.Id
  7887. //if org_id == 10579 {
  7888. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7889. // c.ServeSuccessJSON(map[string]interface{}{
  7890. // "list": list,
  7891. // })
  7892. // return
  7893. //} else {
  7894. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7895. // c.ServeSuccessJSON(map[string]interface{}{
  7896. // "list": list,
  7897. // })
  7898. // return
  7899. //}
  7900. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7901. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7902. c.ServeSuccessJSON(map[string]interface{}{
  7903. "list": list,
  7904. })
  7905. return
  7906. } else {
  7907. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7908. c.ServeSuccessJSON(map[string]interface{}{
  7909. "list": list,
  7910. })
  7911. }
  7912. return
  7913. }
  7914. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7915. dataBody := make(map[string]interface{}, 0)
  7916. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7917. ids := c.GetString("ids")
  7918. idArray := strings.Split(ids, ",")
  7919. origin, _ := c.GetInt64("origin")
  7920. if origin == 1 {
  7921. err = service.BatchDeleteAdvice(idArray)
  7922. fmt.Print("err", err)
  7923. c.ServeSuccessJSON(map[string]interface{}{
  7924. "msg": "批量删除成功",
  7925. })
  7926. return
  7927. }
  7928. if origin == 2 {
  7929. service.BatchDeleteHisAdvice(idArray)
  7930. }
  7931. }
  7932. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7933. good_id, _ := c.GetInt64("good_id")
  7934. count, _ := c.GetInt64("count")
  7935. record_time, _ := c.GetInt64("record_time")
  7936. patient_id, _ := c.GetInt64("patient_id")
  7937. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7938. c.ServeSuccessJSON(map[string]interface{}{
  7939. "detail": detail,
  7940. })
  7941. return
  7942. }
  7943. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7944. good_id, _ := c.GetInt64("good_id")
  7945. record_time, _ := c.GetInt64("record_time")
  7946. patient_id, _ := c.GetInt64("patient_id")
  7947. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7948. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7949. fmt.Print("err", err)
  7950. c.ServeSuccessJSON(map[string]interface{}{
  7951. "msg": "批量删除成功",
  7952. })
  7953. return
  7954. }
  7955. func (c *DialysisAPIController) BatchAdviceCheck() {
  7956. ids := c.GetString("ids")
  7957. idArray := strings.Split(ids, ",")
  7958. creator, _ := c.GetInt64("creator")
  7959. origin, _ := c.GetInt64("origin")
  7960. if origin == 1 {
  7961. err := service.BatchAdviceCheck(idArray, creator)
  7962. fmt.Println(err)
  7963. list, _ := service.GetAdviceExecutionById(idArray)
  7964. c.ServeSuccessJSON(map[string]interface{}{
  7965. "list": list,
  7966. })
  7967. return
  7968. }
  7969. if origin == 2 {
  7970. service.BatchHisAdviceCheck(idArray, creator)
  7971. list, _ := service.GetHisAdviceExecutionById(idArray)
  7972. c.ServeSuccessJSON(map[string]interface{}{
  7973. "list": list,
  7974. })
  7975. return
  7976. }
  7977. }
  7978. func (c *DialysisAPIController) BatchAdviceExecution() {
  7979. ids := c.GetString("ids")
  7980. idArray := strings.Split(ids, ",")
  7981. executionTime := c.GetString("execution_time")
  7982. creator, _ := c.GetInt64("creator")
  7983. timeLayout := "2006-01-02 15:04:05"
  7984. loc, _ := time.LoadLocation("Local")
  7985. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7986. orgin, _ := c.GetInt64("origin")
  7987. if orgin == 1 {
  7988. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7989. list, _ := service.GetAdviceExecutionById(idArray)
  7990. fmt.Println(err)
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "list": list,
  7993. })
  7994. return
  7995. }
  7996. if orgin == 2 {
  7997. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7998. list, _ := service.GetHisAdviceExecutionById(idArray)
  7999. fmt.Println(err)
  8000. c.ServeSuccessJSON(map[string]interface{}{
  8001. "list": list,
  8002. })
  8003. return
  8004. }
  8005. }
  8006. func (c *DialysisAPIController) UpdateStockGoods() {
  8007. good_id, _ := c.GetInt64("good_id")
  8008. record_time, _ := c.GetInt64("record_time")
  8009. patient_id, _ := c.GetInt64("patient_id")
  8010. count, _ := c.GetInt64("count")
  8011. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8012. fmt.Print("err", err)
  8013. c.ServeSuccessJSON(map[string]interface{}{
  8014. "msg": "更新成功",
  8015. })
  8016. return
  8017. }
  8018. // 当前数据比上一次出库数据少
  8019. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8020. //查询该患者当天已经出库的耗材信息
  8021. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8022. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8023. for i := len(goods_yc) - 1; i >= 0; i-- {
  8024. goods_yc_temp := goods_yc[i]
  8025. for j := len(goods) - 1; j >= 0; j-- {
  8026. goods_temp := goods[j]
  8027. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8028. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8029. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8030. if goods_yc_temp.Count == goods_temp.Count {
  8031. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8032. goods = append(goods[:j], goods[j+1:]...)
  8033. break
  8034. }
  8035. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8036. if goods_yc_temp.Count > goods_temp.Count {
  8037. temp_count := goods_yc_temp.Count - goods_temp.Count
  8038. goods_yc[i].Count = temp_count
  8039. goods = append(goods[:j], goods[j+1:]...)
  8040. break
  8041. }
  8042. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8043. if goods_yc_temp.Count < goods_temp.Count {
  8044. temp_count := goods_temp.Count - goods_yc_temp.Count
  8045. goods[j].Count = temp_count
  8046. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8047. break
  8048. }
  8049. }
  8050. }
  8051. }
  8052. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8053. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8054. //退库
  8055. if len(goods_yc) > 0 {
  8056. for _, good_yc := range goods_yc {
  8057. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8058. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8059. }
  8060. }
  8061. return nil
  8062. }
  8063. // 耗材出库删除
  8064. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8065. // 先根据相关信息查询当天该耗材的出库信息
  8066. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8067. if err != nil {
  8068. return err
  8069. }
  8070. var delete_count int64 = 0
  8071. delete_count = warehouseOutInfos.Count - count
  8072. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8073. // 在出库记录表里记录退库详情
  8074. warehouseOutInfo := &models.WarehouseOutInfo{
  8075. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8076. WarehouseOutId: warehouseOut.ID,
  8077. Status: 1,
  8078. Ctime: time.Now().Unix(),
  8079. OrgId: orgID,
  8080. Type: 1,
  8081. IsSys: 1,
  8082. SysRecordTime: record_time,
  8083. GoodTypeId: good_yc.GoodTypeId,
  8084. GoodId: good_yc.GoodId,
  8085. PatientId: good_yc.PatientId,
  8086. ConsumableType: 2,
  8087. StorehouseId: houseConfig.StorehouseOutInfo,
  8088. IsCheck: 1,
  8089. }
  8090. warehouseOutInfo.Count = count
  8091. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8092. warehouseOutInfo.Price = stockInInfo.Price
  8093. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8094. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8095. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8096. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8097. warehouseOutInfo.Number = warehouseOutInfos.Number
  8098. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8099. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8100. //查找当天是否存在出库记录
  8101. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8102. if errcod == gorm.ErrRecordNotFound {
  8103. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8104. //插入详情明细表
  8105. stockFlow := models.VmStockFlow{
  8106. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8107. WarehouseOutId: warehouseOut.ID,
  8108. GoodId: good_yc.GoodId,
  8109. Number: warehouseOutInfos.Number,
  8110. ProductDate: stockInInfo.ProductDate,
  8111. ExpireDate: stockInInfo.ExpiryDate,
  8112. Count: count,
  8113. Price: stockInInfo.Price,
  8114. Status: 1,
  8115. Ctime: time.Now().Unix(),
  8116. UserOrgId: good_yc.OrgId,
  8117. Manufacturer: stockInInfo.Manufacturer,
  8118. Dealer: stockInInfo.Dealer,
  8119. LicenseNumber: stockInInfo.LicenseNumber,
  8120. IsEdit: 2,
  8121. Creator: creater,
  8122. SystemTime: record_time,
  8123. ConsumableType: 3,
  8124. WarehousingDetailId: 0,
  8125. IsSys: 1,
  8126. UpdateCreator: creater,
  8127. PatientId: patient_id,
  8128. StorehouseId: houseConfig.StorehouseOutInfo,
  8129. }
  8130. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8131. if errflow == gorm.ErrRecordNotFound {
  8132. //创建流水表
  8133. err := service.CreateStockFlowOne(stockFlow)
  8134. fmt.Println("err", err)
  8135. } else if errflow == nil {
  8136. //插入详情明细表
  8137. stockFlow := models.VmStockFlow{
  8138. ID: exsit.ID,
  8139. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8140. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8141. WarehouseOutId: warehouseOut.ID,
  8142. GoodId: good_yc.GoodId,
  8143. Number: warehouseOutInfos.Number,
  8144. ProductDate: stockInInfo.ProductDate,
  8145. ExpireDate: stockInInfo.ExpiryDate,
  8146. Count: exsit.Count - delete_count,
  8147. Price: stockInInfo.Price,
  8148. Status: 1,
  8149. Ctime: time.Now().Unix(),
  8150. UserOrgId: good_yc.OrgId,
  8151. Manufacturer: stockInInfo.Manufacturer,
  8152. Dealer: stockInInfo.Dealer,
  8153. LicenseNumber: stockInInfo.LicenseNumber,
  8154. IsEdit: 2,
  8155. Creator: creater,
  8156. SystemTime: record_time,
  8157. ConsumableType: 3,
  8158. WarehousingDetailId: 0,
  8159. IsSys: 1,
  8160. UpdateCreator: creater,
  8161. PatientId: patient_id,
  8162. StorehouseId: houseConfig.StorehouseOutInfo,
  8163. }
  8164. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8165. }
  8166. if errOne != nil {
  8167. return errOne
  8168. }
  8169. } else if errcod == nil {
  8170. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8171. //插入详情明细表
  8172. stockFlow := models.VmStockFlow{
  8173. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8174. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8175. WarehouseOutId: warehouseOut.ID,
  8176. GoodId: good_yc.GoodId,
  8177. Number: warehouseOutInfos.Number,
  8178. ProductDate: stockInInfo.ProductDate,
  8179. ExpireDate: stockInInfo.ExpiryDate,
  8180. Count: count,
  8181. Price: stockInInfo.Price,
  8182. Status: 1,
  8183. Ctime: time.Now().Unix(),
  8184. UserOrgId: good_yc.OrgId,
  8185. Manufacturer: stockInInfo.Manufacturer,
  8186. Dealer: stockInInfo.Dealer,
  8187. LicenseNumber: stockInInfo.LicenseNumber,
  8188. IsEdit: 2,
  8189. Creator: creater,
  8190. SystemTime: record_time,
  8191. ConsumableType: 3,
  8192. WarehousingDetailId: 0,
  8193. IsSys: 1,
  8194. UpdateCreator: creater,
  8195. PatientId: patient_id,
  8196. ReturnCount: delete_count,
  8197. StorehouseId: houseConfig.StorehouseOutInfo,
  8198. }
  8199. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8200. if errflows == gorm.ErrRecordNotFound {
  8201. //创建流水表
  8202. service.CreateStockFlowOne(stockFlow)
  8203. } else if errflows == nil {
  8204. stockFlow := models.VmStockFlow{
  8205. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8206. ID: exsit.ID,
  8207. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8208. WarehouseOutId: warehouseOut.ID,
  8209. GoodId: good_yc.GoodId,
  8210. Number: warehouseOutInfos.Number,
  8211. ProductDate: stockInInfo.ProductDate,
  8212. ExpireDate: stockInInfo.ExpiryDate,
  8213. Count: exsit.Count - delete_count,
  8214. Price: stockInInfo.Price,
  8215. Status: 1,
  8216. Ctime: time.Now().Unix(),
  8217. UserOrgId: good_yc.OrgId,
  8218. Manufacturer: stockInInfo.Manufacturer,
  8219. Dealer: stockInInfo.Dealer,
  8220. LicenseNumber: stockInInfo.LicenseNumber,
  8221. IsEdit: 2,
  8222. Creator: creater,
  8223. SystemTime: record_time,
  8224. ConsumableType: 3,
  8225. WarehousingDetailId: 0,
  8226. IsSys: 1,
  8227. UpdateCreator: creater,
  8228. PatientId: patient_id,
  8229. ReturnCount: delete_count,
  8230. StorehouseId: houseConfig.StorehouseOutInfo,
  8231. }
  8232. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8233. }
  8234. }
  8235. //更改自动出库的表格
  8236. details := models.BloodAutomaticReduceDetail{
  8237. WarehouseOutId: warehouseOutInfo.ID,
  8238. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8239. PatientId: patient_id,
  8240. Ctime: time.Now().Unix(),
  8241. Mtime: time.Now().Unix(),
  8242. Status: 1,
  8243. RecordTime: record_time,
  8244. OrgId: orgID,
  8245. GoodId: good_yc.GoodId,
  8246. GoodTypeId: good_yc.GoodTypeId,
  8247. Count: count,
  8248. StorehouseId: houseConfig.StorehouseOutInfo,
  8249. }
  8250. //查询当天耗材是否已经存在数据
  8251. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8252. if errcode == gorm.ErrRecordNotFound {
  8253. errTwo := service.CreateAutoReduceRecord(&details)
  8254. if errTwo != nil {
  8255. return errTwo
  8256. }
  8257. } else if errcode == nil {
  8258. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8259. service.CreateAutoReduceRecord(&details)
  8260. }
  8261. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8262. //增加出库库存数量
  8263. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8264. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8265. fmt.Println("errOne", errOne)
  8266. // 删除出库完成后,要增加对应批次的库存数量
  8267. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8268. if errThree != nil {
  8269. return errThree
  8270. }
  8271. if good_yc.Count == 0 {
  8272. return nil
  8273. } else {
  8274. return errors.New("退库和出库数据不匹配")
  8275. }
  8276. }
  8277. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8278. //查询该患者当天已经出库的耗材信息
  8279. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8280. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8281. for i := len(goods_yc) - 1; i >= 0; i-- {
  8282. goods_yc_temp := goods_yc[i]
  8283. for j := len(goods) - 1; j >= 0; j-- {
  8284. goods_temp := goods[j]
  8285. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8286. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8287. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8288. if goods_yc_temp.Count == goods_temp.Count {
  8289. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8290. goods = append(goods[:j], goods[j+1:]...)
  8291. break
  8292. }
  8293. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8294. if goods_yc_temp.Count > goods_temp.Count {
  8295. temp_count := goods_yc_temp.Count - goods_temp.Count
  8296. goods_yc[i].Count = temp_count
  8297. goods = append(goods[:j], goods[j+1:]...)
  8298. break
  8299. }
  8300. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8301. if goods_yc_temp.Count < goods_temp.Count {
  8302. temp_count := goods_temp.Count - goods_yc_temp.Count
  8303. goods[j].Count = temp_count
  8304. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8305. break
  8306. }
  8307. }
  8308. }
  8309. }
  8310. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8311. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8312. fmt.Println("剩余需要出库的", len(goods))
  8313. if len(goods) > 0 {
  8314. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8315. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8316. if err == gorm.ErrRecordNotFound {
  8317. //没有记录,则创建出库单
  8318. timeStr := time.Now().Format("2006-01-02")
  8319. timeArr := strings.Split(timeStr, "-")
  8320. total, _ := service.FindAllWarehouseOut(orgID)
  8321. total = total + 1
  8322. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8323. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8324. number = number + total
  8325. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8326. warehouseOut := models.WarehouseOut{
  8327. WarehouseOutOrderNumber: warehousing_out_order,
  8328. OperationTime: time.Now().Unix(),
  8329. OrgId: orgID,
  8330. Creater: creater,
  8331. Ctime: time.Now().Unix(),
  8332. Status: 1,
  8333. WarehouseOutTime: record_time,
  8334. Dealer: 0,
  8335. Manufacturer: 0,
  8336. Type: 1,
  8337. IsSys: 1,
  8338. StorehouseId: houseConfig.StorehouseOutInfo,
  8339. IsCheck: 1,
  8340. }
  8341. err := service.AddSigleWarehouseOut(&warehouseOut)
  8342. if err != nil {
  8343. utils.TraceLog("创建出库单失败 err = %v", err)
  8344. return err
  8345. } else {
  8346. out = warehouseOut
  8347. }
  8348. }
  8349. for _, item := range goods {
  8350. var newCount int64 = 0
  8351. for _, it := range goodOne {
  8352. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8353. newCount = it.Count
  8354. }
  8355. }
  8356. prepare := models.DialysisBeforePrepare{
  8357. GoodTypeId: item.GoodTypeId,
  8358. GoodId: item.GoodId,
  8359. Count: item.Count,
  8360. StorehouseId: houseConfig.StorehouseOutInfo,
  8361. }
  8362. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8363. //增加出库数量
  8364. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8365. }
  8366. }
  8367. if len(goods_yc) > 0 {
  8368. for _, good_yc := range goods_yc {
  8369. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8370. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8371. }
  8372. }
  8373. return nil
  8374. }
  8375. // 耗材出库删除
  8376. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8377. // 先根据相关信息查询当天该耗材的出库信息
  8378. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8379. if err != nil {
  8380. return err
  8381. }
  8382. var delete_count int64 = 0
  8383. for _, ware := range warehouseOutInfos {
  8384. // 判断当前出库的数据和删除出库数量
  8385. if good_yc.Count <= ware.Count {
  8386. delete_count = good_yc.Count
  8387. } else {
  8388. delete_count = ware.Count
  8389. }
  8390. warehouseOutInfo := &models.WarehouseOutInfo{
  8391. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8392. WarehouseOutId: warehouseOut.ID,
  8393. Status: 1,
  8394. Ctime: time.Now().Unix(),
  8395. Remark: "",
  8396. OrgId: orgID,
  8397. Type: 1,
  8398. Manufacturer: 0,
  8399. Dealer: 0,
  8400. IsSys: 0,
  8401. SysRecordTime: record_time,
  8402. GoodTypeId: good_yc.GoodTypeId,
  8403. GoodId: good_yc.GoodId,
  8404. StorehouseId: warehouseOut.StorehouseId,
  8405. IsCheck: 1,
  8406. }
  8407. warehouseOutInfo.Count = delete_count
  8408. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8409. warehouseOutInfo.Price = stockInInfo.Price
  8410. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8411. if errOne != nil {
  8412. return errOne
  8413. }
  8414. // 删除出库完成后,要改变流水库存(有疑问)
  8415. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8416. fmt.Println("errOne", errOne)
  8417. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8418. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8419. //扣减出库数量
  8420. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8421. if errThree != nil {
  8422. return errThree
  8423. }
  8424. }
  8425. if good_yc.Count == 0 {
  8426. return nil
  8427. } else {
  8428. return errors.New("退库和出库数据不匹配")
  8429. }
  8430. }
  8431. func (this *DialysisAPIController) GetMobileScheduleList() {
  8432. limit, _ := this.GetInt64("limit")
  8433. page, _ := this.GetInt64("page")
  8434. type_options_visible, _ := this.GetInt64("type_options_visible")
  8435. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8436. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8437. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8438. }
  8439. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8440. newArr = make([]*models.HisPrescriptionProject, 0)
  8441. for i := 0; i < len(arr); i++ {
  8442. repeat := false
  8443. for j := i + 1; j < len(arr); j++ {
  8444. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8445. repeat = true
  8446. break
  8447. }
  8448. }
  8449. if !repeat {
  8450. newArr = append(newArr, arr[i])
  8451. }
  8452. }
  8453. return
  8454. }
  8455. func (this *DialysisAPIController) GetRoleList() {
  8456. admin_user_id, _ := this.GetInt64("admin_user_id")
  8457. orgid := this.GetMobileAdminUserInfo().Org.Id
  8458. list, err := service.GetRoleList(orgid, admin_user_id)
  8459. fmt.Println(err)
  8460. this.ServeSuccessJSON(map[string]interface{}{
  8461. "list": list,
  8462. })
  8463. return
  8464. }
  8465. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8466. // 先根据相关信息查询当天该耗材的出库信息
  8467. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8468. if err != nil {
  8469. return err
  8470. }
  8471. var delete_count int64 = 0
  8472. delete_count = warehouseOutInfos.Count - count
  8473. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8474. // 删除出库完成后,要增加对应批次的库存数量
  8475. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8476. if errThree != nil {
  8477. return errThree
  8478. }
  8479. //增加退库数量
  8480. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8481. //扣减出库数量
  8482. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8483. //查询剩余库存
  8484. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8485. var sum_count int64
  8486. for _, item := range goodList {
  8487. sum_count += item.StockCount
  8488. }
  8489. // 在出库记录表里记录退库详情
  8490. warehouseOutInfo := &models.WarehouseOutInfo{
  8491. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8492. WarehouseOutId: warehouseOut.ID,
  8493. Status: 1,
  8494. Ctime: time.Now().Unix(),
  8495. OrgId: orgID,
  8496. Type: 1,
  8497. IsSys: 1,
  8498. SysRecordTime: record_time,
  8499. GoodTypeId: good_yc.GoodTypeId,
  8500. GoodId: good_yc.GoodId,
  8501. PatientId: good_yc.PatientId,
  8502. ConsumableType: 2,
  8503. StorehouseId: houseConfig.StorehouseOutInfo,
  8504. IsCheck: 1,
  8505. OverCount: sum_count,
  8506. }
  8507. warehouseOutInfo.Count = count
  8508. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8509. warehouseOutInfo.Price = stockInInfo.Price
  8510. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8511. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8512. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8513. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8514. warehouseOutInfo.Number = warehouseOutInfos.Number
  8515. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8516. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8517. //查找当天是否存在出库记录
  8518. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8519. if errcod == gorm.ErrRecordNotFound {
  8520. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8521. //插入详情明细表
  8522. if errOne != nil {
  8523. return errOne
  8524. }
  8525. //插入详情明细表
  8526. stockFlow := models.VmStockFlow{
  8527. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8528. WarehouseOutId: warehouseOut.ID,
  8529. GoodId: good_yc.GoodId,
  8530. Number: warehouseOutInfos.Number,
  8531. ProductDate: stockInInfo.ProductDate,
  8532. ExpireDate: stockInInfo.ExpiryDate,
  8533. Count: count,
  8534. Price: stockInInfo.Price,
  8535. Status: 1,
  8536. Ctime: record_time,
  8537. UserOrgId: good_yc.OrgId,
  8538. Manufacturer: stockInInfo.Manufacturer,
  8539. Dealer: stockInInfo.Dealer,
  8540. LicenseNumber: stockInInfo.LicenseNumber,
  8541. IsEdit: 2,
  8542. Creator: creater,
  8543. SystemTime: record_time,
  8544. ConsumableType: 3,
  8545. WarehousingDetailId: 0,
  8546. IsSys: 1,
  8547. UpdateCreator: creater,
  8548. PatientId: patient_id,
  8549. StorehouseId: houseConfig.StorehouseOutInfo,
  8550. OverCount: sum_count,
  8551. ProjectId: good_yc.ProjectId,
  8552. }
  8553. err := service.CreateStockFlowOne(stockFlow)
  8554. fmt.Println("err", err)
  8555. } else if errcod == nil {
  8556. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8557. }
  8558. //创建退库单
  8559. operation_time := time.Now().Unix()
  8560. //创建退库单
  8561. timeStr := time.Now().Format("2006-01-02")
  8562. timeArr := strings.Split(timeStr, "-")
  8563. total, _ := service.FindAllCancelStockTotal(orgID)
  8564. total = total + 1
  8565. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8566. cancelStock := models.CancelStock{
  8567. OrderNumber: orderNumber,
  8568. OperaTime: operation_time,
  8569. OrgId: orgID,
  8570. Creater: warehouseOut.Creater,
  8571. Ctime: time.Now().Unix(),
  8572. Status: 1,
  8573. ReturnTime: record_time,
  8574. Type: 1,
  8575. StorehouseId: stockInInfo.StorehouseId,
  8576. IsCheck: 1,
  8577. }
  8578. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8579. if msgerrkonde == gorm.ErrRecordNotFound {
  8580. service.AddSigleCancelStock(&cancelStock)
  8581. }
  8582. cancel, _ := service.GetLastCancelStockById(orgID)
  8583. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8584. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8585. cancelStockInfo := models.CancelStockInfo{
  8586. GoodId: stockInInfo.GoodId,
  8587. CancelStockId: cancel.ID,
  8588. GoodTypeId: stockInInfo.GoodTypeId,
  8589. Count: delete_count,
  8590. Price: stockInInfo.PackingPrice,
  8591. Total: 0,
  8592. ProductDate: stockInInfo.ProductDate,
  8593. ExpiryDate: stockInInfo.ExpiryDate,
  8594. Ctime: record_time,
  8595. Status: 1,
  8596. OrgId: orgID,
  8597. OrderNumber: cancel.OrderNumber,
  8598. Type: 0,
  8599. Dealer: deaerler.DealerName,
  8600. Manufacturer: manufacturer.ManufacturerName,
  8601. Number: stockInInfo.Number,
  8602. RegisterAccount: "",
  8603. Remark: "",
  8604. WarehouseInfoId: stockInInfo.ID,
  8605. PatientId: patient_id,
  8606. RecordDate: record_time,
  8607. StorehouseId: stockInInfo.StorehouseId,
  8608. IsCheck: 1,
  8609. }
  8610. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8611. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8612. flow := models.VmStockFlow{
  8613. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8614. GoodId: good_yc.GoodId,
  8615. Number: warehouseOutInfos.Number,
  8616. LicenseNumber: stockInInfo.LicenseNumber,
  8617. Count: delete_count,
  8618. UserOrgId: orgID,
  8619. PatientId: patient_id,
  8620. SystemTime: record_time,
  8621. ConsumableType: 7,
  8622. IsSys: 0,
  8623. WarehousingOrder: "",
  8624. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8625. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8626. IsEdit: 0,
  8627. CancelStockId: cancel.ID,
  8628. CancelOrderNumber: cancel.OrderNumber,
  8629. Manufacturer: manufacturer.ID,
  8630. Dealer: 0,
  8631. Creator: warehouseOut.Creater,
  8632. UpdateCreator: 0,
  8633. Status: 1,
  8634. Ctime: record_time,
  8635. Mtime: 0,
  8636. Price: stockInInfo.Price,
  8637. WarehousingDetailId: stockInInfo.ID,
  8638. WarehouseOutDetailId: warehouseOutInfos.ID,
  8639. CancelOutDetailId: cancelInfo.ID,
  8640. ProductDate: stockInInfo.ProductDate,
  8641. ExpireDate: stockInInfo.ExpiryDate,
  8642. StorehouseId: houseConfig.StorehouseOutInfo,
  8643. OverCount: sum_count,
  8644. }
  8645. service.CreateStockFlowOne(flow)
  8646. //更改自动出库的表格
  8647. details := models.BloodAutomaticReduceDetail{
  8648. WarehouseOutId: warehouseOutInfo.ID,
  8649. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8650. PatientId: patient_id,
  8651. Ctime: time.Now().Unix(),
  8652. Mtime: time.Now().Unix(),
  8653. Status: 1,
  8654. RecordTime: record_time,
  8655. OrgId: orgID,
  8656. GoodId: good_yc.GoodId,
  8657. GoodTypeId: good_yc.GoodTypeId,
  8658. Count: count,
  8659. StorehouseId: houseConfig.StorehouseOutInfo,
  8660. }
  8661. //查询当天耗材是否已经存在数据
  8662. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8663. if errcode == gorm.ErrRecordNotFound {
  8664. errTwo := service.CreateAutoReduceRecord(&details)
  8665. if errTwo != nil {
  8666. return errTwo
  8667. }
  8668. } else if errcode == nil {
  8669. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8670. service.CreateAutoReduceRecord(&details)
  8671. }
  8672. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8673. //增加出库库存数量
  8674. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8675. if good_yc.Count == 0 {
  8676. return nil
  8677. } else {
  8678. return errors.New("退库和出库数据不匹配")
  8679. }
  8680. }
  8681. func (this *DialysisAPIController) SavePatientSign() {
  8682. adminUserInfo := this.GetMobileAdminUserInfo()
  8683. patient_id, _ := this.GetInt64("patient_id")
  8684. dialysis_date, _ := this.GetInt64("dialysis_date")
  8685. orgid := adminUserInfo.Org.Id
  8686. var esdata models.DialysisOrder
  8687. var err error
  8688. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8690. return
  8691. }
  8692. esdata.Hash = esdata.Hash
  8693. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8694. order := models.DialysisOrder{
  8695. Hash: esdata.Hash,
  8696. Url: esdata.Url,
  8697. }
  8698. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8699. redis := service.RedisClient()
  8700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8701. redis.Set(key, "", time.Second)
  8702. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8703. //清空key 值
  8704. redis.Set(keyOne, "", time.Second)
  8705. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8706. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8707. //redis.Set(keyTwo, "", time.Second)
  8708. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8709. redis.Set(keyThree, "", time.Second)
  8710. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8711. redis.Set(keyFour, "", time.Second)
  8712. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8713. redis.Set(keyFive, "", time.Second)
  8714. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8715. redis.Set(keySix, "", time.Second)
  8716. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8717. redis.Set(keySeven, "", time.Second)
  8718. if err != nil {
  8719. fmt.Println(err)
  8720. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8721. return
  8722. }
  8723. this.ServeSuccessJSON(map[string]interface{}{
  8724. "electronic_signature": esdata,
  8725. })
  8726. }
  8727. func (this *DialysisAPIController) GetPatientSign() {
  8728. patient_id, _ := this.GetInt64("patient_id")
  8729. dialysis_date, _ := this.GetInt64("dialysis_date")
  8730. adminUserInfo := this.GetMobileAdminUserInfo()
  8731. orgId := adminUserInfo.Org.Id
  8732. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8733. if err != nil {
  8734. fmt.Println(err)
  8735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8736. return
  8737. }
  8738. this.ServeSuccessJSON(map[string]interface{}{
  8739. "dialysisOrder": dialysisOrder,
  8740. })
  8741. }
  8742. func (this *DialysisAPIController) GetScheduleByPatient() {
  8743. patient_id, _ := this.GetInt64("patient_id")
  8744. schedule_date, _ := this.GetInt64("schedule_date")
  8745. orgid := this.GetMobileAdminUserInfo().Org.Id
  8746. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8747. this.ServeSuccessJSON(map[string]interface{}{
  8748. "schedule": schedule,
  8749. })
  8750. }
  8751. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8752. org_id := this.GetMobileAdminUserInfo().Org.Id
  8753. patient_id, _ := this.GetInt64("patient_id")
  8754. schedule_date, _ := this.GetInt64("schedule_date")
  8755. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8756. this.ServeSuccessJSON(map[string]interface{}{
  8757. "order": order,
  8758. })
  8759. }
  8760. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8761. org_id := this.GetMobileAdminUserInfo().Org.Id
  8762. schedule_date := this.GetString("schedule_date")
  8763. schedule_type, _ := this.GetInt64("schedule_type")
  8764. timeLayout := "2006-01-02"
  8765. loc, _ := time.LoadLocation("Local")
  8766. var startdateunix int64
  8767. if len(schedule_date) > 0 {
  8768. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8769. if err != nil {
  8770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8771. return
  8772. }
  8773. startdateunix = theTime.Unix()
  8774. }
  8775. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8776. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8777. devices, _ := service.GetAllDevicetByListSix(org_id)
  8778. for key, item := range scheduals {
  8779. // 床位信息
  8780. for _, device := range devices {
  8781. if item.BedId == device.ID {
  8782. scheduals[key].DeviceNumber = device
  8783. break
  8784. }
  8785. }
  8786. }
  8787. this.ServeSuccessJSON(map[string]interface{}{
  8788. "list": list,
  8789. "scheduals": scheduals,
  8790. })
  8791. }
  8792. func (this *DialysisAPIController) SavePatientPicture() {
  8793. patient_id, _ := this.GetInt64("patient_id")
  8794. dialysis_date, _ := this.GetInt64("schedule_date")
  8795. avatar := this.GetString("avatar")
  8796. fmt.Println("patient_id", patient_id)
  8797. orgId := this.GetMobileAdminUserInfo().Org.Id
  8798. order := models.DialysisOrder{
  8799. Url: avatar,
  8800. }
  8801. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8802. redis := service.RedisClient()
  8803. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8804. redis.Set(key, "", time.Second)
  8805. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8806. //清空key 值
  8807. redis.Set(keyOne, "", time.Second)
  8808. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8809. redis.Set(keyThree, "", time.Second)
  8810. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8811. redis.Set(keyFour, "", time.Second)
  8812. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8813. redis.Set(keyFive, "", time.Second)
  8814. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8815. redis.Set(keySix, "", time.Second)
  8816. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8817. redis.Set(keySeven, "", time.Second)
  8818. if err != nil {
  8819. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8820. return
  8821. }
  8822. this.ServeSuccessJSON(map[string]interface{}{
  8823. "order": order,
  8824. })
  8825. }
  8826. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8827. ids := this.GetString("ids")
  8828. idSplit := strings.Split(ids, ",")
  8829. orgId := this.GetMobileAdminUserInfo().Org.Id
  8830. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8831. execution_time := this.GetString("exce_time")
  8832. timeLayout2 := "2006-01-02 15:04:05"
  8833. loc, _ := time.LoadLocation("Local")
  8834. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8835. if errs != nil {
  8836. utils.ErrorLog(errs.Error())
  8837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8838. return
  8839. }
  8840. //his客户
  8841. if config.IsOpen == 1 {
  8842. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8843. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8844. for _, item := range list {
  8845. for _, it := range adviceList {
  8846. if item.DrugId == it.DrugId {
  8847. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8848. }
  8849. }
  8850. }
  8851. for _, item := range list {
  8852. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8853. var sum_out_count int64
  8854. for _, itemThree := range item.ChildDoctorAdvice {
  8855. var prescribing_number int64
  8856. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8857. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8858. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8859. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8860. }
  8861. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8862. prescribing_number = parseIntPrescribingNumber
  8863. }
  8864. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8865. prescribing_number = parseIntPrescribingNumber
  8866. }
  8867. sum_out_count += prescribing_number
  8868. }
  8869. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8870. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8871. //库存不足
  8872. if sum_out_count > drugStockOut.FlushCount {
  8873. this.ServeSuccessJSON(map[string]interface{}{
  8874. "msg": "2",
  8875. "drug": medical,
  8876. "ids": ids,
  8877. })
  8878. return
  8879. }
  8880. }
  8881. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8882. //执行医嘱
  8883. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8884. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8885. for _, item := range advices {
  8886. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8887. redis := service.RedisClient()
  8888. //清空key 值
  8889. redis.Set(key, "", time.Second)
  8890. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8891. redis.Set(keyTwo, "", time.Second)
  8892. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8893. redis.Set(keyThree, "", time.Second)
  8894. recordDate := theTime.Format("2006-01-02")
  8895. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8896. redis.Set(keyFour, "", time.Second)
  8897. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8898. redis.Set(keyFive, "", time.Second)
  8899. defer redis.Close()
  8900. }
  8901. if errs == nil {
  8902. //药品管理信息
  8903. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8904. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8905. if drugStockConfig.IsOpen == 1 {
  8906. for _, item := range advices {
  8907. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8908. config, _ := service.GetDrugOpenConfigOne(orgId)
  8909. if config.IsOpen != 1 {
  8910. //查询该药品是否有库存
  8911. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8912. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8913. if medical.IsUse == 2 {
  8914. if config.IsOpen != 1 {
  8915. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8916. service.HisDrugsDelivery(orgId, creater, &advice)
  8917. if orgId == 3877 || orgId == 10265 {
  8918. //查询该药品是否有出库记录
  8919. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8920. if len(flowMap) == 0 {
  8921. errs := service.UpdateHisAdviceById(advice.ID)
  8922. if errs != nil {
  8923. drugError := models.XtDrugError{
  8924. UserOrgId: orgId,
  8925. DrugId: item.DrugId,
  8926. RecordDate: item.AdviceDate,
  8927. PatientId: item.PatientId,
  8928. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8929. Status: 1,
  8930. Ctime: time.Now().Unix(),
  8931. Mtime: 0,
  8932. SumCount: 0,
  8933. Prescribingnumber: advice.PrescribingNumber,
  8934. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8935. }
  8936. service.CreateDrugError(drugError)
  8937. }
  8938. this.ServeSuccessJSON(map[string]interface{}{
  8939. "msg": "2",
  8940. "drug": medical,
  8941. "ids": ids,
  8942. })
  8943. return
  8944. }
  8945. }
  8946. }
  8947. if pharmacyConfig.IsOpen != 1 {
  8948. service.HisDrugsDelivery(orgId, creater, &advice)
  8949. if orgId == 3877 || orgId == 10265 {
  8950. //查询该药品是否有出库记录
  8951. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8952. if len(flowMap) == 0 {
  8953. errs := service.UpdateHisAdviceById(advice.ID)
  8954. if errs != nil {
  8955. drugError := models.XtDrugError{
  8956. UserOrgId: orgId,
  8957. DrugId: item.DrugId,
  8958. RecordDate: item.AdviceDate,
  8959. PatientId: item.PatientId,
  8960. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8961. Status: 1,
  8962. Ctime: time.Now().Unix(),
  8963. Mtime: 0,
  8964. SumCount: 0,
  8965. Prescribingnumber: advice.PrescribingNumber,
  8966. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8967. }
  8968. service.CreateDrugError(drugError)
  8969. }
  8970. this.ServeSuccessJSON(map[string]interface{}{
  8971. "msg": "2",
  8972. "drug": medical,
  8973. "ids": ids,
  8974. })
  8975. return
  8976. }
  8977. }
  8978. }
  8979. //更新字典里面的库存
  8980. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8981. var sum_count int64
  8982. for _, its := range stockInfo {
  8983. if its.MaxUnit == medical.MaxUnit {
  8984. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8985. }
  8986. sum_count += its.StockMaxNumber + its.StockMinNumber
  8987. }
  8988. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8989. //剩余库存
  8990. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8991. }
  8992. }
  8993. }
  8994. }
  8995. }
  8996. this.ServeSuccessJSON(map[string]interface{}{
  8997. "msg": "1",
  8998. "ids": ids,
  8999. })
  9000. return
  9001. } else {
  9002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9003. }
  9004. }
  9005. //血透客户
  9006. if config.IsOpen == 2 || config.IsOpen == 0 {
  9007. //药品管理信息
  9008. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9009. if drugStockConfig.IsOpen == 1 {
  9010. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9011. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9012. for _, item := range list {
  9013. for _, it := range adviceList {
  9014. if item.DrugId == it.DrugId {
  9015. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9016. }
  9017. }
  9018. }
  9019. for _, item := range list {
  9020. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9021. var sum_out_count int64
  9022. for _, itemThree := range item.ChildDoctorAdvice {
  9023. var prescribing_number int64
  9024. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9025. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9026. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9027. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9028. }
  9029. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9030. prescribing_number = parseIntPrescribingNumber
  9031. }
  9032. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9033. prescribing_number = parseIntPrescribingNumber
  9034. }
  9035. sum_out_count += prescribing_number
  9036. }
  9037. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9038. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9039. //库存不足
  9040. if sum_out_count > drugStockOut.FlushCount {
  9041. this.ServeSuccessJSON(map[string]interface{}{
  9042. "msg": "2",
  9043. "drug": medical,
  9044. "ids": ids,
  9045. })
  9046. return
  9047. }
  9048. }
  9049. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9050. //执行医嘱
  9051. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9052. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9053. for _, item := range advices {
  9054. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9055. redis := service.RedisClient()
  9056. //清空key 值
  9057. redis.Set(key, "", time.Second)
  9058. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9059. redis.Set(keyTwo, "", time.Second)
  9060. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9061. redis.Set(keyThree, "", time.Second)
  9062. recordDate := theTime.Format("2006-01-02")
  9063. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9064. redis.Set(keyFour, "", time.Second)
  9065. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9066. redis.Set(keyFive, "", time.Second)
  9067. defer redis.Close()
  9068. }
  9069. if errs == nil {
  9070. for _, item := range advices {
  9071. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9072. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9073. //查询是否出库按钮开启
  9074. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9075. if adviceSetting.IsAdviceOpen == 1 {
  9076. //查询是否出库按钮开启
  9077. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9078. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9079. if prescriptionConfig.IsOpen == 1 {
  9080. if medical.IsUse == 2 {
  9081. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9082. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9083. }
  9084. if pharmacyConfig.IsOpen != 1 {
  9085. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9086. }
  9087. //更新字典里面的库存
  9088. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9089. var sum_count int64
  9090. for _, its := range stockInfo {
  9091. if its.MaxUnit == medical.MaxUnit {
  9092. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9093. }
  9094. sum_count += its.StockMaxNumber + its.StockMinNumber
  9095. }
  9096. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9097. //剩余库存
  9098. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9099. }
  9100. }
  9101. } else {
  9102. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9103. if medical.IsUse == 2 {
  9104. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9105. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9106. }
  9107. if pharmacyConfig.IsOpen != 1 {
  9108. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9109. }
  9110. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9111. var sum_count int64
  9112. for _, its := range stockInfo {
  9113. if its.MaxUnit == medical.MaxUnit {
  9114. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9115. }
  9116. sum_count += its.StockMaxNumber + its.StockMinNumber
  9117. }
  9118. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9119. //剩余库存
  9120. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9121. }
  9122. }
  9123. }
  9124. }
  9125. this.ServeSuccessJSON(map[string]interface{}{
  9126. "msg": "1",
  9127. "ids": ids,
  9128. })
  9129. return
  9130. } else {
  9131. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9132. //执行医嘱
  9133. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9134. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9135. for _, item := range advices {
  9136. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9137. redis := service.RedisClient()
  9138. //清空key 值
  9139. redis.Set(key, "", time.Second)
  9140. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9141. redis.Set(keyTwo, "", time.Second)
  9142. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9143. redis.Set(keyThree, "", time.Second)
  9144. recordDate := theTime.Format("2006-01-02")
  9145. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9146. redis.Set(keyFour, "", time.Second)
  9147. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9148. redis.Set(keyFive, "", time.Second)
  9149. defer redis.Close()
  9150. }
  9151. this.ServeSuccessJSON(map[string]interface{}{
  9152. "msg": "1",
  9153. "ids": ids,
  9154. })
  9155. return
  9156. }
  9157. }
  9158. }
  9159. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9160. ids := this.GetString("ids")
  9161. idSplit := strings.Split(ids, ",")
  9162. orgId := this.GetMobileAdminUserInfo().Org.Id
  9163. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9164. if config.IsOpen == 1 {
  9165. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9166. this.ServeSuccessJSON(map[string]interface{}{
  9167. "msg": "1",
  9168. "ids": ids,
  9169. })
  9170. return
  9171. }
  9172. if config.IsOpen == 0 || config.IsOpen == 2 {
  9173. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9174. this.ServeSuccessJSON(map[string]interface{}{
  9175. "msg": "1",
  9176. "ids": ids,
  9177. })
  9178. return
  9179. }
  9180. }
  9181. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9182. ids := this.GetString("ids")
  9183. idSplit := strings.Split(ids, ",")
  9184. orgId := this.GetMobileAdminUserInfo().Org.Id
  9185. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9186. //his
  9187. if config.IsOpen == 1 {
  9188. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9189. theTime := time.Now()
  9190. advices := models.HisDoctorAdviceThirty{
  9191. CheckTime: theTime.Unix(),
  9192. Checker: checker,
  9193. UpdatedTime: time.Now().Unix(),
  9194. }
  9195. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9196. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9197. for _, item := range list {
  9198. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9199. redis := service.RedisClient()
  9200. //清空key 值
  9201. redis.Set(key, "", time.Second)
  9202. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9203. redis.Set(keyTwo, "", time.Second)
  9204. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9205. redis.Set(keyThree, "", time.Second)
  9206. recordDate := theTime.Format("2006-01-02")
  9207. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9208. redis.Set(keyFour, "", time.Second)
  9209. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9210. redis.Set(keyFive, "", time.Second)
  9211. defer redis.Close()
  9212. }
  9213. this.ServeSuccessJSON(map[string]interface{}{
  9214. "msg": "1",
  9215. "ids": ids,
  9216. })
  9217. return
  9218. }
  9219. //血透
  9220. if config.IsOpen == 0 || config.IsOpen == 2 {
  9221. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9222. theTime := time.Now()
  9223. advices := models.DoctorAdvice{
  9224. CheckTime: theTime.Unix(),
  9225. Checker: checker,
  9226. UpdatedTime: time.Now().Unix(),
  9227. }
  9228. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9229. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9230. for _, item := range list {
  9231. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9232. redis := service.RedisClient()
  9233. //清空key 值
  9234. redis.Set(key, "", time.Second)
  9235. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9236. redis.Set(keyTwo, "", time.Second)
  9237. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9238. redis.Set(keyThree, "", time.Second)
  9239. recordDate := theTime.Format("2006-01-02")
  9240. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9241. redis.Set(keyFour, "", time.Second)
  9242. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9243. redis.Set(keyFive, "", time.Second)
  9244. defer redis.Close()
  9245. }
  9246. this.ServeSuccessJSON(map[string]interface{}{
  9247. "msg": "1",
  9248. "ids": ids,
  9249. })
  9250. return
  9251. }
  9252. }
  9253. func (this *DialysisAPIController) CheckSchedule() {
  9254. patientID, _ := this.GetInt64("patient_id")
  9255. recordDateStr := this.GetString("record_date")
  9256. nurseID, _ := this.GetInt64("start_nurse")
  9257. schedual_type, _ := this.GetInt64("schedual_type")
  9258. bedID, _ := this.GetInt64("bed")
  9259. start_time := this.GetString("start_time")
  9260. fmt.Println("patientID", patientID)
  9261. fmt.Println("recordDateStr", recordDateStr)
  9262. fmt.Println("nurseID", nurseID)
  9263. fmt.Println("schedual_type------", schedual_type)
  9264. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9266. return
  9267. }
  9268. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9269. if parseStartDateErr != nil {
  9270. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9272. return
  9273. }
  9274. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9275. if parseErr != nil {
  9276. this.ErrorLog("时间解析失败:%v", parseErr)
  9277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9278. return
  9279. }
  9280. adminUserInfo := this.GetMobileAdminUserInfo()
  9281. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9282. if getPatientErr != nil {
  9283. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9285. return
  9286. } else if patient == nil {
  9287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9288. return
  9289. }
  9290. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9291. if getNurseErr != nil {
  9292. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9294. return
  9295. } else if nurse == nil {
  9296. this.ErrorLog("护士不存在")
  9297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9298. return
  9299. }
  9300. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9301. if getDeviceNumberErr != nil {
  9302. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9304. return
  9305. } else if deviceNumber == nil {
  9306. this.ErrorLog("床位号不存在")
  9307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9308. return
  9309. }
  9310. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9311. if getRecordErr != nil {
  9312. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9314. return
  9315. } else if dialysisRecord != nil {
  9316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9317. return
  9318. }
  9319. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9320. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9321. timeLayout := "2006-01-02 15:04:05"
  9322. loc, _ := time.LoadLocation("Local")
  9323. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9324. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9325. schedulestartTime := theStartTime.Unix()
  9326. scheduleendTime := theEndTime.Unix()
  9327. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9328. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9329. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9330. //查询该床位是否有人用了
  9331. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9332. if err == nil {
  9333. if schedule.ID == 0 {
  9334. this.ServeSuccessJSON(map[string]interface{}{
  9335. "status": 0,
  9336. "msg": "请求失败",
  9337. })
  9338. } else {
  9339. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9340. if order.ID > 0 { //该机位被其他人占用了
  9341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9342. return
  9343. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9344. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9345. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9346. this.ServeSuccessJSON(map[string]interface{}{
  9347. "status": 1,
  9348. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9349. })
  9350. return
  9351. } else {
  9352. this.ServeSuccessJSON(map[string]interface{}{
  9353. "status": 0,
  9354. "msg": "",
  9355. })
  9356. }
  9357. }
  9358. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9359. this.ServeSuccessJSON(map[string]interface{}{
  9360. "status": 2,
  9361. "msg": "当前机位已有患者在使用,请重新选择!",
  9362. })
  9363. }
  9364. }
  9365. } else {
  9366. this.ServeSuccessJSON(map[string]interface{}{
  9367. "status": 0,
  9368. "msg": "",
  9369. })
  9370. }
  9371. }
  9372. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9373. orgId := this.GetMobileAdminUserInfo().Org.Id
  9374. schedule_type, _ := this.GetInt64("schedule_type")
  9375. partion_type, _ := this.GetInt64("partion_type")
  9376. start_time := this.GetString("start_time")
  9377. timeLayout := "2006-01-02"
  9378. loc, _ := time.LoadLocation("Local")
  9379. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9380. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9381. _, config := service.FindXTHisRecordByOrgId(orgId)
  9382. appId := this.GetMobileAdminUserInfo().App.Id
  9383. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9384. if err == nil {
  9385. this.ServeSuccessJSON(map[string]interface{}{
  9386. "list": list,
  9387. "config": config,
  9388. "doctorList": doctorList,
  9389. })
  9390. return
  9391. } else {
  9392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9393. return
  9394. }
  9395. }
  9396. func (this *DialysisAPIController) SaveMobileInformation() {
  9397. patient_id, _ := this.GetInt64("patient_id")
  9398. record_date, _ := this.GetInt64("record_date")
  9399. startTime := this.GetString("start_time")
  9400. module, _ := this.GetInt64("module")
  9401. remark := this.GetString("remark")
  9402. timeLayout := "2006-01-02 15:04"
  9403. loc, _ := time.LoadLocation("Local")
  9404. if len(startTime) == 0 {
  9405. utils.ErrorLog("len(start_time) == 0")
  9406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9407. return
  9408. }
  9409. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9410. if err != nil {
  9411. utils.ErrorLog(err.Error())
  9412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9413. return
  9414. }
  9415. StartTime := theTime.Unix()
  9416. fmt.Println("startime-------------", StartTime)
  9417. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9418. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9419. information := models.XtDialysisInformation{
  9420. Module: module,
  9421. PatientId: patient_id,
  9422. RecordDate: record_date,
  9423. ApplicationDate: StartTime,
  9424. Creater: creater,
  9425. ApplicationStatus: 2,
  9426. Checker: 0,
  9427. CheckTime: 0,
  9428. Remark: remark,
  9429. UserOrgId: user_org_id,
  9430. Ctime: time.Now().Unix(),
  9431. Status: 1,
  9432. Mtime: 0,
  9433. }
  9434. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9435. if infor.ID == 0 {
  9436. service.SaveDialysisInformation(information)
  9437. }
  9438. if infor.ID > 0 {
  9439. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9440. }
  9441. this.ServeSuccessJSON(map[string]interface{}{
  9442. "information": information,
  9443. })
  9444. return
  9445. }
  9446. func (this *DialysisAPIController) GetMobileInformation() {
  9447. limit, _ := this.GetInt64("limit")
  9448. page, _ := this.GetInt64("page")
  9449. orgid := this.GetMobileAdminUserInfo().Org.Id
  9450. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9451. appid := this.GetMobileAdminUserInfo().App.Id
  9452. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9453. patients, _ := service.GetAllpatientThirty(orgid)
  9454. this.ServeSuccessJSON(map[string]interface{}{
  9455. "information": information,
  9456. "total": total,
  9457. "doclist": doclist,
  9458. "patients": patients,
  9459. })
  9460. return
  9461. }
  9462. func (this *DialysisAPIController) GetMobileInformationOne() {
  9463. limit, _ := this.GetInt64("limit")
  9464. page, _ := this.GetInt64("page")
  9465. orgid := this.GetMobileAdminUserInfo().Org.Id
  9466. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9467. appid := this.GetMobileAdminUserInfo().App.Id
  9468. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9469. patients, _ := service.GetAllpatientThirty(orgid)
  9470. this.ServeSuccessJSON(map[string]interface{}{
  9471. "information": information,
  9472. "total": total,
  9473. "doclist": doclist,
  9474. "patients": patients,
  9475. })
  9476. return
  9477. }
  9478. func (this *DialysisAPIController) CheckMobileInformation() {
  9479. id, _ := this.GetInt64("id")
  9480. application_status, _ := this.GetInt64("application_status")
  9481. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9482. checktime := time.Now().Unix()
  9483. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9484. if err == nil {
  9485. this.ServeSuccessJSON(map[string]interface{}{
  9486. "msg": "ok",
  9487. })
  9488. return
  9489. }
  9490. }
  9491. func (c *DialysisAPIController) GetControlMonitorList() {
  9492. partition, _ := c.GetInt64("partition")
  9493. monitorDate := c.GetString("date")
  9494. patient_id, _ := c.GetInt64("patient_id")
  9495. pat_type, _ := c.GetInt64("pat_type")
  9496. timeLayout := "2006-01-02"
  9497. loc, _ := time.LoadLocation("Local")
  9498. var theStartTime int64
  9499. if len(monitorDate) > 0 {
  9500. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9501. if err != nil {
  9502. theStartTime = 0
  9503. }
  9504. theStartTime = theTime.Unix()
  9505. }
  9506. adminInfo := c.GetMobileAdminUserInfo()
  9507. orgID := adminInfo.Org.Id
  9508. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9509. if err != nil {
  9510. c.ErrorLog("获取排班信息失败:%v", err)
  9511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9512. } else {
  9513. if len(monitor) > 0 {
  9514. //获取所有床位
  9515. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9516. //获取所有分区
  9517. zoneList, _ := service.GetAllZoneByList(orgID)
  9518. //获取透析处方
  9519. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9520. //获取透前评估
  9521. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9522. //获取上机
  9523. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9524. //获取透后
  9525. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9526. //获取透后监测
  9527. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9528. //获取所有的患者
  9529. patients, _ := service.GetAllPatientListByListOne(orgID)
  9530. //获取所有透析模式
  9531. treatments, _ := service.GetAllTreatModeByList(orgID)
  9532. //获取所有医嘱
  9533. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9534. //获取双人核对
  9535. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9536. //治疗小结
  9537. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9538. //待消毒
  9539. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9540. for key, item := range monitor {
  9541. // 获取床位信息
  9542. for _, it := range numberList {
  9543. if item.BedId == it.ID {
  9544. monitor[key].DeviceNumber = it
  9545. break
  9546. }
  9547. }
  9548. //获取分区信息
  9549. for _, it := range zoneList {
  9550. if item.PartitionId == it.ID {
  9551. monitor[key].DeviceZone = it
  9552. }
  9553. }
  9554. for _, prescription := range prescriptions {
  9555. if item.PatientId == prescription.PatientId {
  9556. monitor[key].Prescription = prescription
  9557. break
  9558. }
  9559. }
  9560. for _, it := range checkList {
  9561. if item.PatientId == it.PatientId {
  9562. monitor[key].DoubleCheck = it
  9563. break
  9564. }
  9565. }
  9566. for _, it := range summaryList {
  9567. if item.PatientId == it.PatientId {
  9568. monitor[key].TreatmentSummaryForList = it
  9569. break
  9570. }
  9571. }
  9572. // 透前评估
  9573. for _, assessmentBefore := range assessmentBefores {
  9574. if item.PatientId == assessmentBefore.PatientId {
  9575. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9576. break
  9577. }
  9578. }
  9579. // 透析上下机
  9580. for _, dialysisOrder := range dialysisOrders {
  9581. if item.PatientId == dialysisOrder.PatientId {
  9582. monitor[key].DialysisOrder = dialysisOrder
  9583. break
  9584. }
  9585. }
  9586. // 治疗小节
  9587. for _, afterDislysis := range AssessmentAfterDislysis {
  9588. if item.PatientId == afterDislysis.PatientId {
  9589. monitor[key].AssessmentAfterDislysis = afterDislysis
  9590. break
  9591. }
  9592. }
  9593. for _, it := range monitorlist {
  9594. if item.PatientId == it.PatientId {
  9595. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9596. }
  9597. }
  9598. for _, it := range adviceList {
  9599. if item.PatientId == it.PatientId {
  9600. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9601. }
  9602. }
  9603. for _, patient := range patients {
  9604. if item.PatientId == patient.ID {
  9605. monitor[key].MonitorPatients = patient
  9606. break
  9607. }
  9608. }
  9609. for _, treatment := range treatments {
  9610. if item.ModeId == treatment.ID {
  9611. monitor[key].TreatmentMode = treatment
  9612. break
  9613. }
  9614. }
  9615. for _, infor := range informationList {
  9616. if item.PatientId == infor.PatientId {
  9617. monitor[key].NewDeviceInformation = infor
  9618. break
  9619. }
  9620. }
  9621. }
  9622. }
  9623. }
  9624. patients, err := service.GetAllpatientFourty(orgID)
  9625. var mds []*models.NewMonitorDialysisScheduleList
  9626. if pat_type == 0 {
  9627. for _, item := range monitor {
  9628. mds = append(mds, item)
  9629. }
  9630. }
  9631. //待医嘱核对
  9632. if pat_type == 1 {
  9633. for _, item := range monitor {
  9634. if len(item.AdviceList) > 0 {
  9635. mds = append(mds, item)
  9636. }
  9637. }
  9638. }
  9639. //待开小结
  9640. if pat_type == 2 {
  9641. for _, item := range monitor {
  9642. if item.TreatmentSummaryForList == nil {
  9643. mds = append(mds, item)
  9644. }
  9645. }
  9646. }
  9647. //待下机
  9648. if pat_type == 3 {
  9649. for _, item := range monitor {
  9650. if item.DialysisOrder != nil {
  9651. if item.DialysisOrder.ID > 0 {
  9652. mds = append(mds, item)
  9653. }
  9654. }
  9655. }
  9656. }
  9657. //待消毒
  9658. if pat_type == 4 {
  9659. for _, item := range monitor {
  9660. if item.NewDeviceInformation == nil {
  9661. mds = append(mds, item)
  9662. }
  9663. }
  9664. }
  9665. //待双人核对
  9666. if pat_type == 5 {
  9667. for _, item := range monitor {
  9668. if item.DoubleCheck == nil {
  9669. mds = append(mds, item)
  9670. }
  9671. }
  9672. }
  9673. //医嘱未执行
  9674. if pat_type == 6 {
  9675. for _, item := range monitor {
  9676. if len(item.AdviceList) > 0 {
  9677. mds = append(mds, item)
  9678. }
  9679. }
  9680. }
  9681. //患者未签名
  9682. if pat_type == 7 {
  9683. for _, item := range monitor {
  9684. if item.DialysisOrder != nil {
  9685. if item.DialysisOrder.ID > 0 {
  9686. mds = append(mds, item)
  9687. }
  9688. }
  9689. }
  9690. }
  9691. //目标超滤于实际超滤不同
  9692. if pat_type == 8 {
  9693. for _, item := range monitor {
  9694. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9695. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9696. mds = append(mds, item)
  9697. }
  9698. }
  9699. }
  9700. }
  9701. //血压少于5次
  9702. if pat_type == 9 {
  9703. for _, item := range monitor {
  9704. if len(item.MonitoringRecord) < 5 {
  9705. mds = append(mds, item)
  9706. }
  9707. }
  9708. }
  9709. if pat_type == 10 {
  9710. for _, item := range monitor {
  9711. if len(item.MonitoringRecord) == 0 {
  9712. mds = append(mds, item)
  9713. }
  9714. }
  9715. }
  9716. if pat_type == 11 {
  9717. for _, item := range monitor {
  9718. if len(item.MonitoringRecord) > 0 {
  9719. mds = append(mds, item)
  9720. }
  9721. }
  9722. }
  9723. if pat_type == 12 {
  9724. for _, item := range monitor {
  9725. if len(item.MonitoringRecord) > 0 {
  9726. mds = append(mds, item)
  9727. }
  9728. }
  9729. }
  9730. if err == nil {
  9731. c.ServeSuccessJSON(map[string]interface{}{
  9732. "monitor": mds,
  9733. "patients": patients,
  9734. })
  9735. } else {
  9736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9737. }
  9738. }
  9739. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9740. admin_user_id, _ := c.GetInt64("admin_user_id")
  9741. timeStr := time.Now().Format("2006-01-02")
  9742. timeLayout := "2006-01-02 15:04:05"
  9743. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9744. timenow := timeStringToTime.Unix()
  9745. orgId := c.GetMobileAdminUserInfo().Org.Id
  9746. //查询当前护士的患者
  9747. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9748. var patientIds []int64
  9749. for _, item := range orderList {
  9750. patientIds = append(patientIds, item.PatientId)
  9751. }
  9752. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9753. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9754. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9755. //药品管理信息
  9756. _, drugStockConfig := service.FindHisConfig(orgId)
  9757. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9758. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9759. c.ServeSuccessJSON(map[string]interface{}{
  9760. "adviceList": adviceList,
  9761. "hisAdviceList": hisAdviceList,
  9762. "projectList": projectList,
  9763. "drugStockConfig": drugStockConfig,
  9764. "patientList": patientList,
  9765. "projectConfig": projectConfig,
  9766. })
  9767. }
  9768. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9769. patient_id, _ := c.GetInt64("patient_id")
  9770. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9771. c.ServeSuccessJSON(map[string]interface{}{
  9772. "recrods": recrods,
  9773. })
  9774. }
  9775. func (c *DialysisAPIController) ExMobileChangeSch() {
  9776. id_one, _ := c.GetInt64("id_one")
  9777. id_two, _ := c.GetInt64("id_two")
  9778. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9779. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9780. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9781. //if order2.ID > 0 {
  9782. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9783. // return
  9784. //}
  9785. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9786. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9787. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9788. if count > 0 {
  9789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9790. return
  9791. }
  9792. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9793. if count1 > 0 {
  9794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9795. return
  9796. }
  9797. }
  9798. err := service.UpdateScheduleThree(sch, sch_two)
  9799. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9800. if order.ID > 0 {
  9801. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9802. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9803. redis := service.RedisClient()
  9804. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9805. redis.Set(key, "", time.Second)
  9806. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9807. //清空key 值
  9808. redis.Set(keyOne, "", time.Second)
  9809. }
  9810. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9811. if orderOne.ID > 0 {
  9812. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9813. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9814. redis := service.RedisClient()
  9815. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9816. redis.Set(key, "", time.Second)
  9817. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9818. //清空key 值
  9819. redis.Set(keyOne, "", time.Second)
  9820. }
  9821. if err == nil {
  9822. //去除当天患者排班中重复数据,保留最后一条数据
  9823. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9824. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9825. c.ServeSuccessJSON(map[string]interface{}{
  9826. "msg": "交换成功",
  9827. })
  9828. } else {
  9829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9830. return
  9831. }
  9832. }
  9833. func (c *DialysisAPIController) MobileCoverSch() {
  9834. id_one, _ := c.GetInt64("id_one")
  9835. id_two, _ := c.GetInt64("id_two")
  9836. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9837. //针对凤凰医院
  9838. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9839. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9840. if len(advice) > 0 {
  9841. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9842. }
  9843. }
  9844. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9845. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9846. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9847. if len(hisAdvice) > 0 {
  9848. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9849. }
  9850. if len(project) > 0 {
  9851. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9852. }
  9853. }
  9854. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9855. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9856. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9857. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9858. if count > 0 {
  9859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9860. return
  9861. }
  9862. }
  9863. var new_sch models.Schedule
  9864. new_sch = sch
  9865. new_sch.BedId = sch_two.BedId
  9866. new_sch.ScheduleDate = sch_two.ScheduleDate
  9867. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9868. new_sch.PartitionId = sch_two.PartitionId
  9869. new_sch.ScheduleType = sch_two.ScheduleType
  9870. new_sch.ID = 0
  9871. //删除原来的排班
  9872. err := service.SaveSchTwo(sch, sch_two)
  9873. //生成新的排班
  9874. if err == nil {
  9875. err2 := service.SaveSch(&new_sch)
  9876. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9877. if order.ID > 0 {
  9878. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9879. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9880. redis := service.RedisClient()
  9881. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9882. redis.Set(key, "", time.Second)
  9883. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9884. //清空key 值
  9885. redis.Set(keyOne, "", time.Second)
  9886. }
  9887. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9888. if orderOne.ID > 0 {
  9889. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9890. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9891. redis := service.RedisClient()
  9892. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9893. redis.Set(key, "", time.Second)
  9894. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9895. //清空key 值
  9896. redis.Set(keyOne, "", time.Second)
  9897. }
  9898. if err2 == nil {
  9899. //去除当天患者排班中重复数据,保留最后一条数据
  9900. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9901. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9902. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9903. c.ServeSuccessJSON(map[string]interface{}{
  9904. "msg": "覆盖成功",
  9905. "new_sch": new_sch,
  9906. })
  9907. } else {
  9908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9909. return
  9910. }
  9911. } else {
  9912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9913. return
  9914. }
  9915. }
  9916. func (c *DialysisAPIController) BatchCheckAdvice() {
  9917. patient_id, _ := c.GetInt64("patient_id")
  9918. advice_date, _ := c.GetInt64("advice_date")
  9919. org_id := c.GetMobileAdminUserInfo().Org.Id
  9920. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9921. //查询是his系统还是血透系统
  9922. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9923. //his客户
  9924. if configs.IsOpen == 1 {
  9925. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9926. for _, item := range adviceList {
  9927. service.BatchCheckHisAdvice(item.ID, creater)
  9928. }
  9929. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9930. for _, item := range projectList {
  9931. service.BatchCheckProject(item.ID, creater)
  9932. }
  9933. c.ServeSuccessJSON(map[string]interface{}{
  9934. "adviceList": adviceList,
  9935. "projectList": projectList,
  9936. })
  9937. }
  9938. if configs.IsOpen != 1 {
  9939. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9940. for _, item := range adviceList {
  9941. service.BatchAdviceList(item.ID, creater)
  9942. }
  9943. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9944. for _, item := range projectList {
  9945. service.BatchCheckProject(item.ID, creater)
  9946. }
  9947. c.ServeSuccessJSON(map[string]interface{}{
  9948. "adviceList": adviceList,
  9949. "projectList": projectList,
  9950. })
  9951. }
  9952. return
  9953. }
  9954. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9955. org_id := c.GetMobileAdminUserInfo().Org.Id
  9956. drugList, _ := service.GetAllDrugList(org_id)
  9957. c.ServeSuccessJSON(map[string]interface{}{
  9958. "drugList": drugList,
  9959. })
  9960. }
  9961. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9962. org_id := c.GetMobileAdminUserInfo().Org.Id
  9963. dataBody := make(map[string]interface{}, 0)
  9964. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9965. if err != nil {
  9966. utils.ErrorLog(err.Error())
  9967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9968. return
  9969. }
  9970. timeLayout := "2006-01-02"
  9971. loc, _ := time.LoadLocation("Local")
  9972. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9973. utils.ErrorLog("advice_type")
  9974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9975. return
  9976. }
  9977. adviceType := int64(dataBody["advice_type"].(float64))
  9978. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9979. utils.ErrorLog("start_time")
  9980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9981. return
  9982. }
  9983. startTime2, _ := dataBody["start_time"].(string)
  9984. time_arr := strings.Split(startTime2, " ")
  9985. if len(time_arr) > 0 {
  9986. startTime2 = time_arr[0]
  9987. }
  9988. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9989. utils.ErrorLog("advice_date")
  9990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9991. return
  9992. }
  9993. advice_date, _ := dataBody["advice_date"].(string)
  9994. var advicedateunix int64
  9995. if len(advice_date) > 0 {
  9996. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9997. if err != nil {
  9998. fmt.Println(err)
  9999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10000. return
  10001. }
  10002. advicedateunix = theTime.Unix()
  10003. }
  10004. adviceDate := startTime2
  10005. if len(adviceDate) == 0 {
  10006. utils.ErrorLog("len(adviceDate) == 0")
  10007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10008. return
  10009. }
  10010. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10011. if err != nil {
  10012. utils.ErrorLog(err.Error())
  10013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10014. return
  10015. }
  10016. AdviceDate := advicedateunix
  10017. RecordDate := advicedateunix
  10018. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10019. utils.ErrorLog("start_time")
  10020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10021. return
  10022. }
  10023. startTime, _ := dataBody["start_time"].(string)
  10024. if len(startTime) == 0 {
  10025. utils.ErrorLog("len(start_time) == 0")
  10026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10027. return
  10028. }
  10029. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10030. if err != nil {
  10031. utils.ErrorLog(err.Error())
  10032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10033. return
  10034. }
  10035. StartTime := theTime.Unix()
  10036. advice_name, _ := dataBody["advice_name"].(string)
  10037. advice_desc, _ := dataBody["advice_desc"].(string)
  10038. delivery_way, _ := dataBody["delivery_way"].(string)
  10039. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10040. frequency_type := int64(dataBody["frequency_type"].(float64))
  10041. frequency_week, _ := dataBody["frequency_week"].(string)
  10042. prescribing_number := dataBody["prescribing_number"].(float64)
  10043. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10044. remark := dataBody["remark"].(string)
  10045. single_dose := dataBody["single_dose"].(float64)
  10046. single_dose_unit := dataBody["single_dose_unit"].(string)
  10047. patient_id := int64(dataBody["patient_id"].(float64))
  10048. day_count := int64(dataBody["day_count"].(float64))
  10049. groupNo := int64(dataBody["group_no"].(float64))
  10050. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10051. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10052. if groupNo <= 0 {
  10053. group := service.GetMaxAdviceGroupID(org_id)
  10054. groupNo = group + 1
  10055. }
  10056. var template_id = ""
  10057. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10058. template_id = "M" + adviceLastId
  10059. advice := models.DoctorAdvice{
  10060. UserOrgId: org_id,
  10061. PatientId: patient_id,
  10062. AdviceType: adviceType,
  10063. AdviceDate: AdviceDate,
  10064. StartTime: StartTime,
  10065. AdviceName: advice_name,
  10066. AdviceDesc: advice_desc,
  10067. ReminderDate: 0,
  10068. SingleDose: single_dose,
  10069. SingleDoseUnit: single_dose_unit,
  10070. DrugSpec: 0,
  10071. DrugSpecUnit: "",
  10072. PrescribingNumber: prescribing_number,
  10073. PrescribingNumberUnit: prescribing_number_unit,
  10074. DeliveryWay: delivery_way,
  10075. ExecutionFrequency: execution_frequency,
  10076. AdviceDoctor: advice_doctor,
  10077. Status: 1,
  10078. CreatedTime: time.Now().Unix(),
  10079. UpdatedTime: 0,
  10080. AdviceAffirm: "",
  10081. Remark: remark,
  10082. StopTime: 0,
  10083. StopReason: "",
  10084. StopDoctor: 0,
  10085. StopState: 0,
  10086. ParentId: 0,
  10087. ExecutionTime: 0,
  10088. ExecutionStaff: 0,
  10089. ExecutionState: 0,
  10090. Checker: 0,
  10091. RecordDate: RecordDate,
  10092. DialysisOrderId: 0,
  10093. CheckTime: 0,
  10094. CheckState: 0,
  10095. AdviceId: 0,
  10096. RemindType: 0,
  10097. FrequencyType: frequency_type,
  10098. DayCount: day_count,
  10099. WeekDay: frequency_week,
  10100. ChildDoctorAdvice: nil,
  10101. TemplateId: template_id,
  10102. Modifier: 0,
  10103. IsCheck: 0,
  10104. Way: 0,
  10105. DrugId: 0,
  10106. DrugNameId: 0,
  10107. IsMedicine: 0,
  10108. PushStartTime: 0,
  10109. IsSettle: 0,
  10110. IsPrescription: 0,
  10111. GroupNo: groupNo,
  10112. }
  10113. service.CreateMobileAdivce(advice)
  10114. c.ServeSuccessJSON(map[string]interface{}{
  10115. "msg": "保存成功!",
  10116. })
  10117. }
  10118. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10119. patient_id, _ := c.GetInt64("patient_id")
  10120. org_id := c.GetMobileAdminUserInfo().Org.Id
  10121. app_id := c.GetMobileAdminUserInfo().App.Id
  10122. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10123. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10124. c.ServeSuccessJSON(map[string]interface{}{
  10125. "adviceList": adviceList,
  10126. "adminRoles": adminRoles,
  10127. })
  10128. }
  10129. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10130. org_id := c.GetMobileAdminUserInfo().Org.Id
  10131. dataBody := make(map[string]interface{}, 0)
  10132. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10133. if err != nil {
  10134. utils.ErrorLog(err.Error())
  10135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10136. return
  10137. }
  10138. timeLayout := "2006-01-02"
  10139. loc, _ := time.LoadLocation("Local")
  10140. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10141. utils.ErrorLog("start_time")
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. startTime2, _ := dataBody["start_time"].(string)
  10146. time_arr := strings.Split(startTime2, " ")
  10147. if len(time_arr) > 0 {
  10148. startTime2 = time_arr[0]
  10149. }
  10150. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10151. utils.ErrorLog("advice_date")
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10153. return
  10154. }
  10155. advice_date, _ := dataBody["advice_date"].(string)
  10156. var advicedateunix int64
  10157. if len(advice_date) > 0 {
  10158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10159. if err != nil {
  10160. fmt.Println(err)
  10161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10162. return
  10163. }
  10164. advicedateunix = theTime.Unix()
  10165. }
  10166. adviceDate := startTime2
  10167. if len(adviceDate) == 0 {
  10168. utils.ErrorLog("len(adviceDate) == 0")
  10169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10170. return
  10171. }
  10172. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10173. if err != nil {
  10174. utils.ErrorLog(err.Error())
  10175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10176. return
  10177. }
  10178. AdviceDate := advicedateunix
  10179. RecordDate := advicedateunix
  10180. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10181. utils.ErrorLog("start_time")
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. startTime, _ := dataBody["start_time"].(string)
  10186. if len(startTime) == 0 {
  10187. utils.ErrorLog("len(start_time) == 0")
  10188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10189. return
  10190. }
  10191. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10192. if err != nil {
  10193. utils.ErrorLog(err.Error())
  10194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10195. return
  10196. }
  10197. StartTime := theTime.Unix()
  10198. advice_name, _ := dataBody["advice_name"].(string)
  10199. advice_desc, _ := dataBody["advice_desc"].(string)
  10200. delivery_way, _ := dataBody["delivery_way"].(string)
  10201. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10202. prescribing_number := dataBody["prescribing_number"].(float64)
  10203. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10204. remark := dataBody["remark"].(string)
  10205. single_dose := dataBody["single_dose"].(float64)
  10206. single_dose_unit := dataBody["single_dose_unit"].(string)
  10207. patient_id := int64(dataBody["patient_id"].(float64))
  10208. groupNo := int64(dataBody["group_no"].(float64))
  10209. parent_id := int64(dataBody["parent_id"].(float64))
  10210. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10211. advice := models.XtDoctorAdviceOne{
  10212. UserOrgId: org_id,
  10213. PatientId: patient_id,
  10214. AdviceType: 1,
  10215. AdviceDate: AdviceDate,
  10216. StartTime: StartTime,
  10217. AdviceName: advice_name,
  10218. AdviceDesc: advice_desc,
  10219. ReminderDate: 0,
  10220. SingleDose: single_dose,
  10221. SingleDoseUnit: single_dose_unit,
  10222. PrescribingNumber: prescribing_number,
  10223. PrescribingNumberUnit: prescribing_number_unit,
  10224. DeliveryWay: delivery_way,
  10225. ExecutionFrequency: execution_frequency,
  10226. AdviceDoctor: advice_doctor,
  10227. Status: 1,
  10228. CreatedTime: time.Now().Unix(),
  10229. UpdatedTime: time.Now().Unix(),
  10230. AdviceAffirm: "",
  10231. Remark: remark,
  10232. StopTime: 0,
  10233. StopReason: "",
  10234. StopDoctor: 0,
  10235. StopState: 0,
  10236. ParentId: parent_id,
  10237. ExecutionTime: 0,
  10238. ExecutionStaff: 0,
  10239. ExecutionState: 0,
  10240. Checker: 0,
  10241. RecordDate: RecordDate,
  10242. DialysisOrderId: 0,
  10243. CheckTime: 0,
  10244. CheckState: 0,
  10245. DrugSpec: 0,
  10246. DrugSpecUnit: "",
  10247. Groupno: groupNo,
  10248. RemindType: 0,
  10249. FrequencyType: 0,
  10250. DayCount: 0,
  10251. WeekDay: "",
  10252. TemplateId: "",
  10253. Modifier: 0,
  10254. }
  10255. service.CreateMobileAdivceOne(advice)
  10256. c.ServeSuccessJSON(map[string]interface{}{
  10257. "msg": "保存成功!",
  10258. })
  10259. }
  10260. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10261. id, _ := c.GetInt64("id")
  10262. service.DeleteSelfAdviceSubAdvice(id)
  10263. c.ServeSuccessJSON(map[string]interface{}{
  10264. "msg": "保存成功!",
  10265. })
  10266. }
  10267. func (c *DialysisAPIController) GetEditAdviceAction() {
  10268. id, _ := c.GetInt64("id")
  10269. org_id := c.GetMobileAdminUserInfo().Org.Id
  10270. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10271. drugList, _ := service.GetAllDrugList(org_id)
  10272. c.ServeSuccessJSON(map[string]interface{}{
  10273. "advice": advice,
  10274. "drugList": drugList,
  10275. })
  10276. }
  10277. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10278. dataBody := make(map[string]interface{}, 0)
  10279. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10280. if err != nil {
  10281. utils.ErrorLog(err.Error())
  10282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10283. return
  10284. }
  10285. timeLayout := "2006-01-02"
  10286. loc, _ := time.LoadLocation("Local")
  10287. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10288. utils.ErrorLog("start_time")
  10289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10290. return
  10291. }
  10292. startTime2, _ := dataBody["start_time"].(string)
  10293. time_arr := strings.Split(startTime2, " ")
  10294. if len(time_arr) > 0 {
  10295. startTime2 = time_arr[0]
  10296. }
  10297. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10298. utils.ErrorLog("advice_date")
  10299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10300. return
  10301. }
  10302. advice_date, _ := dataBody["advice_date"].(string)
  10303. var advicedateunix int64
  10304. if len(advice_date) > 0 {
  10305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10306. if err != nil {
  10307. fmt.Println(err)
  10308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10309. return
  10310. }
  10311. advicedateunix = theTime.Unix()
  10312. }
  10313. adviceDate := startTime2
  10314. if len(adviceDate) == 0 {
  10315. utils.ErrorLog("len(adviceDate) == 0")
  10316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10317. return
  10318. }
  10319. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10320. if err != nil {
  10321. utils.ErrorLog(err.Error())
  10322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10323. return
  10324. }
  10325. AdviceDate := advicedateunix
  10326. RecordDate := advicedateunix
  10327. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10328. utils.ErrorLog("start_time")
  10329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10330. return
  10331. }
  10332. startTime, _ := dataBody["start_time"].(string)
  10333. if len(startTime) == 0 {
  10334. utils.ErrorLog("len(start_time) == 0")
  10335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10336. return
  10337. }
  10338. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10339. if err != nil {
  10340. utils.ErrorLog(err.Error())
  10341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10342. return
  10343. }
  10344. StartTime := theTime.Unix()
  10345. advice_name, _ := dataBody["advice_name"].(string)
  10346. advice_desc, _ := dataBody["advice_desc"].(string)
  10347. delivery_way, _ := dataBody["delivery_way"].(string)
  10348. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10349. prescribing_number := dataBody["prescribing_number"].(float64)
  10350. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10351. remark := dataBody["remark"].(string)
  10352. single_dose := dataBody["single_dose"].(float64)
  10353. single_dose_unit := dataBody["single_dose_unit"].(string)
  10354. id := int64(dataBody["id"].(float64))
  10355. frequency_type := int64(dataBody["frequency_type"].(float64))
  10356. frequency_week, _ := dataBody["frequency_week"].(string)
  10357. day_count := int64(dataBody["day_count"].(float64))
  10358. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10359. advice := models.XtDoctorAdviceOne{
  10360. AdviceDate: AdviceDate,
  10361. StartTime: StartTime,
  10362. AdviceName: advice_name,
  10363. AdviceDesc: advice_desc,
  10364. SingleDose: single_dose,
  10365. SingleDoseUnit: single_dose_unit,
  10366. PrescribingNumber: prescribing_number,
  10367. PrescribingNumberUnit: prescribing_number_unit,
  10368. DeliveryWay: delivery_way,
  10369. ExecutionFrequency: execution_frequency,
  10370. AdviceDoctor: advice_doctor,
  10371. Remark: remark,
  10372. RecordDate: RecordDate,
  10373. FrequencyType: frequency_type,
  10374. DayCount: day_count,
  10375. WeekDay: frequency_week,
  10376. }
  10377. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10378. c.ServeSuccessJSON(map[string]interface{}{
  10379. "advice": advice,
  10380. })
  10381. }
  10382. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10383. dataBody := make(map[string]interface{}, 0)
  10384. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10385. if err != nil {
  10386. utils.ErrorLog(err.Error())
  10387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10388. return
  10389. }
  10390. timeLayout := "2006-01-02"
  10391. loc, _ := time.LoadLocation("Local")
  10392. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10393. utils.ErrorLog("start_time")
  10394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10395. return
  10396. }
  10397. startTime2, _ := dataBody["start_time"].(string)
  10398. time_arr := strings.Split(startTime2, " ")
  10399. if len(time_arr) > 0 {
  10400. startTime2 = time_arr[0]
  10401. }
  10402. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10403. utils.ErrorLog("advice_date")
  10404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10405. return
  10406. }
  10407. advice_date, _ := dataBody["advice_date"].(string)
  10408. var advicedateunix int64
  10409. if len(advice_date) > 0 {
  10410. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10411. if err != nil {
  10412. fmt.Println(err)
  10413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10414. return
  10415. }
  10416. advicedateunix = theTime.Unix()
  10417. }
  10418. adviceDate := startTime2
  10419. if len(adviceDate) == 0 {
  10420. utils.ErrorLog("len(adviceDate) == 0")
  10421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10422. return
  10423. }
  10424. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10425. if err != nil {
  10426. utils.ErrorLog(err.Error())
  10427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10428. return
  10429. }
  10430. AdviceDate := advicedateunix
  10431. RecordDate := advicedateunix
  10432. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10433. utils.ErrorLog("start_time")
  10434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10435. return
  10436. }
  10437. startTime, _ := dataBody["start_time"].(string)
  10438. if len(startTime) == 0 {
  10439. utils.ErrorLog("len(start_time) == 0")
  10440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10441. return
  10442. }
  10443. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10444. if err != nil {
  10445. utils.ErrorLog(err.Error())
  10446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10447. return
  10448. }
  10449. StartTime := theTime.Unix()
  10450. advice_name, _ := dataBody["advice_name"].(string)
  10451. advice_desc, _ := dataBody["advice_desc"].(string)
  10452. delivery_way, _ := dataBody["delivery_way"].(string)
  10453. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10454. prescribing_number := dataBody["prescribing_number"].(float64)
  10455. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10456. remark := dataBody["remark"].(string)
  10457. single_dose := dataBody["single_dose"].(float64)
  10458. single_dose_unit := dataBody["single_dose_unit"].(string)
  10459. id := int64(dataBody["id"].(float64))
  10460. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10461. advice := models.XtDoctorAdviceOne{
  10462. AdviceDate: AdviceDate,
  10463. StartTime: StartTime,
  10464. AdviceName: advice_name,
  10465. AdviceDesc: advice_desc,
  10466. SingleDose: single_dose,
  10467. SingleDoseUnit: single_dose_unit,
  10468. PrescribingNumber: prescribing_number,
  10469. PrescribingNumberUnit: prescribing_number_unit,
  10470. DeliveryWay: delivery_way,
  10471. ExecutionFrequency: execution_frequency,
  10472. AdviceDoctor: advice_doctor,
  10473. Remark: remark,
  10474. RecordDate: RecordDate,
  10475. }
  10476. service.UpdateMobileDoctorAdviceById(id, advice)
  10477. c.ServeSuccessJSON(map[string]interface{}{
  10478. "advice": advice,
  10479. })
  10480. }
  10481. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10482. dataBody := make(map[string]interface{}, 0)
  10483. timeLayout := "2006-01-02"
  10484. loc, _ := time.LoadLocation("Local")
  10485. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10486. if err != nil {
  10487. utils.ErrorLog(err.Error())
  10488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10489. return
  10490. }
  10491. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10492. utils.ErrorLog("start_time")
  10493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10494. return
  10495. }
  10496. startTime2, _ := dataBody["start_time"].(string)
  10497. time_arr := strings.Split(startTime2, " ")
  10498. if len(time_arr) > 0 {
  10499. startTime2 = time_arr[0]
  10500. }
  10501. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10502. utils.ErrorLog("advice_date")
  10503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10504. return
  10505. }
  10506. advice_date, _ := dataBody["advice_date"].(string)
  10507. var advicedateunix int64
  10508. if len(advice_date) > 0 {
  10509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10510. if err != nil {
  10511. fmt.Println(err)
  10512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10513. return
  10514. }
  10515. advicedateunix = theTime.Unix()
  10516. }
  10517. adviceDate := startTime2
  10518. if len(adviceDate) == 0 {
  10519. utils.ErrorLog("len(adviceDate) == 0")
  10520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10521. return
  10522. }
  10523. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10524. if err != nil {
  10525. utils.ErrorLog(err.Error())
  10526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10527. return
  10528. }
  10529. RecordDate := advicedateunix
  10530. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10531. utils.ErrorLog("start_time")
  10532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10533. return
  10534. }
  10535. startTime, _ := dataBody["start_time"].(string)
  10536. if len(startTime) == 0 {
  10537. utils.ErrorLog("len(start_time) == 0")
  10538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10539. return
  10540. }
  10541. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10542. if err != nil {
  10543. utils.ErrorLog(err.Error())
  10544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10545. return
  10546. }
  10547. StartTime := theTime.Unix()
  10548. patient_id := int64(dataBody["patient_id"].(float64))
  10549. group_no := int64(dataBody["group_no"].(float64))
  10550. org_id := c.GetMobileAdminUserInfo().Org.Id
  10551. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10552. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10553. utils.ErrorLog("advices")
  10554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10555. return
  10556. }
  10557. adviceNames := dataBody["advices"].([]interface{})
  10558. var advices []*models.GroupAdvice
  10559. for _, adviceNameMap := range adviceNames {
  10560. var advice models.GroupAdvice
  10561. adviceNameM := adviceNameMap.(map[string]interface{})
  10562. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10563. utils.ErrorLog("advice_name")
  10564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10565. return
  10566. }
  10567. adviceName, _ := adviceNameM["advice_name"].(string)
  10568. if len(adviceName) == 0 {
  10569. utils.ErrorLog("len(advice_name) == 0")
  10570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10571. return
  10572. }
  10573. advice.AdviceName = adviceName
  10574. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10575. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10576. advice.DrugSpec = drugSpec
  10577. }
  10578. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10579. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10580. advice.AdviceDesc = adviceDesc
  10581. }
  10582. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10583. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10584. advice.DrugSpecUnit = drugSpecUnit
  10585. }
  10586. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10587. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10588. advice.SingleDose = singleDose
  10589. }
  10590. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10591. singleDose := adviceNameM["single_dose"].(float64)
  10592. advice.SingleDose = singleDose
  10593. }
  10594. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10595. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10596. advice.SingleDoseUnit = singleDoseUnit
  10597. }
  10598. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10599. tmp := adviceNameM["single_dose_unit"].(float64)
  10600. singleDoseUnit := service.TypeConversion(tmp)
  10601. advice.SingleDoseUnit = singleDoseUnit
  10602. }
  10603. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10604. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10605. advice.PrescribingNumber = prescribingNumber
  10606. }
  10607. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10608. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10609. advice.PrescribingNumber = prescribingNumber
  10610. }
  10611. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10612. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10613. advice.PrescribingNumberUnit = prescribingNumberUnit
  10614. }
  10615. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10616. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10617. advice.DeliveryWay = deliveryWay
  10618. }
  10619. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10620. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10621. advice.ExecutionFrequency = executionFrequency
  10622. }
  10623. remark, _ := adviceNameM["remark"].(string)
  10624. advice.Remark = remark
  10625. advice.AdviceType = 1
  10626. advice.StartTime = StartTime
  10627. advice.RecordDate = RecordDate
  10628. advice.PatientId = patient_id
  10629. advice.UserOrgId = org_id
  10630. advice.AdviceDoctor = advice_doctor
  10631. advices = append(advices, &advice)
  10632. }
  10633. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10634. c.ServeSuccessJSON(map[string]interface{}{
  10635. "advice": newAdvices,
  10636. })
  10637. }
  10638. func (c *DialysisAPIController) StopLongAdvice() {
  10639. stop_time := c.GetString("execution_time")
  10640. id, _ := c.GetInt64("id")
  10641. if len(stop_time) <= 0 {
  10642. utils.ErrorLog("stop_time")
  10643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10644. return
  10645. }
  10646. timeLayout2 := "2006-01-02 15:04:05"
  10647. loc, _ := time.LoadLocation("Local")
  10648. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10649. if errs != nil {
  10650. utils.ErrorLog(errs.Error())
  10651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10652. return
  10653. }
  10654. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10655. c.ServeSuccessJSON(map[string]interface{}{
  10656. "advice": advice,
  10657. })
  10658. }