dialysis_api_controller.go 312KB

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