dialysis_api_controller.go 286KB

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