dialysis_api_controller.go 335KB

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