dialysis_api_controller.go 387KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  503. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  504. returnData := map[string]interface{}{
  505. "patient": patient,
  506. "schedual": schedual,
  507. "prescription": dialysisPrescribe,
  508. "solution": dialysisSolution,
  509. "last_prescription": lastDialysisPrescribe,
  510. "receiver_treatment_access": receiverTreatmentAccess,
  511. "predialysis_evaluation": predialysisEvaluation,
  512. "doctor_advices": doctorAdvices,
  513. "double_check": doubleCheck,
  514. "assessment_after_dislysis": assessmentAfterDislysis,
  515. "treatment_summary": treatmentSummary,
  516. "monitor_records": monitorRecords,
  517. "dialysis_order": dialysisOrder,
  518. "operators": operators,
  519. "last_predialysis_evaluation": lastPredialysisEvaluation,
  520. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  521. "last_monitor_record": lastMonitorRecord,
  522. "config": gobalConfig,
  523. "dry_weight": lastDryWeightDislysis,
  524. "system_prescription": systemDialysisPrescribe,
  525. "his_advices": his_advices,
  526. "is_open_config": is_open_config,
  527. "stockType": stockType,
  528. "prepare": prepare,
  529. "lastAssessment": lastAssessment,
  530. "prescribeOne": prescribeOne,
  531. "is_project_open_config": is_project_open_config,
  532. "project": projects,
  533. "team_projects": team_projects,
  534. "is_advice_open": is_advice_open,
  535. "prescription_open": prescriptionConfig.IsOpen,
  536. "lastOrder": lastOrder,
  537. "remind_lists": remind_lists,
  538. "lastDialysisPrescription": lastDialysisPrescription,
  539. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  540. "dryWeightList": dryWeightList,
  541. "firstMonitor": firstMonitor,
  542. "lastMonitor": lastMonitor,
  543. }
  544. this.ServeSuccessJSON(returnData)
  545. }
  546. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  547. adminInfo := c.GetMobileAdminUserInfo()
  548. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  549. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  550. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  551. returnData := map[string]interface{}{
  552. "admin_users": adminUsers,
  553. "devices": devices,
  554. "device_numbers": device_numbers,
  555. }
  556. c.ServeSuccessJSON(returnData)
  557. }
  558. func (c *DialysisAPIController) PostAtreatmentInfo() {
  559. id, _ := c.GetInt64("patient", 0)
  560. recordDateStr := c.GetString("record_date")
  561. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  562. summaryContent := c.GetString("summaryContent")
  563. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  564. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  565. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  566. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  567. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  568. nursingRecord := c.GetString("nursing_record")
  569. fmt.Println("护理记录", nursingRecord)
  570. specialRecord := c.GetString("special_record")
  571. fmt.Println("特殊记录", specialRecord)
  572. adminUserInfo := c.GetMobileAdminUserInfo()
  573. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  574. checkStaffId = adminUserInfo.AdminUser.Id
  575. deboardNurseId = adminUserInfo.AdminUser.Id
  576. treatDoctor = adminUserInfo.AdminUser.Id
  577. if id <= 0 {
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  579. return
  580. }
  581. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  582. if patient.ID == 0 {
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  584. return
  585. }
  586. if len(recordDateStr) == 0 {
  587. recordDateStr = time.Now().Format("2006-01-02")
  588. }
  589. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  590. if parseDateErr != nil {
  591. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  593. return
  594. }
  595. summary := models.TreatmentSummary{
  596. UserOrgId: adminUserInfo.Org.Id,
  597. PatientId: id,
  598. AssessmentDate: recordDate.Unix(),
  599. Mission: propagandaAndEducationContent,
  600. DialysisSummary: summaryContent,
  601. SjNurse: changeMedicalNurseId,
  602. ZlNurse: treatNurseId,
  603. HdNurse: checkStaffId,
  604. XjNurse: deboardNurseId,
  605. ZlDoctor: treatDoctor,
  606. CreatedTime: time.Now().Unix(),
  607. Status: 1,
  608. NursingRecord: nursingRecord,
  609. SpecialRecord: specialRecord,
  610. }
  611. // 查询信息规挡的设置天数
  612. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  613. if infor.ID > 0 && infor.WeekDay > 0 {
  614. var cha_time int64
  615. timeNowStr := time.Now().Format("2006-01-02")
  616. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  617. //今日的日期减去设置的日期
  618. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  619. if cha_time >= recordDate.Unix() {
  620. //查询审核是否允许
  621. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  622. //申请状态不允许的情况 拒绝修改
  623. if infor.ApplicationStatus != 1 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  625. return
  626. }
  627. }
  628. }
  629. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  630. if treatmentSummary.ID == 0 { //新增
  631. summary.Creater = adminUserInfo.AdminUser.Id
  632. service.AddSigleSummaryRecord(&summary)
  633. finish := models.XtDialysisFinish{
  634. IsFinish: 1,
  635. UserOrgId: adminUserInfo.Org.Id,
  636. Status: 1,
  637. Ctime: time.Now().Unix(),
  638. Mtime: 0,
  639. Module: 10,
  640. RecordDate: recordDate.Unix(),
  641. Sourse: 1,
  642. PatientId: id,
  643. }
  644. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  645. if dialysisFinish.ID == 0 {
  646. service.CreateDialysisFinish(finish)
  647. }
  648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  649. redis := service.RedisClient()
  650. //清空key 值
  651. redis.Set(key, "", time.Second)
  652. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  653. redis.Set(keyOne, "", time.Second)
  654. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyThree, "", time.Second)
  656. defer redis.Close()
  657. c.ServeSuccessJSON(map[string]interface{}{
  658. "summary": summary,
  659. })
  660. } else { //修改
  661. summary.Creater = treatmentSummary.Creater
  662. summary.CreatedTime = treatmentSummary.CreatedTime
  663. summary.Modifier = adminUserInfo.AdminUser.Id
  664. summary.ID = treatmentSummary.ID
  665. service.UpdateSummeRecord(&summary)
  666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  667. redis := service.RedisClient()
  668. //清空key 值
  669. redis.Set(key, "", time.Second)
  670. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  671. redis.Set(keyOne, "", time.Second)
  672. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  673. redis.Set(keyThree, "", time.Second)
  674. defer redis.Close()
  675. c.ServeSuccessJSON(map[string]interface{}{
  676. "summary": summary,
  677. })
  678. }
  679. }
  680. func (c *DialysisAPIController) PostDoubleCheck() {
  681. id, _ := c.GetInt64("patient", 0)
  682. recordDateStr := c.GetString("record_date")
  683. checkTimeStr := c.GetString("check_time")
  684. firstCheckTimeStr := c.GetString("first_check_time")
  685. creater, _ := c.GetInt64("creater", 0)
  686. modifier, _ := c.GetInt64("modifier", 0)
  687. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  688. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  689. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  690. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  691. dialysis_item_desc := c.GetString("dialysis_item_desc")
  692. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  693. vascular_access_desc := c.GetString("vascular_access_desc")
  694. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  695. collator, _ := c.GetInt64("collator", 0)
  696. employee_number := c.GetString("employee_number")
  697. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  698. needle_batch_number := c.GetString("needle_batch_number")
  699. if id <= 0 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. adminUserInfo := c.GetMobileAdminUserInfo()
  704. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  705. if patient.ID == 0 {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  707. return
  708. }
  709. if len(recordDateStr) == 0 {
  710. recordDateStr = time.Now().Format("2006-01-02")
  711. }
  712. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  713. if parseDateErr != nil {
  714. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  716. return
  717. }
  718. var checkDate int64
  719. if len(checkTimeStr) == 0 {
  720. checkDate = 0
  721. } else {
  722. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  723. checkDate = checkDateUnix.Unix()
  724. }
  725. var firstCheckDate int64
  726. if len(firstCheckTimeStr) == 0 {
  727. firstCheckDate = 0
  728. } else {
  729. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  730. firstCheckDate = firstCheckDateUnix.Unix()
  731. }
  732. if adminUserInfo.Org.Id == 10644 {
  733. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  734. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  735. if check.ID == 0 {
  736. if employee_number != list.JobNumber {
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "doubleCheck": check,
  739. "msg": "2",
  740. })
  741. return
  742. }
  743. }
  744. if check.ID > 0 {
  745. if employee_number != list.JobNumber {
  746. c.ServeSuccessJSON(map[string]interface{}{
  747. "doubleCheck": check,
  748. "msg": "2",
  749. })
  750. return
  751. }
  752. }
  753. }
  754. doubleCheck := models.DoubleCheck{
  755. UserOrgId: adminUserInfo.Org.Id,
  756. PatientId: id,
  757. DialysisItemCheck: dialysis_item_check,
  758. DialysisParameterCheck: dialysis_parameter_check,
  759. VascularAccessVerification: vascular_access_verification,
  760. PipelineConnectionCheck: pipeline_connection_check,
  761. DialysisItemDesc: dialysis_item_desc,
  762. DialysisParameterDesc: dialysis_parameter_desc,
  763. VascularAccessDesc: vascular_access_desc,
  764. PipelineConnectionDesc: pipeline_connection_desc,
  765. Collator: collator,
  766. Status: 1,
  767. CreatedTime: time.Now().Unix(),
  768. CheckDate: recordDate.Unix(),
  769. UpdatedTime: time.Now().Unix(),
  770. EmployeeNumber: employee_number,
  771. DialyzerBatchNumber: dialyzer_batch_number,
  772. NeedleBatchNumber: needle_batch_number,
  773. }
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 { //新增
  776. doubleCheck.FirstCheckTime = firstCheckDate
  777. doubleCheck.CheckTime = checkDate
  778. doubleCheck.Creater = creater
  779. doubleCheck.Modifier = modifier
  780. if adminUserInfo.Org.Id == 10340 {
  781. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  782. doubleCheck.Creater = order.StartNurse
  783. }
  784. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  785. //查询未核对的医嘱
  786. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  787. for _, advice := range doctorList {
  788. if advice.ExecutionStaff == modifier {
  789. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  790. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  791. return
  792. }
  793. }
  794. }
  795. // 查询信息规挡的设置天数
  796. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  797. if infor.ID > 0 && infor.WeekDay > 0 {
  798. var cha_time int64
  799. timeNowStr := time.Now().Format("2006-01-02")
  800. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  801. //今日的日期减去设置的日期
  802. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  803. if cha_time >= recordDate.Unix() {
  804. //查询审核是否允许
  805. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  806. //申请状态不允许的情况 拒绝修改
  807. if infor.ApplicationStatus != 1 {
  808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  809. return
  810. }
  811. }
  812. }
  813. err := service.AddSigleDoubleCheck(&doubleCheck)
  814. finish := models.XtDialysisFinish{
  815. IsFinish: 1,
  816. UserOrgId: adminUserInfo.Org.Id,
  817. Status: 1,
  818. Ctime: time.Now().Unix(),
  819. Mtime: 0,
  820. Module: 5,
  821. RecordDate: recordDate.Unix(),
  822. Sourse: 1,
  823. PatientId: id,
  824. }
  825. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  826. if dialysisFinish.ID == 0 {
  827. service.CreateDialysisFinish(finish)
  828. }
  829. //针对长沙南雅
  830. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  831. //查询未核对的医嘱
  832. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  833. if len(doctorList) > 0 && modifier > 0 {
  834. for _, advice := range doctorList {
  835. service.UpdateDoctorAdviceList(advice.ID, modifier)
  836. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  837. redis := service.RedisClient()
  838. //清空key 值
  839. redis.Set(key, "", time.Second)
  840. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  841. redis.Set(keyTwo, "", time.Second)
  842. theTime := time.Now()
  843. recordDate := theTime.Format("2006-01-02")
  844. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  845. redis.Set(keyFour, "", time.Second)
  846. defer redis.Close()
  847. }
  848. }
  849. }
  850. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  851. redis := service.RedisClient()
  852. //清空key 值
  853. redis.Set(key, "", time.Second)
  854. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  855. redis.Set(keyOne, "", time.Second)
  856. defer redis.Close()
  857. if err == nil {
  858. c.ServeSuccessJSON(map[string]interface{}{
  859. "doubleCheck": &doubleCheck,
  860. })
  861. }
  862. } else { //修改
  863. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  864. if infor.ID > 0 {
  865. var cha_time int64
  866. timeNowStr := time.Now().Format("2006-01-02")
  867. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  868. //今日的日期减去设置的日期
  869. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  870. if cha_time >= recordDate.Unix() {
  871. //查询审核是否允许
  872. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  873. //申请状态不允许的情况 拒绝修改
  874. if infor.ApplicationStatus != 1 {
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  876. return
  877. }
  878. }
  879. }
  880. doubleCheck.FirstCheckTime = firstCheckDate
  881. doubleCheck.CheckTime = checkDate
  882. doubleCheck.Creater = creater
  883. doubleCheck.Modifier = modifier
  884. doubleCheck.CreatedTime = check.CreatedTime
  885. doubleCheck.ID = check.ID
  886. doubleCheck.EmployeeNumber = employee_number
  887. doubleCheck.NeedleBatchNumber = needle_batch_number
  888. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  889. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  890. //查询未核对的医嘱
  891. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  892. for _, advice := range doctorList {
  893. if advice.ExecutionStaff == modifier {
  894. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  895. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  896. return
  897. }
  898. }
  899. }
  900. err := service.UpdateDoubleCheck(&doubleCheck)
  901. //针对长沙南雅
  902. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  903. //查询未核对的医嘱
  904. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  905. if len(doctorList) > 0 && modifier > 0 {
  906. for _, advice := range doctorList {
  907. service.UpdateDoctorAdviceList(advice.ID, modifier)
  908. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  909. redis := service.RedisClient()
  910. //清空key 值
  911. redis.Set(key, "", time.Second)
  912. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  913. redis.Set(keyTwo, "", time.Second)
  914. theTime := time.Now()
  915. recordDate := theTime.Format("2006-01-02")
  916. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  917. redis.Set(keyFour, "", time.Second)
  918. defer redis.Close()
  919. }
  920. }
  921. }
  922. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  923. redis := service.RedisClient()
  924. //清空key 值
  925. redis.Set(key, "", time.Second)
  926. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  927. redis.Set(keyOne, "", time.Second)
  928. defer redis.Close()
  929. if err == nil {
  930. c.ServeSuccessJSON(map[string]interface{}{
  931. "doubleCheck": &doubleCheck,
  932. "msg": "1",
  933. })
  934. }
  935. }
  936. }
  937. func (c *DialysisAPIController) PostAcceptsAssessment() {
  938. id, _ := c.GetInt64("patient", 0)
  939. recordDateStr := c.GetString("record_date")
  940. way, _ := c.GetInt64("way", 0)
  941. consciousness, _ := c.GetInt64("consciousness", 0)
  942. appetite, _ := c.GetInt64("appetite", 0)
  943. condition, _ := c.GetInt64("condition", 0)
  944. posture, _ := c.GetInt64("posture")
  945. sick_condition, _ := c.GetInt64("sick_condition", 0)
  946. danger_level, _ := c.GetInt64("danger_level", 0)
  947. intake, _ := c.GetInt64("intake", 0)
  948. nutrition, _ := c.GetInt64("nutrition", 0)
  949. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  950. psychological_assessment_other := c.GetString("psychological_assessment_other")
  951. score := c.GetString("score")
  952. sick_condition_other := c.GetString("sick_condition_other")
  953. //precaution, _ := c.GetInt64("precaution", 0)
  954. precaution := c.GetString("precaution")
  955. precaution_other := c.GetString("precaution_other")
  956. psychological_other := c.GetString("psychological_other")
  957. admission_number := c.GetString("admission_number")
  958. tumble, _ := c.GetInt64("tumble")
  959. diacrisis := c.GetString("diacrisis")
  960. his_department := c.GetString("his_department")
  961. his_bed := c.GetString("his_bed")
  962. if id <= 0 {
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. adminUserInfo := c.GetMobileAdminUserInfo()
  967. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  968. if patient.ID == 0 {
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  970. return
  971. }
  972. //now := time.Now()
  973. //year, month, day := now.Date()
  974. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  975. //todayTimeStamp := today_time.Unix()
  976. if len(recordDateStr) == 0 {
  977. recordDateStr = time.Now().Format("2006-01-02")
  978. }
  979. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  980. if parseDateErr != nil {
  981. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. return
  984. }
  985. // 查询信息规挡的设置天数
  986. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  987. if infor.ID > 0 && infor.WeekDay > 0 {
  988. var cha_time int64
  989. timeNowStr := time.Now().Format("2006-01-02")
  990. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  991. //今日的日期减去设置的日期
  992. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  993. if cha_time >= recordDate.Unix() {
  994. //查询审核是否允许
  995. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  996. //申请状态不允许的情况 拒绝修改
  997. if infor.ApplicationStatus != 1 {
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  999. return
  1000. }
  1001. }
  1002. }
  1003. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1004. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1005. UserOrgId: adminUserInfo.Org.Id,
  1006. PatientId: id,
  1007. RecordDate: recordDate.Unix(),
  1008. Way: way,
  1009. Consciousness: consciousness,
  1010. Appetite: appetite,
  1011. Condition: condition,
  1012. SickCondition: sick_condition,
  1013. DangerLevel: danger_level,
  1014. Intake: intake,
  1015. Nutrition: nutrition,
  1016. PsychologicalAssessment: psychological_assessment,
  1017. PsychologicalAssessmentOther: psychological_assessment_other,
  1018. SickConditionOther: sick_condition_other,
  1019. Posture: posture,
  1020. CreatedTime: time.Now().Unix(),
  1021. UpdateTime: time.Now().Unix(),
  1022. Status: 1,
  1023. Score: score,
  1024. Precaution: precaution,
  1025. PrecautionOther: precaution_other,
  1026. PsychologicalOther: psychological_other,
  1027. AdmissionNumber: admission_number,
  1028. Tumble: tumble,
  1029. Diacrisis: diacrisis,
  1030. HisBed: his_bed,
  1031. HisDepartment: his_department,
  1032. }
  1033. if receiveTreatment.ID == 0 { //新增
  1034. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1035. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1036. finish := models.XtDialysisFinish{
  1037. IsFinish: 1,
  1038. UserOrgId: adminUserInfo.Org.Id,
  1039. Status: 1,
  1040. Ctime: time.Now().Unix(),
  1041. Mtime: 0,
  1042. Module: 2,
  1043. RecordDate: recordDate.Unix(),
  1044. Sourse: 1,
  1045. PatientId: id,
  1046. }
  1047. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1048. if dialysisFinish.ID == 0 {
  1049. service.CreateDialysisFinish(finish)
  1050. }
  1051. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1052. redis := service.RedisClient()
  1053. defer redis.Close()
  1054. //清空key 值
  1055. redis.Set(key, "", time.Second)
  1056. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1057. redis.Set(keyOne, "", time.Second)
  1058. if err == nil {
  1059. c.ServeSuccessJSON(map[string]interface{}{
  1060. "receiveTreatmentAsses": receiveTreatmentAsses,
  1061. })
  1062. }
  1063. } else { //修改
  1064. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1065. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1066. // if getPermissionErr != nil {
  1067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1068. // return
  1069. // } else if headNursePermission == nil {
  1070. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1071. // return
  1072. // }
  1073. //}
  1074. // 查询信息规挡的设置天数
  1075. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1076. if infor.ID > 0 && infor.WeekDay > 0 {
  1077. var cha_time int64
  1078. timeNowStr := time.Now().Format("2006-01-02")
  1079. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1080. //今日的日期减去设置的日期
  1081. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1082. if cha_time >= recordDate.Unix() {
  1083. //查询审核是否允许
  1084. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1085. //申请状态不允许的情况 拒绝修改
  1086. if infor.ApplicationStatus != 1 {
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1088. return
  1089. }
  1090. }
  1091. }
  1092. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1093. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1094. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1095. receiveTreatmentAsses.ID = receiveTreatment.ID
  1096. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1097. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1098. redis := service.RedisClient()
  1099. defer redis.Close()
  1100. //清空key 值
  1101. redis.Set(key, "", time.Second)
  1102. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1103. redis.Set(keyOne, "", time.Second)
  1104. if err == nil {
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "receiveTreatmentAsses": receiveTreatmentAsses,
  1107. })
  1108. }
  1109. }
  1110. }
  1111. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1112. id, _ := c.GetInt64("patient", 0)
  1113. recordDateStr := c.GetString("record_date")
  1114. weightAfter, _ := c.GetFloat("weight_after", 0)
  1115. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1116. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1117. fmt.Println("weight_loss", weightReduce)
  1118. temperature, _ := c.GetFloat("temperature", 0)
  1119. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1120. breathing_rate := c.GetString("breathing_rate")
  1121. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1122. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1123. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1124. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1125. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1126. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1127. cruor := c.GetString("cruor")
  1128. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1129. internalFistula := c.GetString("internal_fistula")
  1130. catheter := c.GetString("catheter")
  1131. complications := c.GetString("complication")
  1132. remark := c.GetString("remark")
  1133. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1134. dialysis_intakes := c.GetString("dialysis_intakes")
  1135. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1136. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1137. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1138. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1139. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1140. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1141. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1142. patientGose, _ := c.GetInt64("patient_gose", 0)
  1143. inpatientDepartment := c.GetString("inpatient_department")
  1144. observationContent := c.GetString("observation_content")
  1145. observationContentOther := c.GetString("observation_content_other")
  1146. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1147. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1148. in_advance_reason := c.GetString("in_advance_reason")
  1149. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1150. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1151. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1152. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1153. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1154. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1155. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1156. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1157. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1158. is_eat, _ := c.GetInt64("is_eat", 0)
  1159. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1160. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1161. channels, _ := c.GetInt64("channel", 0)
  1162. return_blood, _ := c.GetInt64("return_blood", 0)
  1163. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1164. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1165. dialysis_during, _ := c.GetFloat("dialysis_during")
  1166. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1167. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1168. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1169. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1170. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1171. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1172. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1173. setting_pressure := c.GetString("setting_pressure")
  1174. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1175. diastolic_pressure := c.GetString("diastolic_pressure")
  1176. other_complication := c.GetString("other_complication")
  1177. ktv := c.GetString("ktv")
  1178. urr := c.GetString("urr")
  1179. hypertenison, _ := c.GetInt64("hypertenison")
  1180. hypopiesia, _ := c.GetInt64("hypopiesia")
  1181. leave_office_method, _ := c.GetInt64("leave_office_method")
  1182. lapse, _ := c.GetInt64("lapse")
  1183. consciousness, _ := c.GetInt64("consciousness")
  1184. fallrisk, _ := c.GetInt64("fallrisk")
  1185. machine_run := c.GetString("machine_run")
  1186. after_urea := c.GetString("after_urea")
  1187. pip_coagulation := c.GetString("pip_coagulation")
  1188. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1189. transfusion_volume := c.GetString("transfusion_volume")
  1190. last_after_weight := c.GetString("last_after_weight")
  1191. displace_liqui_value := c.GetString("displace_liqui_value")
  1192. if id <= 0 {
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1194. return
  1195. }
  1196. adminUserInfo := c.GetMobileAdminUserInfo()
  1197. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1198. if patient.ID == 0 {
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1200. return
  1201. }
  1202. if len(recordDateStr) == 0 {
  1203. recordDateStr = time.Now().Format("2006-01-02")
  1204. }
  1205. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1206. fmt.Println("parseDateErr", parseDateErr)
  1207. if parseDateErr != nil {
  1208. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. //now := time.Now()
  1213. //year, month, day := now.Date()
  1214. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1215. //todayTimeStamp := today_time.Unix()
  1216. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1217. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1218. UserOrgId: adminUserInfo.Org.Id,
  1219. PatientId: id,
  1220. AssessmentDate: recordDate.Unix(),
  1221. Temperature: temperature,
  1222. PulseFrequency: pulse_frequency,
  1223. BreathingRate: breathing_rate,
  1224. SystolicBloodPressure: systolic_blood_pressure,
  1225. DiastolicBloodPressure: diastolic_blood_pressure,
  1226. ActualUltrafiltration: actual_ultrafiltration,
  1227. ActualDisplacement: actual_displacement,
  1228. ActualTreatmentHour: actualtreatHour,
  1229. ActualTreatmentMinute: actualtreatmin,
  1230. WeightAfter: weightAfter,
  1231. AdditionalWeight: additionalWeight,
  1232. WeightLoss: weightReduce,
  1233. Cruor: cruor,
  1234. SymptomAfterDialysis: symptomsAfterDialysi,
  1235. InternalFistula: internalFistula,
  1236. Catheter: catheter,
  1237. Complication: complications,
  1238. DialysisIntakes: dialysateVolume,
  1239. CreatedTime: time.Now().Unix(),
  1240. UpdatedTime: time.Now().Unix(),
  1241. Status: 1,
  1242. Remark: remark,
  1243. BloodAccessPartId: blood_access_part_id,
  1244. BloodAccessPartOperaId: blood_access_part_opera_id,
  1245. DialysisIntakesUnit: dialysis_intakes_unit,
  1246. PuncturePointOozingBlood: puncturePointOozingBlood,
  1247. PuncturePointHaematoma: puncturePointHaematoma,
  1248. InternalFistulaTremorAc: internalFistulaTremorAc,
  1249. PatientGose: patientGose,
  1250. InpatientDepartment: inpatientDepartment,
  1251. ObservationContent: observationContent,
  1252. ObservationContentOther: observationContentOther,
  1253. DialysisProcess: dialysis_process,
  1254. InAdvanceMinute: in_advance_minute,
  1255. InAdvanceReason: in_advance_reason,
  1256. HemostasisMinute: hemostasis_minute,
  1257. HemostasisOpera: hemostasis_opera,
  1258. TremorNoise: tremor_noise,
  1259. DisequilibriumSyndrome: disequilibrium_syndrome,
  1260. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1261. ArterialTube: arterial_tube,
  1262. IntravenousTube: intravenous_tube,
  1263. Dialyzer: dialyzer,
  1264. InAdvanceReasonOther: in_advance_reason_other,
  1265. IsEat: is_eat,
  1266. CvcA: cvc_a,
  1267. CvcV: cvc_v,
  1268. Channel: channels,
  1269. ReturnBlood: return_blood,
  1270. RehydrationVolume: rehydration_volume,
  1271. DialysisDuring: dialysis_during,
  1272. StrokeVolume: stroke_volume,
  1273. BloodFlow: blood_flow,
  1274. SealingFluidDispose: sealing_fluid_dispose,
  1275. SealingFluidSpecial: sealing_fluid_special,
  1276. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1277. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1278. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1279. SettingPressure: setting_pressure,
  1280. DiastolicPressure: diastolic_pressure,
  1281. OtherComplication: other_complication,
  1282. Ktv: ktv,
  1283. Urr: urr,
  1284. Hypopiesia: hypopiesia,
  1285. Hypertenison: hypertenison,
  1286. Lapse: lapse,
  1287. LeaveOfficeMethod: leave_office_method,
  1288. Consciousness: consciousness,
  1289. Fallrisk: fallrisk,
  1290. MachineRun: machine_run,
  1291. AfterUrea: after_urea,
  1292. PipCoagulation: pip_coagulation,
  1293. AccumulatedBloodVolume: accumulated_blood_volume,
  1294. TransfusionVolume: transfusion_volume,
  1295. LastAfterWeight: last_after_weight,
  1296. DisplaceLiquiValue: displace_liqui_value,
  1297. }
  1298. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1299. // 查询信息规挡的设置天数
  1300. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1301. if infor.ID > 0 && infor.WeekDay > 0 {
  1302. var cha_time int64
  1303. timeNowStr := time.Now().Format("2006-01-02")
  1304. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1305. //今日的日期减去设置的日期
  1306. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1307. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1308. if cha_time >= recordDate.Unix() {
  1309. //查询审核是否允许
  1310. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1311. //申请状态不允许的情况 拒绝修改
  1312. if infor.ApplicationStatus != 1 {
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1314. return
  1315. }
  1316. }
  1317. }
  1318. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1319. if assessmentAfter.ID == 0 { //新增
  1320. if appRole.UserType == 2 || appRole.UserType == 1 {
  1321. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1322. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1323. } else {
  1324. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1325. }
  1326. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1327. if assessmentAfterDislysis.UserOrgId != 10340 {
  1328. if assessmentAfterDislysis.WeightAfter == 0 {
  1329. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1330. }
  1331. }
  1332. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1333. //记录日志
  1334. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1335. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1336. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1337. PatientId: assessmentAfterDislysis.PatientId,
  1338. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1339. Status: 1,
  1340. ErrLog: string(byterequest),
  1341. AdminUserId: adminUserInfo.AdminUser.Id,
  1342. Ctime: 0,
  1343. Mtime: 0,
  1344. Source: "手机端保存透后评估",
  1345. }
  1346. service.CreateAfterDialysisLog(afterDialysisLog)
  1347. finish := models.XtDialysisFinish{
  1348. IsFinish: 1,
  1349. UserOrgId: adminUserInfo.Org.Id,
  1350. Status: 1,
  1351. Ctime: time.Now().Unix(),
  1352. Mtime: 0,
  1353. Module: 9,
  1354. RecordDate: recordDate.Unix(),
  1355. Sourse: 1,
  1356. PatientId: id,
  1357. }
  1358. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1359. if dialysisFinish.ID == 0 {
  1360. service.CreateDialysisFinish(finish)
  1361. }
  1362. redis := service.RedisClient()
  1363. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1364. redis.Set(keyTwo, "", time.Second)
  1365. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1366. //清空key 值
  1367. redis.Set(key, "", time.Second)
  1368. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1369. redis.Set(keyOne, "", time.Second)
  1370. defer redis.Close()
  1371. if err == nil {
  1372. c.ServeSuccessJSON(map[string]interface{}{
  1373. "assessmentAfterDislysis": assessmentAfterDislysis,
  1374. })
  1375. }
  1376. return
  1377. } else { //修改
  1378. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1379. if infor.ID > 0 && infor.WeekDay > 0 {
  1380. var cha_time int64
  1381. timeNowStr := time.Now().Format("2006-01-02")
  1382. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1383. //今日的日期减去设置的日期
  1384. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1385. if cha_time >= recordDate.Unix() {
  1386. //查询审核是否允许
  1387. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1388. //申请状态不允许的情况 拒绝修改
  1389. if infor.ApplicationStatus != 1 {
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1391. return
  1392. }
  1393. }
  1394. }
  1395. if appRole.UserType == 2 || appRole.UserType == 1 {
  1396. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1397. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1398. } else {
  1399. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1400. if assessmentAfterDislysis.Creater == 0 {
  1401. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1402. }
  1403. }
  1404. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1405. assessmentAfterDislysis.ID = assessmentAfter.ID
  1406. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1407. if assessmentAfterDislysis.UserOrgId != 10340 {
  1408. if assessmentAfterDislysis.WeightAfter == 0 {
  1409. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1410. }
  1411. }
  1412. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1413. //记录日志
  1414. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1415. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1416. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1417. PatientId: assessmentAfterDislysis.PatientId,
  1418. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1419. Status: 1,
  1420. ErrLog: string(byterequest),
  1421. AdminUserId: adminUserInfo.AdminUser.Id,
  1422. Ctime: time.Now().Unix(),
  1423. Mtime: 0,
  1424. Source: "手机端修改保存透后评估",
  1425. }
  1426. service.CreateAfterDialysisLog(afterDialysisLog)
  1427. redis := service.RedisClient()
  1428. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1429. redis.Set(keyTwo, "", time.Second)
  1430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1431. //清空key 值
  1432. redis.Set(key, "", time.Second)
  1433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1434. redis.Set(keyOne, "", time.Second)
  1435. if err == nil {
  1436. c.ServeSuccessJSON(map[string]interface{}{
  1437. "assessmentAfterDislysis": assessmentAfterDislysis,
  1438. })
  1439. return
  1440. }
  1441. }
  1442. return
  1443. }
  1444. func (c *DialysisAPIController) PostDialysisPrescription() {
  1445. id, _ := c.GetInt64("patient", 0)
  1446. recordDateStr := c.GetString("record_date")
  1447. if id <= 0 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1449. return
  1450. }
  1451. adminUserInfo := c.GetMobileAdminUserInfo()
  1452. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1453. if patient.ID == 0 {
  1454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1455. return
  1456. }
  1457. if len(recordDateStr) == 0 {
  1458. recordDateStr = time.Now().Format("2006-01-02")
  1459. }
  1460. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1461. if parseDateErr != nil {
  1462. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1464. return
  1465. }
  1466. mode_id, _ := c.GetInt64("mode_id", 0)
  1467. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1468. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1469. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1470. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1471. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1472. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1473. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1474. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1475. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1476. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1477. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1478. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1479. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1480. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1481. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1482. kalium, _ := c.GetFloat("kalium", 0)
  1483. sodium, _ := c.GetFloat("sodium", 0)
  1484. calcium, _ := c.GetFloat("calcium", 0)
  1485. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1486. glucose, _ := c.GetFloat("glucose", 0)
  1487. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1488. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1489. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1490. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1491. conductivity, _ := c.GetFloat("conductivity", 0)
  1492. remark := c.GetString("remark")
  1493. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1494. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1495. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1496. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1497. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1498. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1499. special_medicine_other := c.GetString("special_medicine_other")
  1500. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1501. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1502. blood_access, _ := c.GetInt64("blood_access", 0)
  1503. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1504. body_fluid_other := c.GetString("body_fluid_other")
  1505. niprocart, _ := c.GetInt64("niprocart", 0)
  1506. jms, _ := c.GetInt64("jms", 0)
  1507. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1508. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1509. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1510. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1511. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1512. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1513. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1514. injector, _ := c.GetInt64("injector", 0)
  1515. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1516. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1517. safe_package, _ := c.GetInt64("package", 0)
  1518. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1519. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1520. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1521. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1522. blood := c.GetString("blood")
  1523. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1524. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1525. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1526. displace_speed := c.GetString("displace_speed")
  1527. illness, _ := c.GetInt64("illness")
  1528. amylaceum := c.GetString("amylaceum")
  1529. single_time := c.GetString("single_time")
  1530. single_water := c.GetString("single_water")
  1531. replacement_flow := c.GetString("replacement_flow")
  1532. plasma_separator := c.GetString("plasma_separator")
  1533. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1534. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1535. oxygen_flow := c.GetString("oxygen_flow")
  1536. oxygen_time := c.GetString("oxygen_time")
  1537. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1538. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1539. puncture_needle := c.GetString("puncture_needle")
  1540. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1541. epo := c.GetString("epo")
  1542. epo_count, _ := c.GetFloat("epo_count", 0)
  1543. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1544. admin_user_id, _ := c.GetInt64("admin_user_id")
  1545. is_water := c.GetString("is_water")
  1546. var is_war int64
  1547. if is_water == "是" {
  1548. is_war = 1
  1549. }
  1550. if is_water == "否" {
  1551. is_war = 2
  1552. }
  1553. if is_water == "请选择" {
  1554. is_war = 0
  1555. }
  1556. drhy_water := c.GetString("drhy_water")
  1557. dry_water_hour := c.GetString("dry_water_hour")
  1558. water_machine := c.GetString("water_machine")
  1559. add_amount, _ := c.GetFloat("add_amount")
  1560. reduce_amount, _ := c.GetFloat("reduce_amount")
  1561. dialysis_remark := c.GetString("dialysis_remark")
  1562. prescribing_number, _ := c.GetFloat("prescribing_number")
  1563. prescription_sodium := c.GetString("prescription_sodium")
  1564. start_sodium := c.GetString("start_sodium")
  1565. sodium_curve := c.GetString("sodium_curve")
  1566. treatment_remark := c.GetString("treatment_remark")
  1567. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1568. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1569. prescription_water, _ := c.GetFloat("prescription_water")
  1570. dialysis_strainer := c.GetString("dialysis_strainer")
  1571. chaptalization := c.GetString("chaptalization")
  1572. washing_time := c.GetString("washing_time")
  1573. warsh_count := c.GetString("warsh_count")
  1574. blood_access_part_id := c.GetString("blood_access_part_id")
  1575. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1576. dialyzate := c.GetString("dialyzate")
  1577. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1578. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1579. //
  1580. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1581. // if appRole.UserType == 3 {
  1582. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1583. // if getPermissionErr != nil {
  1584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1585. // return
  1586. // } else if headNursePermission == nil {
  1587. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1588. // return
  1589. // }
  1590. // }
  1591. //}
  1592. // 查询信息规挡的设置天数
  1593. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1594. if infor.ID > 0 && infor.WeekDay > 0 {
  1595. var cha_time int64
  1596. timeNowStr := time.Now().Format("2006-01-02")
  1597. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1598. //今日的日期减去设置的日期
  1599. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1600. if cha_time >= recordDate.Unix() {
  1601. //查询审核是否允许
  1602. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1603. //申请状态不允许的情况 拒绝修改
  1604. if infor.ApplicationStatus != 1 {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1606. return
  1607. }
  1608. }
  1609. }
  1610. if mode_id > 0 {
  1611. var str string
  1612. //查找该机构用的是什么透析器
  1613. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1614. if filedConfig.ID > 0 {
  1615. str = dialyzerPerfusionApparatus
  1616. } else {
  1617. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1618. }
  1619. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1620. }
  1621. //TODO 需要根据角色去判断
  1622. prescription := models.DialysisPrescription{
  1623. UserOrgId: adminUserInfo.Org.Id,
  1624. PatientId: id,
  1625. RecordDate: recordDate.Unix(),
  1626. ModeId: mode_id,
  1627. DialysisDuration: dialysis_duration,
  1628. Dialyzer: dialyzer,
  1629. PerfusionApparatus: perfusion_apparatus,
  1630. BloodFlowVolume: blood_flow_volume,
  1631. DewaterAmount: dewater_amount,
  1632. DisplaceLiqui: displace_liqui,
  1633. ReplacementWay: replacement_way,
  1634. Anticoagulant: anticoagulant,
  1635. AnticoagulantShouji: anticoagulant_shouji,
  1636. AnticoagulantWeichi: anticoagulant_weichi,
  1637. AnticoagulantZongliang: anticoagulant_zongliang,
  1638. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1639. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1640. Kalium: kalium,
  1641. Sodium: sodium,
  1642. Calcium: calcium,
  1643. Bicarbonate: bicarbonate,
  1644. Glucose: glucose,
  1645. // DryWeight: dry_weight,
  1646. DialysateFlow: dialysate_flow,
  1647. DialysateTemperature: dialysate_temperature,
  1648. // PrescriptionDoctor: prescription_doctor,
  1649. ReplacementTotal: replacement_total,
  1650. Conductivity: conductivity,
  1651. Remark: remark,
  1652. Status: 1,
  1653. CreatedTime: time.Now().Unix(),
  1654. UpdatedTime: time.Now().Unix(),
  1655. DialysisDurationMinute: dialysisDurationMinute,
  1656. DialysisDurationHour: dialysisDurationHour,
  1657. TargetUltrafiltration: targetUltrafiltration,
  1658. DialysateFormulation: dialysateFormulation,
  1659. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1660. BodyFluid: body_fluid,
  1661. SpecialMedicine: special_medicine,
  1662. SpecialMedicineOther: special_medicine_other,
  1663. DisplaceLiquiPart: displace_liqui_part,
  1664. DisplaceLiquiValue: displace_liqui_value,
  1665. BloodAccess: blood_access,
  1666. Ultrafiltration: ultrafiltration,
  1667. BodyFluidOther: body_fluid_other,
  1668. Niprocart: niprocart,
  1669. Jms: jms,
  1670. FistulaNeedleSet: fistula_needle_set,
  1671. FistulaNeedleSet16: fistula_needle_set_16,
  1672. Hemoperfusion: hemoperfusion,
  1673. DialyserSterilised: dialyser_sterilised,
  1674. Filtryzer: filtryzer,
  1675. Dialyzers: dialyzers,
  1676. Injector: injector,
  1677. Bloodlines: bloodlines,
  1678. TubingHemodialysis: tubing_hemodialysis,
  1679. Package: safe_package,
  1680. ALiquid: a_liquid,
  1681. TargetKtv: target_ktv,
  1682. PreImpulse: pre_impulse,
  1683. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1684. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1685. Blood: blood,
  1686. DialysisDialyszers: dialysis_dialyszers,
  1687. DialysisIrrigation: dialysis_irrigation,
  1688. AntioxidantCommodityName: antioxidant_commodity_name,
  1689. DisplaceSpeed: displace_speed,
  1690. Illness: illness,
  1691. Amylaceum: amylaceum,
  1692. SingleTime: single_time,
  1693. SingleWater: single_water,
  1694. ReplacementFlow: replacement_flow,
  1695. PlasmaSeparator: plasma_separator,
  1696. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1697. OxygenUptake: oxygen_uptake,
  1698. OxygenFlow: oxygen_flow,
  1699. OxygenTime: oxygen_time,
  1700. HemodialysisPipelines: hemodialysis_pipelines,
  1701. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1702. PunctureNeedle: puncture_needle,
  1703. PunctureNeedleCount: puncture_needle_count,
  1704. Epo: epo,
  1705. EpoCount: epo_count,
  1706. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1707. AdminUserId: admin_user_id,
  1708. IsWater: is_war,
  1709. DrhyWater: drhy_water,
  1710. DryWaterHour: dry_water_hour,
  1711. WaterMachine: water_machine,
  1712. AddAmount: add_amount,
  1713. ReduceAmount: reduce_amount,
  1714. DialysisRemark: dialysis_remark,
  1715. PrescribingNumber: prescribing_number,
  1716. StartSodium: start_sodium,
  1717. SodiumCurve: sodium_curve,
  1718. TreatmentRemark: treatment_remark,
  1719. PrescriptionSodium: prescription_sodium,
  1720. DialysisFluidFlow: dialysis_fluid_flow,
  1721. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1722. PrescriptionWater: prescription_water,
  1723. DialysisStrainer: dialysis_strainer,
  1724. Chaptalization: chaptalization,
  1725. WashingTime: washing_time,
  1726. WarshCount: warsh_count,
  1727. BloodAccessPartId: blood_access_part_id,
  1728. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1729. Dialyzate: dialyzate,
  1730. }
  1731. //查询最近透析准备表里是否存在 透析器 灌流器
  1732. //
  1733. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1734. //
  1735. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1736. //
  1737. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1738. //if len(mation)>0{
  1739. // for _, item := range splitStr {
  1740. // for _,it := range mation{
  1741. // if(item == it.SpecificationName){
  1742. //
  1743. // //查询最近一次的透析器
  1744. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1745. //
  1746. // if errcode == gorm.ErrRecordNotFound{
  1747. // //插入数据
  1748. // prepare := models.DialysisBeforePrepare{
  1749. // UserOrgId: adminUserInfo.Org.Id,
  1750. // PatientId: id,
  1751. // RecordDate: recordDate.Unix(),
  1752. // GoodTypeId: it.GoodTypeId,
  1753. // GoodId: it.ID,
  1754. // Count: 1,
  1755. // Ctime: time.Now().Unix(),
  1756. // Creater: adminUserInfo.AdminUser.Id,
  1757. // Status:1,
  1758. //
  1759. // }
  1760. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1761. // fmt.Println("",errcode)
  1762. // }
  1763. // }
  1764. // }
  1765. //
  1766. // }
  1767. //
  1768. // for _, item := range splitIrrigation {
  1769. // for _,it := range mation{
  1770. // if(item == it.SpecificationName){
  1771. // //查询最近一次的透析器
  1772. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1773. // if errcode == gorm.ErrRecordNotFound{
  1774. // //插入数据
  1775. // prepare := models.DialysisBeforePrepare{
  1776. // UserOrgId: adminUserInfo.Org.Id,
  1777. // PatientId: id,
  1778. // RecordDate: recordDate.Unix(),
  1779. // GoodTypeId: it.GoodTypeId,
  1780. // GoodId: it.ID,
  1781. // Count: 1,
  1782. // Ctime: time.Now().Unix(),
  1783. // Creater: adminUserInfo.AdminUser.Id,
  1784. // Status:1,
  1785. //
  1786. // }
  1787. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1788. // fmt.Println(errcode)
  1789. // }
  1790. // }
  1791. // }
  1792. // }
  1793. //}
  1794. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1795. if dialysisPrescription.ID == 0 { //新增
  1796. if appRole.UserType == 2 || appRole.UserType == 1 {
  1797. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1798. }
  1799. prescription.Creater = adminUserInfo.AdminUser.Id
  1800. //针对河间咸得
  1801. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1802. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1803. prescription.DisplaceLiquiPart = 0
  1804. prescription.DisplaceLiquiValue = 0
  1805. }
  1806. }
  1807. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1808. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1809. }
  1810. err := service.AddSigleRecord(&prescription)
  1811. //记录日志
  1812. byterequest, _ := json.Marshal(prescription)
  1813. prescriptionLog := models.XtDialysisPrescriptionLog{
  1814. UserOrgId: prescription.UserOrgId,
  1815. Ctime: time.Now().Unix(),
  1816. Mtime: 0,
  1817. ErrLog: string(byterequest),
  1818. AdminUserId: adminUserInfo.AdminUser.Id,
  1819. RecordDate: prescription.RecordDate,
  1820. PatientId: prescription.PatientId,
  1821. Source: "手机端新增保存处方",
  1822. Status: 1,
  1823. }
  1824. service.CreatePrescriptionLog(prescriptionLog)
  1825. finish := models.XtDialysisFinish{
  1826. IsFinish: 1,
  1827. UserOrgId: adminUserInfo.Org.Id,
  1828. Status: 1,
  1829. Ctime: time.Now().Unix(),
  1830. Mtime: 0,
  1831. Module: 1,
  1832. RecordDate: recordDate.Unix(),
  1833. Sourse: 1,
  1834. PatientId: id,
  1835. }
  1836. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1837. if dialysisFinish.ID == 0 {
  1838. service.CreateDialysisFinish(finish)
  1839. }
  1840. //长沙南雅医院,自动生成抗凝剂的临时处方
  1841. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1842. if prescribing_number == 0 {
  1843. prescribing_number = 1
  1844. }
  1845. if prescribing_number == 0 && id == 14682 {
  1846. prescribing_number = 2
  1847. }
  1848. if prescribing_number == 0 && id == 18560 {
  1849. prescribing_number = 2
  1850. }
  1851. advice := models.DoctorAdvice{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. GroupNo: 0,
  1855. AdviceType: 2,
  1856. RecordDate: recordDate.Unix(),
  1857. AdviceDate: recordDate.Unix(),
  1858. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1859. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1860. AdviceDesc: "",
  1861. ReminderDate: 0,
  1862. SingleDose: anticoagulant_zongliang,
  1863. SingleDoseUnit: "iu",
  1864. DrugSpec: 0,
  1865. DrugSpecUnit: "",
  1866. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1867. PrescribingNumberUnit: "支",
  1868. DeliveryWay: "静脉注射",
  1869. ExecutionFrequency: "上机前",
  1870. AdviceDoctor: 0,
  1871. Status: 1,
  1872. CreatedTime: time.Now().Unix(),
  1873. UpdatedTime: time.Now().Unix(),
  1874. IsPrescription: 1,
  1875. ExecutionState: 2,
  1876. StopState: 2,
  1877. IsSettle: 2,
  1878. }
  1879. // 查询排班信息
  1880. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1881. if schedulePatient.ID > 0 {
  1882. if schedulePatient.ScheduleType == 1 {
  1883. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1884. }
  1885. if schedulePatient.ScheduleType == 2 {
  1886. advice.StartTime = recordDate.Unix() + 9*60*60
  1887. }
  1888. }
  1889. // 抗凝剂名称
  1890. switch anticoagulant {
  1891. case 1:
  1892. advice.AdviceName = "无肝素"
  1893. break
  1894. case 2:
  1895. advice.AdviceName = "普通肝素"
  1896. break
  1897. case 3:
  1898. advice.AdviceName = "低分子肝素"
  1899. break
  1900. case 4:
  1901. advice.AdviceName = "阿加曲班"
  1902. break
  1903. case 5:
  1904. advice.AdviceName = "枸橼酸钠"
  1905. break
  1906. case 6:
  1907. advice.AdviceName = "低分子肝素钙"
  1908. break
  1909. case 7:
  1910. advice.AdviceName = "低分子肝素钠"
  1911. break
  1912. case 8:
  1913. advice.AdviceName = "依诺肝素"
  1914. break
  1915. case 9:
  1916. advice.AdviceName = "达肝素"
  1917. break
  1918. case 10:
  1919. advice.AdviceName = "体外抗凝"
  1920. break
  1921. case 11:
  1922. advice.AdviceName = "那曲肝素"
  1923. break
  1924. case 12:
  1925. advice.AdviceName = "无抗凝剂"
  1926. break
  1927. }
  1928. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1929. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1930. advice.AdviceDoctor = appRole.AdminUserId
  1931. }
  1932. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1933. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1934. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1935. advice.AdviceName = "低分子肝素钠注射液"
  1936. // 修改患者临时医嘱里的抗凝剂医嘱
  1937. advice.ID = advicePrescription.ID
  1938. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1939. } else {
  1940. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1941. advice.AdviceName = "低分子肝素钠注射液"
  1942. // 新增患者临时医嘱里的抗凝剂医嘱
  1943. service.CreateDoctorAdvice(&advice)
  1944. }
  1945. }
  1946. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1947. redis := service.RedisClient()
  1948. defer redis.Close()
  1949. //清空key 值
  1950. redis.Set(key, "", time.Second)
  1951. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1952. redis.Set(keyOne, "", time.Second)
  1953. }
  1954. //获取key,清空redis
  1955. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1956. redis := service.RedisClient()
  1957. //清空key 值
  1958. redis.Set(key, "", time.Second)
  1959. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1960. //清空key 值
  1961. redis.Set(keyOne, "", time.Second)
  1962. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1963. //清空key 值
  1964. redis.Set(keyTwo, "", time.Second)
  1965. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1966. redis.Set(keySix, "", time.Second)
  1967. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1968. redis.Set(keySeven, "", time.Second)
  1969. if err == nil {
  1970. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1971. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1972. //清空key 值
  1973. redis.Set(keyThree, "", time.Second)
  1974. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1975. //清空key 值
  1976. redis.Set(keyFour, "", time.Second)
  1977. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1978. redis.Set(keyFive, "", time.Second)
  1979. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1980. redis.Set(keySix, "", time.Second)
  1981. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1982. redis.Set(keySeven, "", time.Second)
  1983. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1984. //清空key 值
  1985. redis.Set(keyOne, "", time.Second)
  1986. if updateErr != nil {
  1987. utils.ErrorLog("%v", updateErr)
  1988. }
  1989. defer redis.Close()
  1990. c.ServeSuccessJSON(map[string]interface{}{
  1991. "prescription": prescription,
  1992. })
  1993. }
  1994. } else { //修改
  1995. //if mode_id > 0 {
  1996. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1997. //}
  1998. //if template.TemplateId == 1 {
  1999. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2000. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2001. // if getPermissionErr != nil {
  2002. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2003. // return
  2004. // } else if headNursePermission == nil {
  2005. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2006. // return
  2007. // }
  2008. // }
  2009. //}
  2010. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2011. prescription.Modifier = adminUserInfo.AdminUser.Id
  2012. if appRole.UserType == 2 || appRole.UserType == 1 {
  2013. prescription_doctor := adminUserInfo.AdminUser.Id
  2014. prescription.PrescriptionDoctor = prescription_doctor
  2015. } else {
  2016. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2017. }
  2018. if dialysisPrescription.Creater == 0 { //体重称
  2019. prescription.Creater = adminUserInfo.AdminUser.Id
  2020. } else {
  2021. prescription.Creater = dialysisPrescription.Creater
  2022. if adminUserInfo.Org.Id == 9882 {
  2023. if appRole.UserType == 2 || appRole.UserType == 1 {
  2024. prescription_doctor := adminUserInfo.AdminUser.Id
  2025. prescription.PrescriptionDoctor = prescription_doctor
  2026. prescription.Creater = prescription_doctor
  2027. }
  2028. }
  2029. }
  2030. prescription.ID = dialysisPrescription.ID
  2031. service.UpDateDialysisPrescription(&prescription)
  2032. //记录日志
  2033. byterequest, _ := json.Marshal(prescription)
  2034. prescriptionLog := models.XtDialysisPrescriptionLog{
  2035. UserOrgId: prescription.UserOrgId,
  2036. Ctime: time.Now().Unix(),
  2037. Mtime: 0,
  2038. ErrLog: string(byterequest),
  2039. AdminUserId: adminUserInfo.AdminUser.Id,
  2040. RecordDate: prescription.RecordDate,
  2041. PatientId: prescription.PatientId,
  2042. Source: "手机端修改处方",
  2043. Status: 1,
  2044. }
  2045. service.CreatePrescriptionLog(prescriptionLog)
  2046. finish := models.XtDialysisFinish{
  2047. IsFinish: 1,
  2048. UserOrgId: adminUserInfo.Org.Id,
  2049. Status: 1,
  2050. Ctime: time.Now().Unix(),
  2051. Mtime: 0,
  2052. Module: 1,
  2053. RecordDate: recordDate.Unix(),
  2054. Sourse: 1,
  2055. PatientId: id,
  2056. }
  2057. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2058. if dialysisFinish.ID == 0 {
  2059. service.CreateDialysisFinish(finish)
  2060. }
  2061. //修改处方
  2062. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2063. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2064. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2065. if advicePrescription.ID > 0 {
  2066. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2067. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2068. redis := service.RedisClient()
  2069. defer redis.Close()
  2070. //清空key 值
  2071. redis.Set(key, "", time.Second)
  2072. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2073. redis.Set(keyOne, "", time.Second)
  2074. }
  2075. }
  2076. //获取key,清空redis
  2077. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2078. redis := service.RedisClient()
  2079. //清空key 值
  2080. redis.Set(key, "", time.Second)
  2081. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2082. //清空key 值
  2083. redis.Set(keyOne, "", time.Second)
  2084. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2085. redis.Set(keySix, "", time.Second)
  2086. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2087. redis.Set(keySeven, "", time.Second)
  2088. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2089. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2090. //清空key 值
  2091. redis.Set(keyTwoOne, "", time.Second)
  2092. defer redis.Close()
  2093. if updateErr != nil {
  2094. utils.ErrorLog("%v", updateErr)
  2095. }
  2096. c.ServeSuccessJSON(map[string]interface{}{
  2097. "prescription": prescription,
  2098. })
  2099. }
  2100. }
  2101. func (c *DialysisAPIController) Finish() {
  2102. id, _ := c.GetInt64("patient", 0)
  2103. recordDateStr := c.GetString("record_date")
  2104. nurseID, _ := c.GetInt64("nurse")
  2105. end_time := c.GetString("end_time")
  2106. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2107. internal_fistula := c.GetString("blood_access_internal_fistula")
  2108. catheter := c.GetString("catheter")
  2109. cruor := c.GetString("cruor")
  2110. mission := c.GetString("mission")
  2111. condenser := c.GetString("condenser")
  2112. if id <= 0 || nurseID <= 0 {
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2114. return
  2115. }
  2116. adminUserInfo := c.GetMobileAdminUserInfo()
  2117. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2118. if patient.ID == 0 {
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2120. return
  2121. }
  2122. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2123. if getNurseErr != nil {
  2124. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2126. return
  2127. } else if nurse == nil {
  2128. c.ErrorLog("护士不存在")
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. if len(recordDateStr) == 0 {
  2133. recordDateStr = time.Now().Format("2006-01-02")
  2134. }
  2135. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2136. if parseDateErr != nil {
  2137. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2139. return
  2140. }
  2141. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2142. if parseEndDateErr != nil {
  2143. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2145. return
  2146. }
  2147. // 查询信息规挡的设置天数
  2148. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2149. if infor.ID > 0 && infor.WeekDay > 0 {
  2150. var cha_time int64
  2151. timeNowStr := time.Now().Format("2006-01-02")
  2152. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2153. //今日的日期减去设置的日期
  2154. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2155. if cha_time >= recordDate.Unix() {
  2156. //查询审核是否允许
  2157. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2158. //申请状态不允许的情况 拒绝修改
  2159. if infor.ApplicationStatus != 1 {
  2160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2161. return
  2162. }
  2163. }
  2164. }
  2165. //now := time.Now()
  2166. //year, month, day := now.Date()
  2167. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2168. //todayTimeStamp := today_time.Unix()
  2169. // 获取当天的第一条透析纪录
  2170. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2171. if getMonitorRecordsErr != nil {
  2172. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2174. return
  2175. }
  2176. // 获取当前的最后一条透析纪录
  2177. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2178. if getMonitorRecordsErr != nil {
  2179. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2181. return
  2182. }
  2183. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2184. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2185. if getAADErr != nil {
  2186. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2188. return
  2189. }
  2190. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2192. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2193. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2194. if assessmentAfterDislysis != nil {
  2195. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2196. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2197. } else {
  2198. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2199. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2200. tempassessmentAfterDislysis.Status = 1
  2201. tempassessmentAfterDislysis.PatientId = id
  2202. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2203. }
  2204. //长沙南雅
  2205. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2206. //获取最后一条透析处方数据
  2207. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2208. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2209. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2210. }
  2211. if dialysisOrder.Stage == 1 {
  2212. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2213. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2214. fmt.Println(value)
  2215. a, b := math.Modf(value)
  2216. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2217. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2218. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2219. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2220. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2221. }
  2222. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2223. //var num1 int64
  2224. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2225. //fmt.Println(num1)
  2226. //sub := float64(num1 / 3600)
  2227. //fmt.Println(sub)
  2228. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2229. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2230. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2231. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2232. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2233. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2234. if adminUserInfo.Org.Id != 10375 {
  2235. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2236. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2237. }
  2238. if adminUserInfo.Org.Id != 10445 {
  2239. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2240. }
  2241. //北方营口医院
  2242. if adminUserInfo.Org.Id == 10445 {
  2243. //获取最后一条透析处方数据
  2244. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2245. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2246. } else {
  2247. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2248. }
  2249. //新化博翔
  2250. if adminUserInfo.Org.Id == 10447 {
  2251. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2252. }
  2253. //阳春
  2254. if adminUserInfo.Org.Id == 10485 {
  2255. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2256. }
  2257. if adminUserInfo.Org.Id == 10551 {
  2258. //获取最后一条透析处方数据
  2259. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2260. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2261. }
  2262. if adminUserInfo.Org.Id == 10580 {
  2263. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2264. }
  2265. if adminUserInfo.Org.Id == 10612 {
  2266. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2267. }
  2268. }
  2269. 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 {
  2270. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2271. if evaluation.SystolicBloodPressure == 0 {
  2272. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2273. pre := models.PredialysisEvaluation{
  2274. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2275. }
  2276. fmt.Println("prew", pre)
  2277. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2278. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2279. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2280. redis := service.RedisClient()
  2281. redis.Set(key, "", time.Second)
  2282. redis.Set(keyOne, "", time.Second)
  2283. defer redis.Close()
  2284. fmt.Println(getNurseErr)
  2285. }
  2286. if evaluation.DiastolicBloodPressure == 0 {
  2287. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2288. pres := models.PredialysisEvaluation{
  2289. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2290. }
  2291. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2293. redis := service.RedisClient()
  2294. redis.Set(key, "", time.Second)
  2295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2296. redis.Set(keyOne, "", time.Second)
  2297. defer redis.Close()
  2298. fmt.Println(getNurseErr)
  2299. }
  2300. if evaluation.PulseFrequency == 0 {
  2301. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2302. press := models.PredialysisEvaluation{
  2303. PulseFrequency: evaluation.PulseFrequency,
  2304. }
  2305. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2306. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2307. redis := service.RedisClient()
  2308. redis.Set(key, "", time.Second)
  2309. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2310. redis.Set(keyOne, "", time.Second)
  2311. defer redis.Close()
  2312. fmt.Println(getNurseErr)
  2313. }
  2314. if evaluation.Temperature == 0 {
  2315. evaluation.Temperature = fmonitorRecords.Temperature
  2316. press := models.PredialysisEvaluation{
  2317. Temperature: evaluation.Temperature,
  2318. }
  2319. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2320. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2321. redis := service.RedisClient()
  2322. redis.Set(key, "", time.Second)
  2323. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2324. redis.Set(keyOne, "", time.Second)
  2325. defer redis.Close()
  2326. fmt.Println(getNurseErr)
  2327. }
  2328. }
  2329. if adminUserInfo.Org.Id == 9583 {
  2330. //获取透析处方的最后一条数据
  2331. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2332. if diaerr != nil {
  2333. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2335. return
  2336. }
  2337. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2338. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2339. }
  2340. }
  2341. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2342. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2343. }
  2344. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2345. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2346. }
  2347. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2348. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2349. }
  2350. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2351. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2352. }
  2353. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2354. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2355. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2356. }
  2357. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2358. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2359. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2360. }
  2361. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2362. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2363. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2364. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2365. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2366. }
  2367. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2368. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2369. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2370. }
  2371. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2372. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2373. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2374. }
  2375. if lastAssessmentAfterDislysis != nil {
  2376. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2377. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2378. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2379. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2380. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2381. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2382. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2383. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2384. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2385. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2386. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2387. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2388. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2389. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2390. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2391. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2392. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2393. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2394. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2395. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2396. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2397. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2398. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2399. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2400. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2401. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2402. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2403. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2404. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2405. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2406. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2407. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2408. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2409. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2410. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2411. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2412. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2413. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2414. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2415. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2416. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2417. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2418. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2419. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2420. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2421. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2422. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2423. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2424. if tempassessmentAfterDislysis.PatientId == 18695 {
  2425. tempassessmentAfterDislysis.ActualDisplacement = 0
  2426. }
  2427. if adminUserInfo.Org.Id != 10375 {
  2428. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2429. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2430. }
  2431. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2432. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2433. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2434. }
  2435. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2436. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2437. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2438. }
  2439. }
  2440. finish := models.XtDialysisFinish{
  2441. IsFinish: 1,
  2442. UserOrgId: adminUserInfo.Org.Id,
  2443. Status: 1,
  2444. Ctime: time.Now().Unix(),
  2445. Mtime: 0,
  2446. Module: 9,
  2447. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2448. Sourse: 1,
  2449. PatientId: tempassessmentAfterDislysis.PatientId,
  2450. }
  2451. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2452. if dialysisFinish.ID == 0 {
  2453. service.CreateDialysisFinish(finish)
  2454. }
  2455. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2456. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2457. redis := service.RedisClient()
  2458. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2459. redis.Set(keyOne, "", time.Second)
  2460. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2461. redis.Set(keyTwo, "", time.Second)
  2462. defer redis.Close()
  2463. //清空key 值
  2464. redis.Set(key, "", time.Second)
  2465. if err != nil {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2467. return
  2468. }
  2469. if dialysisOrder == nil {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2471. return
  2472. }
  2473. if dialysisOrder.Stage == 2 {
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2475. return
  2476. }
  2477. if dialysisOrder.Stage == 1 {
  2478. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2479. finish := models.XtDialysisFinish{
  2480. IsFinish: 1,
  2481. UserOrgId: adminUserInfo.Org.Id,
  2482. Status: 1,
  2483. Ctime: time.Now().Unix(),
  2484. Mtime: 0,
  2485. Module: 8,
  2486. RecordDate: recordDate.Unix(),
  2487. Sourse: 1,
  2488. PatientId: id,
  2489. }
  2490. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2491. if dialysisFinish.ID == 0 {
  2492. service.CreateDialysisFinish(finish)
  2493. }
  2494. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2495. redis := service.RedisClient()
  2496. defer redis.Close()
  2497. //清空key 值
  2498. redis.Set(key, "", time.Second)
  2499. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2500. redis.Set(keyOne, "", time.Second)
  2501. //结束时候透析次数加1
  2502. service.UpdateSolutionByPatientId(id)
  2503. //下机完自动消毒,针对长沙南雅
  2504. if dialysisOrder.Stage == 1 {
  2505. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2506. //根据床位号获取设备型号
  2507. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2508. //查询使用消毒最后一条消毒记录
  2509. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2510. fmt.Println("err", err)
  2511. if err == gorm.ErrRecordNotFound {
  2512. //查找排班
  2513. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2514. //查询改设备是否有消毒计划
  2515. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2516. //根据床位号获取设备id
  2517. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2518. //查询病人信息
  2519. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2520. var con = ""
  2521. if patients.IsInfectious == 0 {
  2522. con = ""
  2523. }
  2524. if patients.IsInfectious == 1 {
  2525. con = "无"
  2526. }
  2527. if patients.IsInfectious == 2 {
  2528. con = "有"
  2529. }
  2530. if errcode == nil {
  2531. var end_time int64
  2532. end_time = endDate.Unix() + plan.DisinfecTime*60
  2533. //新增消毒
  2534. information := models.DeviceInformation{
  2535. Date: dialysisOrder.DialysisDate,
  2536. Zone: dialysisOrder.ZoneId,
  2537. Class: dialysisOrder.SchedualType,
  2538. BedNumber: dialysisOrder.BedID,
  2539. PatientId: dialysisOrder.PatientId,
  2540. DialysisMode: scheduleByPatient.ModeId,
  2541. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2542. Disinfection: 1,
  2543. DialysisConcentration: 1,
  2544. DisinfectionStatus: 1,
  2545. Move: 1,
  2546. UserOrgId: dialysisOrder.UserOrgId,
  2547. DisinfectType: plan.Way,
  2548. DisinfectantType: plan.MachineDisinfectant,
  2549. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2550. Disinfectant: plan.Disinfectant,
  2551. Ctime: time.Now().Unix(),
  2552. Status: 1,
  2553. SignName: nurseID,
  2554. EquimentId: addmacher.ID,
  2555. DisinfectionResidue: 2,
  2556. Bed: addmacher.BedNumber,
  2557. StartTime: dialysisOrder.StartTime,
  2558. EndTime: dialysisOrder.EndTime,
  2559. Contagion: con,
  2560. WeightLoss: 0,
  2561. Hyperfiltratio: 0,
  2562. DialysisHour: "",
  2563. MachineRun: 1,
  2564. DisinfecStartime: endDate.Unix(),
  2565. DisinfecEndtime: end_time,
  2566. }
  2567. err := service.CreateInformationTwo(&information)
  2568. fmt.Println("报错", err)
  2569. }
  2570. }
  2571. }
  2572. }
  2573. dialysisOrder.Stage = 2
  2574. dialysisOrder.FinishNurse = nurseID
  2575. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2576. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2577. dialysisOrder.EndTime = endDate.Unix()
  2578. // 长沙南雅需求
  2579. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2580. //获取最后1条监测的数据
  2581. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2582. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2583. var accumulatedBloodVolume float64
  2584. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2585. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2586. fmt.Println(err)
  2587. // 查询未执行的医嘱
  2588. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2589. for _, item := range doctorAdvice {
  2590. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2592. redis := service.RedisClient()
  2593. //清空key 值
  2594. redis.Set(key, "", time.Second)
  2595. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2596. redis.Set(keyTwo, "", time.Second)
  2597. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2598. redis.Set(keyThree, "", time.Second)
  2599. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2600. theTime := toTime.Format("2006-01-02")
  2601. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2602. redis.Set(keyFour, "", time.Second)
  2603. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2604. redis.Set(keyFive, "", time.Second)
  2605. defer redis.Close()
  2606. }
  2607. }
  2608. go func() {
  2609. ssoDomain := beego.AppConfig.String("call_domain")
  2610. api := ssoDomain + "/index/downpatient"
  2611. values := make(url.Values)
  2612. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2613. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2614. values.Set("patient_id", strconv.FormatInt(id, 10))
  2615. http.PostForm(api, values)
  2616. }()
  2617. if err == nil {
  2618. c.ServeSuccessJSON(map[string]interface{}{
  2619. "dialysisOrder": dialysisOrder,
  2620. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2621. })
  2622. } else {
  2623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2624. }
  2625. }
  2626. }
  2627. func (c *DialysisAPIController) GetAllZone() {
  2628. adminUserInfo := c.GetMobileAdminUserInfo()
  2629. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2630. if err == nil {
  2631. c.ServeSuccessJSON(map[string]interface{}{
  2632. "zone": zone,
  2633. })
  2634. }
  2635. }
  2636. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2637. adminUserInfo := c.GetMobileAdminUserInfo()
  2638. page, _ := c.GetInt64("page", 1)
  2639. limit, _ := c.GetInt64("limit", 10)
  2640. schedulType, _ := c.GetInt64("schedul_type", 0)
  2641. startTime, _ := c.GetInt64("schedul_time", 0)
  2642. partitionType, _ := c.GetInt64("partition_type", 0)
  2643. keywords := c.GetString("keywords")
  2644. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2645. if err == nil {
  2646. c.ServeSuccessJSON(map[string]interface{}{
  2647. "schedule": dialysisSchedule,
  2648. })
  2649. }
  2650. return
  2651. }
  2652. // /m/api/dialysis/start [post]
  2653. // @param patient_id:int
  2654. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2655. // @param nurse:int 上机护士
  2656. // @param bed:int 床位号
  2657. func (this *DialysisAPIController) StartDialysis() {
  2658. patientID, _ := this.GetInt64("patient_id")
  2659. recordDateStr := this.GetString("record_date")
  2660. nurseID, _ := this.GetInt64("start_nurse")
  2661. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2662. blood_drawing, _ := this.GetInt64("blood_drawing")
  2663. schedual_type, _ := this.GetInt64("schedual_type")
  2664. bedID, _ := this.GetInt64("bed")
  2665. start_time := this.GetString("start_time")
  2666. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2667. change_nurse, _ := this.GetInt64("change_nurse")
  2668. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2669. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2670. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2671. puncture_needle := this.GetString("puncture_needle")
  2672. puncture_way := this.GetString("puncture_way")
  2673. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2674. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2675. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2676. zone_id, _ := this.GetInt64("zone_id")
  2677. elecsign := this.GetString("url")
  2678. nuclein_date_str := this.GetString("nuclein_date_str")
  2679. schedule_remark := this.GetString("schedule_remark")
  2680. order_remark := this.GetString("order_remark")
  2681. catheter_operation := this.GetString("catheter_operation")
  2682. blood_flow_volume := this.GetString("blood_flow_volume")
  2683. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. return
  2686. }
  2687. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2688. if parseStartDateErr != nil {
  2689. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2694. if parseErr != nil {
  2695. this.ErrorLog("时间解析失败:%v", parseErr)
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2697. return
  2698. }
  2699. adminUserInfo := this.GetMobileAdminUserInfo()
  2700. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2701. if getPatientErr != nil {
  2702. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2704. return
  2705. } else if patient == nil {
  2706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2707. return
  2708. }
  2709. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2710. if getNurseErr != nil {
  2711. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2713. return
  2714. } else if nurse == nil {
  2715. this.ErrorLog("护士不存在")
  2716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2717. return
  2718. }
  2719. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2720. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2721. if getDeviceNumberErr != nil {
  2722. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2724. return
  2725. } else if deviceNumber == nil {
  2726. this.ErrorLog("床位号不存在")
  2727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2728. return
  2729. }
  2730. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2731. if getRecordErr != nil {
  2732. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. return
  2735. } else if dialysisRecord != nil {
  2736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2737. return
  2738. }
  2739. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2740. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2741. timeLayout := "2006-01-02 15:04:05"
  2742. loc, _ := time.LoadLocation("Local")
  2743. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2744. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2745. schedulestartTime := theStartTime.Unix()
  2746. scheduleendTime := theEndTime.Unix()
  2747. var theNucleinDate int64
  2748. timeLayoutOne := "2006-01-02"
  2749. if len(nuclein_date_str) > 0 {
  2750. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2751. if err != nil {
  2752. utils.ErrorLog(err.Error())
  2753. }
  2754. theNucleinDate = theTime.Unix()
  2755. }
  2756. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2757. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2758. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2759. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2760. //查询该床位是否有人用了
  2761. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2762. if err == gorm.ErrRecordNotFound { //空床位
  2763. // 修改了床位逻辑
  2764. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2765. if daySchedule.ID > 0 {
  2766. daySchedule.PartitionId = deviceNumber.ZoneID
  2767. daySchedule.BedId = bedID
  2768. daySchedule.ScheduleType = schedual_type
  2769. daySchedule.UpdatedTime = time.Now().Unix()
  2770. xtSchedule := models.Schedule{
  2771. PartitionId: deviceNumber.ZoneID,
  2772. BedId: bedID,
  2773. ScheduleType: schedual_type,
  2774. UpdatedTime: time.Now().Unix(),
  2775. }
  2776. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2777. if err != nil {
  2778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2779. return
  2780. }
  2781. }
  2782. } else if err == nil {
  2783. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2784. if order.ID > 0 { //该机位被其他人占用了
  2785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2786. return
  2787. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2788. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2789. if daySchedule.ID > 0 {
  2790. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2791. if err != nil {
  2792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2793. return
  2794. }
  2795. }
  2796. }
  2797. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2799. return
  2800. }
  2801. //else if order.ID == 0 { //该床位没被占用
  2802. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2803. // if daySchedule.ID > 0 {
  2804. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2805. // //daySchedule.BedId = bedID
  2806. // //daySchedule.ScheduleType = schedual_type
  2807. // //daySchedule.UpdatedTime = time.Now().Unix()
  2808. // //err := service.UpdateSchedule(&daySchedule)
  2809. // xtSchedule := models.Schedule{
  2810. // PartitionId: deviceNumber.ZoneID,
  2811. // BedId: bedID,
  2812. // ScheduleType: schedual_type,
  2813. // UpdatedTime: time.Now().Unix(),
  2814. // }
  2815. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2816. // if err != nil {
  2817. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2818. // return
  2819. // }
  2820. // }
  2821. //}
  2822. //}
  2823. } else if err != nil {
  2824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2825. return
  2826. }
  2827. // 查询信息规挡的设置天数
  2828. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2829. if infor.ID > 0 && infor.WeekDay > 0 {
  2830. var cha_time int64
  2831. timeNowStr := time.Now().Format("2006-01-02")
  2832. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2833. //今日的日期减去设置的日期
  2834. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2835. if cha_time >= recordDate.Unix() {
  2836. //查询审核是否允许
  2837. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2838. //申请状态不允许的情况 拒绝修改
  2839. if infor.ApplicationStatus != 1 {
  2840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2841. return
  2842. }
  2843. }
  2844. }
  2845. dialysisRecord = &models.DialysisOrder{
  2846. DialysisDate: recordDate.Unix(),
  2847. UserOrgId: adminUserInfo.Org.Id,
  2848. PatientId: patientID,
  2849. Stage: 1,
  2850. BedID: bedID,
  2851. StartNurse: nurseID,
  2852. Status: 1,
  2853. StartTime: startDate.Unix(),
  2854. CreatedTime: time.Now().Unix(),
  2855. UpdatedTime: time.Now().Unix(),
  2856. PunctureNurse: puncture_nurse,
  2857. Creator: adminUserInfo.AdminUser.Id,
  2858. Modifier: adminUserInfo.AdminUser.Id,
  2859. SchedualType: schedual_type,
  2860. WashpipeNurse: washpipe_nurse,
  2861. ChangeNurse: change_nurse,
  2862. DifficultPunctureNurse: difficult_puncture_nurse,
  2863. NewFistulaNurse: new_fistula_nurse,
  2864. ZoneId: zone_id,
  2865. QualityNurseId: quality_nurse_id,
  2866. PunctureNeedle: puncture_needle,
  2867. PunctureWay: puncture_way,
  2868. DialysisIrrigation: dialysis_irrigation,
  2869. DialysisDialyszers: dialysis_dialyszers,
  2870. BloodAccessId: blood_access_id,
  2871. Url: elecsign,
  2872. NucleinDate: theNucleinDate,
  2873. ScheduleRemark: schedule_remark,
  2874. OrderRemark: order_remark,
  2875. CatheterOperation: catheter_operation,
  2876. BloodFlowVolume: blood_flow_volume,
  2877. BloodDrawing: blood_drawing,
  2878. }
  2879. //查询该床位是否有人用了
  2880. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2881. if errorscode == gorm.ErrRecordNotFound {
  2882. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2883. finish := models.XtDialysisFinish{
  2884. IsFinish: 1,
  2885. UserOrgId: adminUserInfo.Org.Id,
  2886. Status: 1,
  2887. Ctime: time.Now().Unix(),
  2888. Mtime: 0,
  2889. Module: 6,
  2890. RecordDate: schedulestartTime,
  2891. Sourse: 1,
  2892. PatientId: patientID,
  2893. }
  2894. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2895. if dialysisFinish.ID == 0 {
  2896. service.CreateDialysisFinish(finish)
  2897. }
  2898. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2899. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2900. //统计该患者总次数
  2901. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2902. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2903. }
  2904. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2905. //统计该患者总次数
  2906. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2907. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2908. }
  2909. redis := service.RedisClient()
  2910. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2911. redis.Set(key, "", time.Second)
  2912. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2913. //清空key 值
  2914. redis.Set(keyOne, "", time.Second)
  2915. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2916. //清空key 值
  2917. redis.Set(keyTwo, "", time.Second)
  2918. if createErr != nil {
  2919. this.ErrorLog("上机失败:%v", createErr)
  2920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2921. return
  2922. }
  2923. }
  2924. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2925. var tempdispose string
  2926. // 只针对中能建
  2927. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2928. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2929. }
  2930. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2931. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2932. }
  2933. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  2934. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2935. //}
  2936. var ultrafiltration_rate float64
  2937. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2938. //后期预增脱水量
  2939. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2940. if prescription.ID > 0 {
  2941. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2942. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2943. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2944. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2945. }
  2946. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  2947. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2948. }
  2949. //针对医师汇
  2950. if adminUserInfo.Org.Id == 10121 {
  2951. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2952. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2953. }
  2954. //针对通道
  2955. if adminUserInfo.Org.Id == 10234 {
  2956. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2957. }
  2958. //针对监利大垸医院
  2959. if template.TemplateId == 41 {
  2960. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2961. }
  2962. //针对肇庆三鹤血液透析中心
  2963. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2964. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2965. }
  2966. if adminUserInfo.Org.Id == 10469 {
  2967. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2968. }
  2969. if adminUserInfo.Org.Id == 10667 {
  2970. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2971. }
  2972. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2973. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2974. }
  2975. // 只针对方济医院
  2976. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2977. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2978. ultrafiltration_rate = value
  2979. }
  2980. //针对
  2981. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2982. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2983. ultrafiltration_rate = ultrafiltration_rate / 1000
  2984. }
  2985. if adminUserInfo.Org.Id == 10551 {
  2986. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2987. ultrafiltration_rate = ultrafiltration_rate / 1000
  2988. }
  2989. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  2990. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2991. ultrafiltration_rate = ultrafiltration_rate / 1000
  2992. }
  2993. if adminUserInfo.Org.Id == 10580 {
  2994. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2995. ultrafiltration_rate = ultrafiltration_rate / 1000
  2996. }
  2997. if adminUserInfo.Org.Id == 10629 {
  2998. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2999. ultrafiltration_rate = ultrafiltration_rate / 1000
  3000. }
  3001. if adminUserInfo.Org.Id == 10644 {
  3002. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3003. ultrafiltration_rate = ultrafiltration_rate / 1000
  3004. }
  3005. if adminUserInfo.Org.Id == 10667 {
  3006. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3007. ultrafiltration_rate = ultrafiltration_rate / 1000
  3008. }
  3009. }
  3010. }
  3011. record := models.MonitoringRecord{
  3012. UserOrgId: adminUserInfo.Org.Id,
  3013. PatientId: patientID,
  3014. DialysisOrderId: dialysisRecord.ID,
  3015. MonitoringDate: schedulestartTime,
  3016. OperateTime: startDate.Unix(),
  3017. // MonitoringTime: recordTime,
  3018. MonitoringNurse: nurseID,
  3019. Dispose: tempdispose,
  3020. UltrafiltrationRate: ultrafiltration_rate,
  3021. UltrafiltrationVolume: 0,
  3022. Status: 1,
  3023. CreatedTime: time.Now().Unix(),
  3024. UpdatedTime: time.Now().Unix(),
  3025. }
  3026. //只针对广慈医院
  3027. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3028. // 查询病人是否有透前评估数据
  3029. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3030. //如果有数据就插入
  3031. if errcode == nil {
  3032. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3033. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3034. record.BreathingRate = befor.BreathingRate
  3035. record.PulseFrequency = befor.PulseFrequency
  3036. record.Temperature = befor.Temperature
  3037. }
  3038. }
  3039. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3040. if newdialysisRecord.ID > 0 {
  3041. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3042. record.Temperature = 36.5
  3043. record.ArterialPressure = -100
  3044. record.DialysateTemperature = 36.5
  3045. record.Conductivity = 14
  3046. record.BreathingRate = "20"
  3047. record.VenousPressure = 80
  3048. record.TransmembranePressure = 60
  3049. record.Dispose = catheter_operation
  3050. }
  3051. //针对新化博翔
  3052. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3053. record.BloodOxygenSaturation = "99"
  3054. record.Conductivity = 14
  3055. record.DialysateTemperature = 36.5
  3056. record.BreathingRate = "20"
  3057. }
  3058. //针对兰溪人民医院的需求
  3059. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3060. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3061. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3062. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3063. record.Temperature = befor.Temperature
  3064. record.PulseFrequency = befor.PulseFrequency
  3065. record.BreathingRate = befor.BreathingRate
  3066. }
  3067. //针对乐山友谊医院的需求
  3068. if adminUserInfo.Org.Id == 10677 {
  3069. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3070. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3071. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3072. record.Temperature = befor.Temperature
  3073. record.PulseFrequency = befor.PulseFrequency
  3074. record.BreathingRate = befor.BreathingRate
  3075. }
  3076. //新化博翔
  3077. if adminUserInfo.Org.Id == 10447 {
  3078. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3079. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3080. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3081. record.BreathingRate = befor.BreathingRate
  3082. }
  3083. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3084. record.PulseFrequency = 80
  3085. record.Temperature = 36.5
  3086. }
  3087. //诊断灵山圣康
  3088. if adminUserInfo.Org.Id == 10375 {
  3089. record.Conductivity = 13.8
  3090. record.DialysateTemperature = 37
  3091. record.DialysateFlow = 500
  3092. record.BloodFlowVolume = 200
  3093. record.BreathingRate = "18"
  3094. record.SodiumConcentration = 140
  3095. }
  3096. //江成肾病医院
  3097. if adminUserInfo.Org.Id == 10517 {
  3098. record.SodiumConcentration = 138
  3099. record.DialysateTemperature = 36.5
  3100. }
  3101. if adminUserInfo.Org.Id != 10683 {
  3102. err = service.CreateMonitor(&record)
  3103. }
  3104. //记录日志
  3105. byterequest, _ := json.Marshal(record)
  3106. monitorRecordLog := models.XtMonitorRecordLog{
  3107. RecordDate: record.MonitoringDate,
  3108. PatientId: record.PatientId,
  3109. Module: 1,
  3110. AdminUserId: adminUserInfo.AdminUser.Id,
  3111. Ctime: time.Now().Unix(),
  3112. Mtime: 0,
  3113. Status: 1,
  3114. UserOrgId: record.UserOrgId,
  3115. ErrLog: string(byterequest),
  3116. Source: "执行上机时新增监测",
  3117. }
  3118. service.CreateMonitorRecordLog(monitorRecordLog)
  3119. finish := models.XtDialysisFinish{
  3120. IsFinish: 1,
  3121. UserOrgId: adminUserInfo.Org.Id,
  3122. Status: 1,
  3123. Ctime: time.Now().Unix(),
  3124. Mtime: 0,
  3125. Module: 7,
  3126. RecordDate: schedulestartTime,
  3127. Sourse: 1,
  3128. PatientId: patientID,
  3129. }
  3130. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3131. if dialysisFinish.ID == 0 {
  3132. service.CreateDialysisFinish(finish)
  3133. }
  3134. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3135. redis := service.RedisClient()
  3136. //清空key 值
  3137. redis.Set(key, "", time.Second)
  3138. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3139. redis.Set(keyOne, "", time.Second)
  3140. defer redis.Close()
  3141. if err != nil {
  3142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3143. return
  3144. }
  3145. }
  3146. go func() {
  3147. ssoDomain := beego.AppConfig.String("call_domain")
  3148. api := ssoDomain + "/index/uppatient"
  3149. values := make(url.Values)
  3150. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3151. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3152. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3153. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3154. http.PostForm(api, values)
  3155. }()
  3156. this.ServeSuccessJSON(map[string]interface{}{
  3157. "dialysis_order": newdialysisRecord,
  3158. "monitor": record,
  3159. })
  3160. return
  3161. }
  3162. func (c *DialysisAPIController) PostSolution() {
  3163. id, _ := c.GetInt64("patient", 0)
  3164. recordDateStr := c.GetString("record_date")
  3165. if id <= 0 {
  3166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3167. return
  3168. }
  3169. adminUserInfo := c.GetMobileAdminUserInfo()
  3170. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3171. if patient.ID == 0 {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3173. return
  3174. }
  3175. if len(recordDateStr) == 0 {
  3176. recordDateStr = time.Now().Format("2006-01-02")
  3177. }
  3178. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3179. if parseDateErr != nil {
  3180. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3182. return
  3183. }
  3184. mode_id, _ := c.GetInt64("mode_id", 0)
  3185. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3186. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3187. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3188. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3189. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3190. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3191. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3192. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3193. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3194. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3195. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3196. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3197. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3198. kalium, _ := c.GetFloat("kalium", 0)
  3199. sodium, _ := c.GetFloat("sodium", 0)
  3200. calcium, _ := c.GetFloat("calcium", 0)
  3201. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3202. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3203. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3204. glucose, _ := c.GetFloat("glucose", 0)
  3205. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3206. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3207. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3208. conductivity, _ := c.GetFloat("conductivity", 0)
  3209. remark := c.GetString("remark")
  3210. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3211. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3212. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3213. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3214. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3215. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3216. special_medicine_other := c.GetString("special_medicine_other")
  3217. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3218. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3219. blood_access, _ := c.GetInt64("blood_access", 0)
  3220. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3221. body_fluid_other := c.GetString("body_fluid_other")
  3222. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3223. niprocart, _ := c.GetInt64("niprocart", 0)
  3224. jms, _ := c.GetInt64("jms", 0)
  3225. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3226. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3227. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3228. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3229. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3230. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3231. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3232. injector, _ := c.GetInt64("injector", 0)
  3233. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3234. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3235. safe_package, _ := c.GetInt64("package", 0)
  3236. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3237. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3238. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3239. blood := c.GetString("blood")
  3240. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3241. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3242. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3243. displace_speed := c.GetString("displace_speed")
  3244. illness, _ := c.GetInt64("illness")
  3245. amylaceum := c.GetString("amylaceum")
  3246. single_time := c.GetString("single_time")
  3247. single_water := c.GetString("single_water")
  3248. replacement_flow := c.GetString("replacement_flow")
  3249. plasma_separator := c.GetString("plasma_separator")
  3250. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3251. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3252. oxygen_flow := c.GetString("oxygen_flow")
  3253. oxygen_time := c.GetString("oxygen_time")
  3254. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3255. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3256. puncture_needle := c.GetString("puncture_needle")
  3257. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3258. epo := c.GetString("epo")
  3259. epo_count, _ := c.GetFloat("epo_count", 0)
  3260. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3261. pre_impulse := c.GetString("pre_impulse")
  3262. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3263. admin_user_id, _ := c.GetInt64("admin_user_id")
  3264. is_water := c.GetString("is_water")
  3265. add_amount, _ := c.GetFloat("add_amount")
  3266. reduce_amount, _ := c.GetFloat("reduce_amount")
  3267. prescribing_number, _ := c.GetFloat("prescribing_number")
  3268. treatment_remark := c.GetString("treatment_remark")
  3269. prescription_sodium := c.GetString("prescription_sodium")
  3270. start_sodium := c.GetString("start_sodium")
  3271. sodium_curve := c.GetString("sodium_curve")
  3272. var is_war int64
  3273. if is_water == "是" {
  3274. is_war = 1
  3275. }
  3276. if is_water == "否" {
  3277. is_war = 2
  3278. }
  3279. if is_water == "请选择" {
  3280. is_war = 0
  3281. }
  3282. drhy_water := c.GetString("drhy_water")
  3283. dry_water_hour := c.GetString("dry_water_hour")
  3284. water_machine := c.GetString("water_machine")
  3285. dialysis_remark := c.GetString("dialysis_remark")
  3286. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3287. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3288. prescription_water, _ := c.GetFloat("prescription_water")
  3289. dialysis_strainer := c.GetString("dialysis_strainer")
  3290. chaptalization := c.GetString("chaptalization")
  3291. washing_time := c.GetString("washing_time")
  3292. warsh_count := c.GetString("warsh_count")
  3293. blood_access_part_id := c.GetString("blood_access_part_id")
  3294. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3295. dialyzate := c.GetString("dialyzate")
  3296. if mode_id > 0 {
  3297. var str string
  3298. //查找该机构用的是什么透析器
  3299. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3300. if filedConfig.ID > 0 {
  3301. str = dialyzerPerfusionApparatus
  3302. } else {
  3303. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3304. }
  3305. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3306. }
  3307. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3308. //
  3309. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3310. // if appRole.UserType == 3 {
  3311. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3312. // if getPermissionErr != nil {
  3313. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3314. // return
  3315. // } else if headNursePermission == nil {
  3316. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3317. // return
  3318. // }
  3319. // }
  3320. //}
  3321. // 查询信息规挡的设置天数
  3322. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3323. if infor.ID > 0 && infor.WeekDay > 0 {
  3324. var cha_time int64
  3325. timeNowStr := time.Now().Format("2006-01-02")
  3326. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3327. //今日的日期减去设置的日期
  3328. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3329. if cha_time >= recordDate.Unix() {
  3330. //查询审核是否允许
  3331. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3332. //申请状态不允许的情况 拒绝修改
  3333. if infor.ApplicationStatus != 1 {
  3334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3335. return
  3336. }
  3337. }
  3338. }
  3339. prescription := models.DialysisPrescription{
  3340. UserOrgId: adminUserInfo.Org.Id,
  3341. PatientId: id,
  3342. RecordDate: recordDate.Unix(),
  3343. ModeId: mode_id,
  3344. DialysisDuration: dialysis_duration,
  3345. Dialyzer: dialyzer,
  3346. PerfusionApparatus: perfusion_apparatus,
  3347. BloodFlowVolume: blood_flow_volume,
  3348. DewaterAmount: dewater_amount,
  3349. DisplaceLiqui: displace_liqui,
  3350. ReplacementWay: replacement_way,
  3351. Anticoagulant: anticoagulant,
  3352. AnticoagulantShouji: anticoagulant_shouji,
  3353. AnticoagulantWeichi: anticoagulant_weichi,
  3354. AnticoagulantZongliang: anticoagulant_zongliang,
  3355. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3356. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3357. Kalium: kalium,
  3358. Sodium: sodium,
  3359. Calcium: calcium,
  3360. Bicarbonate: bicarbonate,
  3361. Glucose: glucose,
  3362. // DryWeight: dry_weight,
  3363. DialysateFlow: dialysate_flow,
  3364. DialysateTemperature: dialysate_temperature,
  3365. Conductivity: conductivity,
  3366. Remark: remark,
  3367. Status: 1,
  3368. CreatedTime: time.Now().Unix(),
  3369. UpdatedTime: time.Now().Unix(),
  3370. DialysisDurationMinute: dialysisDurationMinute,
  3371. DialysisDurationHour: dialysisDurationHour,
  3372. TargetUltrafiltration: targetUltrafiltration,
  3373. DialysateFormulation: dialysateFormulation,
  3374. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3375. BodyFluid: body_fluid,
  3376. SpecialMedicine: special_medicine,
  3377. SpecialMedicineOther: special_medicine_other,
  3378. DisplaceLiquiPart: displace_liqui_part,
  3379. DisplaceLiquiValue: displace_liqui_value,
  3380. BloodAccess: blood_access,
  3381. Ultrafiltration: ultrafiltration,
  3382. BodyFluidOther: body_fluid_other,
  3383. ReplacementTotal: replacement_total,
  3384. Niprocart: niprocart,
  3385. Jms: jms,
  3386. FistulaNeedleSet: fistula_needle_set,
  3387. FistulaNeedleSet16: fistula_needle_set_16,
  3388. Hemoperfusion: hemoperfusion,
  3389. DialyserSterilised: dialyser_sterilised,
  3390. Filtryzer: filtryzer,
  3391. TargetKtv: target_ktv,
  3392. Dialyzers: dialyzers,
  3393. Injector: injector,
  3394. Bloodlines: bloodlines,
  3395. TubingHemodialysis: tubing_hemodialysis,
  3396. Package: safe_package,
  3397. ALiquid: a_liquid,
  3398. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3399. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3400. Blood: blood,
  3401. DialysisDialyszers: dialysis_dialyszers,
  3402. DialysisIrrigation: dialysis_irrigation,
  3403. AntioxidantCommodityName: antioxidant_commodity_name,
  3404. DisplaceSpeed: displace_speed,
  3405. Illness: illness,
  3406. Amylaceum: amylaceum,
  3407. SingleWater: single_water,
  3408. SingleTime: single_time,
  3409. ReplacementFlow: replacement_flow,
  3410. PlasmaSeparator: plasma_separator,
  3411. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3412. OxygenUptake: oxygen_uptake,
  3413. OxygenTime: oxygen_time,
  3414. OxygenFlow: oxygen_flow,
  3415. HemodialysisPipelines: hemodialysis_pipelines,
  3416. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3417. PunctureNeedle: puncture_needle,
  3418. PunctureNeedleCount: puncture_needle_count,
  3419. Epo: epo,
  3420. EpoCount: epo_count,
  3421. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3422. PreImpulse: impulse,
  3423. AdminUserId: admin_user_id,
  3424. IsWater: is_war,
  3425. DrhyWater: drhy_water,
  3426. DryWaterHour: dry_water_hour,
  3427. WaterMachine: water_machine,
  3428. AddAmount: add_amount,
  3429. ReduceAmount: reduce_amount,
  3430. DialysisRemark: dialysis_remark,
  3431. PrescribingNumber: prescribing_number,
  3432. PrescriptionSodium: prescription_sodium,
  3433. StartSodium: start_sodium,
  3434. SodiumCurve: sodium_curve,
  3435. TreatmentRemark: treatment_remark,
  3436. DialysisFluidFlow: dialysis_fluid_flow,
  3437. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3438. PrescriptionWater: prescription_water,
  3439. DialysisStrainer: dialysis_strainer,
  3440. Chaptalization: chaptalization,
  3441. WashingTime: washing_time,
  3442. WarshCount: warsh_count,
  3443. BloodAccessPartId: blood_access_part_id,
  3444. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3445. Dialyzate: dialyzate,
  3446. }
  3447. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3448. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3449. //
  3450. if appRole.UserType == 2 || appRole.UserType == 1 {
  3451. prescription_doctor = adminUserInfo.AdminUser.Id
  3452. prescription.PrescriptionDoctor = prescription_doctor
  3453. }
  3454. if dialysisPrescription.ID == 0 { //新增
  3455. prescription.Creater = adminUserInfo.AdminUser.Id
  3456. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3457. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3458. }
  3459. } else { //修改
  3460. if dialysisPrescription.Creater == 0 {
  3461. prescription.Creater = adminUserInfo.AdminUser.Id
  3462. } else {
  3463. prescription.Creater = dialysisPrescription.Creater
  3464. if adminUserInfo.Org.Id == 9882 {
  3465. if appRole.UserType == 2 || appRole.UserType == 1 {
  3466. prescription.Creater = adminUserInfo.AdminUser.Id
  3467. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3468. }
  3469. }
  3470. }
  3471. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3472. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3473. }
  3474. //if/**/
  3475. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3476. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3477. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3478. // if getPermissionErr != nil {
  3479. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3480. // return
  3481. // } else if headNursePermission == nil {
  3482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3483. // return
  3484. // }
  3485. //}
  3486. //prescription.Creater = dialysisPrescription.Creater
  3487. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3488. prescription.Modifier = adminUserInfo.AdminUser.Id
  3489. prescription.ID = dialysisPrescription.ID
  3490. }
  3491. solution := models.DialysisSolution{
  3492. RegistrarsId: adminUserInfo.AdminUser.Id,
  3493. UserOrgId: adminUserInfo.Org.Id,
  3494. Doctor: prescription_doctor,
  3495. PatientId: id,
  3496. ModeId: mode_id,
  3497. DialysisDuration: dialysis_duration,
  3498. PerfusionApparatus: perfusion_apparatus,
  3499. BloodFlowVolume: blood_flow_volume,
  3500. Dewater: dewater_amount,
  3501. DisplaceLiqui: displace_liqui,
  3502. ReplacementWay: replacement_way,
  3503. Anticoagulant: anticoagulant,
  3504. AnticoagulantShouji: anticoagulant_shouji,
  3505. AnticoagulantWeichi: anticoagulant_weichi,
  3506. AnticoagulantZongliang: anticoagulant_zongliang,
  3507. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3508. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3509. Kalium: kalium,
  3510. Sodium: sodium,
  3511. Calcium: calcium,
  3512. Bicarbonate: bicarbonate,
  3513. Glucose: glucose,
  3514. // DryWeight: dry_weight,
  3515. DialysateFlow: dialysate_flow,
  3516. DialysateTemperature: dialysate_temperature,
  3517. Conductivity: conductivity,
  3518. Remark: remark,
  3519. Status: 1,
  3520. CreatedTime: time.Now().Unix(),
  3521. UpdatedTime: time.Now().Unix(),
  3522. DialysisDurationMinute: dialysisDurationMinute,
  3523. DialysisDurationHour: dialysisDurationHour,
  3524. TargetUltrafiltration: targetUltrafiltration,
  3525. DialysateFormulation: dialysateFormulation,
  3526. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3527. BodyFluid: body_fluid,
  3528. SpecialMedicine: special_medicine,
  3529. SpecialMedicineOther: special_medicine_other,
  3530. DisplaceLiquiPart: displace_liqui_part,
  3531. DisplaceLiquiValue: displace_liqui_value,
  3532. BloodAccess: blood_access,
  3533. Ultrafiltration: ultrafiltration,
  3534. BodyFluidOther: body_fluid_other,
  3535. ReplacementTotal: replacement_total,
  3536. TargetKtv: target_ktv,
  3537. DialysisDialyszers: dialysis_dialyszers,
  3538. DialysisIrrigation: dialysis_irrigation,
  3539. HemodialysisPipelines: hemodialysis_pipelines,
  3540. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3541. PunctureNeedle: puncture_needle,
  3542. PunctureNeedleCount: puncture_needle_count,
  3543. Epo: epo,
  3544. EpoCount: epo_count,
  3545. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3546. PreImpulse: impulse,
  3547. SolutionStatus: 1,
  3548. DialysisRemark: dialysis_remark,
  3549. PrescribingNumber: prescribing_number,
  3550. PrescriptionSodium: prescription_sodium,
  3551. StartSodium: start_sodium,
  3552. SodiumCurve: sodium_curve,
  3553. TreatmentRemark: treatment_remark,
  3554. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3555. DialysisFluidFlow: dialysis_fluid_flow,
  3556. PrescriptionWater: prescription_water,
  3557. DialysisStrainer: dialysis_strainer,
  3558. Chaptalization: chaptalization,
  3559. WashingTime: washing_time,
  3560. WarshCount: warsh_count,
  3561. BloodAccessPartId: blood_access_part_id,
  3562. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3563. Dialyzate: dialyzate,
  3564. }
  3565. //针对河间咸的
  3566. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3567. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3568. solution.DisplaceLiquiPart = 0
  3569. solution.DisplaceLiquiValue = 0
  3570. }
  3571. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3572. prescription.DisplaceLiquiPart = 0
  3573. prescription.DisplaceLiquiValue = 0
  3574. }
  3575. }
  3576. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3577. if solution.PrescribingNumber == 0 {
  3578. solution.PrescribingNumber = 1
  3579. }
  3580. if prescription.PrescribingNumber == 0 {
  3581. prescription.PrescribingNumber = 1
  3582. }
  3583. if solution.PrescribingNumber == 0 && id == 14682 {
  3584. solution.PrescribingNumber = 2
  3585. }
  3586. if solution.PrescribingNumber == 0 && id == 18560 {
  3587. solution.PrescribingNumber = 2
  3588. }
  3589. if prescription.PrescribingNumber == 0 && id == 14682 {
  3590. prescription.PrescribingNumber = 2
  3591. }
  3592. if prescription.PrescribingNumber == 0 && id == 18560 {
  3593. prescription.PrescribingNumber = 2
  3594. }
  3595. }
  3596. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3597. //记录日志
  3598. byterequest, _ := json.Marshal(prescription)
  3599. prescriptionLog := models.XtDialysisPrescriptionLog{
  3600. UserOrgId: prescription.UserOrgId,
  3601. Ctime: time.Now().Unix(),
  3602. Mtime: 0,
  3603. ErrLog: string(byterequest),
  3604. AdminUserId: adminUserInfo.AdminUser.Id,
  3605. RecordDate: prescription.RecordDate,
  3606. PatientId: prescription.PatientId,
  3607. Source: "手机端新增长期处方",
  3608. Status: 1,
  3609. }
  3610. service.CreatePrescriptionLog(prescriptionLog)
  3611. finish := models.XtDialysisFinish{
  3612. IsFinish: 1,
  3613. UserOrgId: adminUserInfo.Org.Id,
  3614. Status: 1,
  3615. Ctime: time.Now().Unix(),
  3616. Mtime: 0,
  3617. Module: 1,
  3618. RecordDate: recordDate.Unix(),
  3619. Sourse: 1,
  3620. PatientId: id,
  3621. }
  3622. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3623. if dialysisFinish.ID == 0 {
  3624. service.CreateDialysisFinish(finish)
  3625. }
  3626. //获取最新1条
  3627. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3628. //更新状态
  3629. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3630. //长沙南雅医院,自动生成抗凝剂的临时处方
  3631. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3632. if prescribing_number == 0 {
  3633. prescribing_number = 1
  3634. }
  3635. advice := models.DoctorAdvice{
  3636. UserOrgId: adminUserInfo.Org.Id,
  3637. PatientId: id,
  3638. GroupNo: 0,
  3639. AdviceType: 2,
  3640. RecordDate: recordDate.Unix(),
  3641. AdviceDate: recordDate.Unix(),
  3642. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3643. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3644. AdviceDesc: "",
  3645. ReminderDate: 0,
  3646. SingleDose: prescription.AnticoagulantZongliang,
  3647. SingleDoseUnit: "iu",
  3648. DrugSpec: 0,
  3649. DrugSpecUnit: "",
  3650. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3651. PrescribingNumberUnit: "支",
  3652. DeliveryWay: "静脉注射",
  3653. ExecutionFrequency: "上机前",
  3654. AdviceDoctor: 0,
  3655. Status: 1,
  3656. CreatedTime: time.Now().Unix(),
  3657. UpdatedTime: time.Now().Unix(),
  3658. IsPrescription: 1,
  3659. ExecutionState: 2,
  3660. StopState: 2,
  3661. IsSettle: 2,
  3662. }
  3663. // 查询排班信息
  3664. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3665. if schedulePatient.ID > 0 {
  3666. if schedulePatient.ScheduleType == 1 {
  3667. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3668. }
  3669. if schedulePatient.ScheduleType == 2 {
  3670. advice.StartTime = recordDate.Unix() + 9*60*60
  3671. }
  3672. }
  3673. // 抗凝剂名称
  3674. switch anticoagulant {
  3675. case 1:
  3676. advice.AdviceName = "无肝素"
  3677. break
  3678. case 2:
  3679. advice.AdviceName = "普通肝素"
  3680. break
  3681. case 3:
  3682. advice.AdviceName = "低分子肝素"
  3683. break
  3684. case 4:
  3685. advice.AdviceName = "阿加曲班"
  3686. break
  3687. case 5:
  3688. advice.AdviceName = "枸橼酸钠"
  3689. break
  3690. case 6:
  3691. advice.AdviceName = "低分子肝素钙"
  3692. break
  3693. case 7:
  3694. advice.AdviceName = "低分子肝素钠"
  3695. break
  3696. case 8:
  3697. advice.AdviceName = "依诺肝素"
  3698. break
  3699. case 9:
  3700. advice.AdviceName = "达肝素"
  3701. break
  3702. case 10:
  3703. advice.AdviceName = "体外抗凝"
  3704. break
  3705. case 11:
  3706. advice.AdviceName = "那曲肝素"
  3707. break
  3708. case 12:
  3709. advice.AdviceName = "无抗凝剂"
  3710. break
  3711. }
  3712. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3713. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3714. advice.AdviceDoctor = appRole.AdminUserId
  3715. }
  3716. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3717. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3718. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3719. advice.AdviceName = "低分子肝素钠注射液"
  3720. // 修改患者临时医嘱里的抗凝剂医嘱
  3721. advice.ID = advicePrescription.ID
  3722. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3723. } else {
  3724. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3725. advice.AdviceName = "低分子肝素钠注射液"
  3726. service.CreateDoctorAdvice(&advice)
  3727. }
  3728. }
  3729. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3730. redis := service.RedisClient()
  3731. defer redis.Close()
  3732. //清空key 值
  3733. redis.Set(key, "", time.Second)
  3734. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3735. redis.Set(keyOne, "", time.Second)
  3736. }
  3737. //获取key,清空redis
  3738. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3739. redis := service.RedisClient()
  3740. defer redis.Close()
  3741. //清空key 值
  3742. redis.Set(key, "", time.Second)
  3743. //清空长期医嘱的key
  3744. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3745. redis.Set(soulution_key, "", time.Second)
  3746. //查询最近透析准备表里是否存在 透析器 灌流器
  3747. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3748. redis.Set(keyOne, "", time.Second)
  3749. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3750. redis.Set(keyTwo, "", time.Second)
  3751. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3752. redis.Set(keyThree, "", time.Second)
  3753. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3754. redis.Set(keyFour, "", time.Second)
  3755. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3756. //
  3757. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3758. //
  3759. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3760. //if len(mation)>0{
  3761. // for _, item := range splitStr {
  3762. // for _,it := range mation{
  3763. // if(item == it.SpecificationName){
  3764. //
  3765. // //查询最近一次的透析器
  3766. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3767. //
  3768. // if errcode == gorm.ErrRecordNotFound{
  3769. // //插入数据
  3770. // prepare := models.DialysisBeforePrepare{
  3771. // UserOrgId: adminUserInfo.Org.Id,
  3772. // PatientId: id,
  3773. // RecordDate: recordDate.Unix(),
  3774. // GoodTypeId: it.GoodTypeId,
  3775. // GoodId: it.ID,
  3776. // Count: 1,
  3777. // Ctime: time.Now().Unix(),
  3778. // Creater: adminUserInfo.AdminUser.Id,
  3779. // Status:1,
  3780. //
  3781. // }
  3782. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3783. // fmt.Println("",errcode)
  3784. // }
  3785. // }
  3786. // }
  3787. //
  3788. // }
  3789. //
  3790. // for _, item := range splitIrrigation {
  3791. // for _,it := range mation{
  3792. // if(item == it.SpecificationName){
  3793. // //查询最近一次的透析器
  3794. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3795. // if errcode == gorm.ErrRecordNotFound{
  3796. // //插入数据
  3797. // prepare := models.DialysisBeforePrepare{
  3798. // UserOrgId: adminUserInfo.Org.Id,
  3799. // PatientId: id,
  3800. // RecordDate: recordDate.Unix(),
  3801. // GoodTypeId: it.GoodTypeId,
  3802. // GoodId: it.ID,
  3803. // Count: 1,
  3804. // Ctime: time.Now().Unix(),
  3805. // Creater: adminUserInfo.AdminUser.Id,
  3806. // Status:1,
  3807. //
  3808. // }
  3809. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3810. // fmt.Println(errcode)
  3811. // }
  3812. // }
  3813. // }
  3814. // }
  3815. //}
  3816. c.ServeSuccessJSON(map[string]interface{}{
  3817. "solution": &solution,
  3818. "prescription": &prescription,
  3819. })
  3820. }
  3821. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3822. patient, _ := c.GetInt64("patient", 0)
  3823. adminUserInfo := c.GetMobileAdminUserInfo()
  3824. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3825. c.ServeSuccessJSON(map[string]interface{}{
  3826. "receiveTreatmentAsses": receiveTreatmentAsses,
  3827. })
  3828. }
  3829. func (this *DialysisAPIController) PostSignInfo() {
  3830. patientID, _ := this.GetInt64("patient_id")
  3831. recordDateStr := this.GetString("date")
  3832. if patientID <= 0 {
  3833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3834. return
  3835. }
  3836. if len(recordDateStr) == 0 {
  3837. recordDateStr = time.Now().Format("2006-01-02")
  3838. }
  3839. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3840. if parseDateErr != nil {
  3841. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3843. return
  3844. }
  3845. adminInfo := this.GetMobileAdminUserInfo()
  3846. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3847. if err != nil {
  3848. this.ErrorLog("签名失败:%v", err)
  3849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3850. return
  3851. }
  3852. this.ServeSuccessJSON(map[string]interface{}{
  3853. "doctor_id": adminInfo.AdminUser.Id,
  3854. })
  3855. }
  3856. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3857. patientID, _ := this.GetInt64("patient_id")
  3858. adminInfo := this.GetMobileAdminUserInfo()
  3859. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3860. this.ServeSuccessJSON(map[string]interface{}{
  3861. "monitor": record,
  3862. })
  3863. }
  3864. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3865. thisTime := time.Now()
  3866. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3867. timeLayout := "2006-01-02 15:04:05"
  3868. loc, _ := time.LoadLocation("Local")
  3869. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3870. theAssessmentDateTime := theStartTime.Unix()
  3871. patientID, _ := this.GetInt64("patient_id")
  3872. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3873. adminInfo := this.GetMobileAdminUserInfo()
  3874. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3875. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3876. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3877. var ultrafiltration_rate float64
  3878. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3879. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3880. fmt.Println(evaluation)
  3881. fmt.Println("prescription.ID", prescription.ID)
  3882. if prescription.ID > 0 {
  3883. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3884. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3885. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3886. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3887. record.UltrafiltrationRate = ultrafiltration_rate
  3888. }
  3889. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  3890. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3891. record.UltrafiltrationRate = ultrafiltration_rate
  3892. }
  3893. if adminInfo.Org.Id == 10510 {
  3894. record.UltrafiltrationRate = 0
  3895. }
  3896. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3897. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3898. record.UltrafiltrationRate = ultrafiltration_rate
  3899. }
  3900. if template.TemplateId == 20 || template.TemplateId == 22 {
  3901. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3902. record.UltrafiltrationRate = ultrafiltration_rate
  3903. }
  3904. // 只针对方济医院
  3905. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3906. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3907. ultrafiltration_rate = value
  3908. record.UltrafiltrationRate = ultrafiltration_rate
  3909. }
  3910. if template.TemplateId == 41 || template.TemplateId == 47 {
  3911. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3912. record.UltrafiltrationRate = ultrafiltration_rate
  3913. }
  3914. if template.TemplateId == 43 {
  3915. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3916. record.UltrafiltrationRate = ultrafiltration_rate
  3917. }
  3918. if template.TemplateId == 46 || template.TemplateId == 54 {
  3919. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3920. record.UltrafiltrationRate = ultrafiltration_rate
  3921. }
  3922. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  3923. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3924. record.UltrafiltrationRate = ultrafiltration_rate
  3925. }
  3926. if adminInfo.Org.Id == 10469 {
  3927. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3928. record.UltrafiltrationRate = ultrafiltration_rate
  3929. }
  3930. if adminInfo.Org.Id == 10667 {
  3931. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3932. record.UltrafiltrationRate = ultrafiltration_rate
  3933. }
  3934. if adminInfo.Org.Id == 10471 {
  3935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3936. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3937. }
  3938. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  3939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3940. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3941. }
  3942. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  3943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3944. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3945. }
  3946. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  3947. record.UltrafiltrationRate = 0
  3948. }
  3949. //if template.TemplateId == 47 {
  3950. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3951. // record.UltrafiltrationRate = ultrafiltration_rate
  3952. //}
  3953. }
  3954. }
  3955. // record.UltrafiltrationRate = ultrafiltration_rate
  3956. record.UltrafiltrationVolume = 0
  3957. 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
  3958. if ultrafiltration_rate > 0 {
  3959. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3960. record.UltrafiltrationVolume = value
  3961. }
  3962. }
  3963. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  3964. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3965. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3966. record.UltrafiltrationVolume = ultrafiltration_volume
  3967. }
  3968. }
  3969. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  3970. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3971. record.UltrafiltrationVolume = ultrafiltration_volume
  3972. }
  3973. //长沙南雅
  3974. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  3975. if ultrafiltration_rate > 0 {
  3976. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3977. record.UltrafiltrationVolume = ultrafiltration_volume
  3978. }
  3979. }
  3980. if adminInfo.Org.Id == 10471 {
  3981. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3982. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3983. }
  3984. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  3985. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3986. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3987. }
  3988. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3989. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3990. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3991. }
  3992. //长沙南雅累计血容量自动计算
  3993. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3994. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3995. //}
  3996. if template.TemplateId == 47 || template.TemplateId == 54 {
  3997. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3998. }
  3999. if adminInfo.Org.Id == 10510 {
  4000. record.UltrafiltrationVolume = 0
  4001. }
  4002. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4003. this.ServeSuccessJSON(map[string]interface{}{
  4004. "monitor": record,
  4005. "lastMonitorRecordList": lastMonitorRecordList,
  4006. })
  4007. }
  4008. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4009. record_id, _ := this.GetInt64("id")
  4010. nurseID, _ := this.GetInt64("start_nurse")
  4011. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4012. bedID, _ := this.GetInt64("bed")
  4013. start_time := this.GetString("start_time")
  4014. schedual_type, _ := this.GetInt64("schedual_type")
  4015. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4016. change_nurse, _ := this.GetInt64("change_nurse")
  4017. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4018. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4019. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4020. patient_id, _ := this.GetInt64("patient_id")
  4021. record_date, _ := this.GetInt64("record_date")
  4022. puncture_needle := this.GetString("puncture_needle")
  4023. puncture_way := this.GetString("puncture_way")
  4024. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4025. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4026. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4027. nuclein_date_str := this.GetString("nuclein_date_str")
  4028. order_remark := this.GetString("order_remark")
  4029. schedule_remark := this.GetString("schedule_remark")
  4030. catheter_operation := this.GetString("catheter_operation")
  4031. blood_flow_volume := this.GetString("blood_flow_volume")
  4032. blood_drawing, _ := this.GetInt64("blood_drawing")
  4033. if record_id == 0 {
  4034. this.ErrorLog("id:%v", record_id)
  4035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4036. return
  4037. }
  4038. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4039. if parseStartDateErr != nil {
  4040. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4042. return
  4043. }
  4044. adminUserInfo := this.GetMobileAdminUserInfo()
  4045. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4046. if getNurseErr != nil {
  4047. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4049. return
  4050. } else if nurse == nil {
  4051. this.ErrorLog("护士不存在")
  4052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4053. return
  4054. }
  4055. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4056. //if getNurseErr != nil {
  4057. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4058. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4059. // return
  4060. //} else if nurse == nil {
  4061. // this.ErrorLog("护士不存在")
  4062. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4063. // return
  4064. //}
  4065. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4066. if getDeviceNumberErr != nil {
  4067. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4069. return
  4070. } else if deviceNumber == nil {
  4071. this.ErrorLog("床位号不存在")
  4072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4073. return
  4074. }
  4075. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4076. //
  4077. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4078. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4079. // if getPermissionErr != nil {
  4080. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4081. // return
  4082. // } else if headNursePermission == nil {
  4083. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4084. // return
  4085. // }
  4086. //}
  4087. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4088. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4089. timeLayout := "2006-01-02 15:04:05"
  4090. loc, _ := time.LoadLocation("Local")
  4091. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4092. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4093. schedulestartTime := theStartTime.Unix()
  4094. scheduleendTime := theEndTime.Unix()
  4095. var theNucleinDate int64
  4096. timeLayoutOne := "2006-01-02"
  4097. if len(nuclein_date_str) > 0 {
  4098. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4099. if err != nil {
  4100. utils.ErrorLog(err.Error())
  4101. }
  4102. theNucleinDate = theTime.Unix()
  4103. }
  4104. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4105. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4106. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4107. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4108. if err == gorm.ErrRecordNotFound { //空床位
  4109. // 修改了床位逻辑
  4110. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4111. if daySchedule.ID > 0 {
  4112. //daySchedule.BedId = bedID
  4113. //daySchedule.PartitionId = deviceNumber.ZoneID
  4114. //daySchedule.ScheduleType = schedual_type
  4115. //daySchedule.UpdatedTime = time.Now().Unix()
  4116. //err := service.UpdateSchedule(&daySchedule)
  4117. xtSchedule := models.Schedule{
  4118. PartitionId: deviceNumber.ZoneID,
  4119. BedId: bedID,
  4120. ScheduleType: schedual_type,
  4121. UpdatedTime: time.Now().Unix(),
  4122. }
  4123. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4124. if err != nil {
  4125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4126. return
  4127. }
  4128. }
  4129. } else if err == nil {
  4130. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4131. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4132. if daySchedule.ID > 0 {
  4133. //daySchedule.BedId = bedID
  4134. //daySchedule.PartitionId = deviceNumber.ZoneID
  4135. //
  4136. //daySchedule.ScheduleType = schedual_type
  4137. //daySchedule.UpdatedTime = time.Now().Unix()
  4138. //err := service.UpdateSchedule(&daySchedule)
  4139. xtSchedule := models.Schedule{
  4140. PartitionId: deviceNumber.ZoneID,
  4141. BedId: bedID,
  4142. ScheduleType: schedual_type,
  4143. UpdatedTime: time.Now().Unix(),
  4144. }
  4145. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4146. if err != nil {
  4147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4148. return
  4149. }
  4150. }
  4151. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4153. return
  4154. }
  4155. } else if err != nil {
  4156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4157. return
  4158. }
  4159. }
  4160. dialysisRecord := &models.DialysisOrder{
  4161. ID: record_id,
  4162. UserOrgId: adminUserInfo.Org.Id,
  4163. BedID: bedID,
  4164. StartNurse: nurseID,
  4165. StartTime: startDate.Unix(),
  4166. PunctureNurse: puncture_nurse,
  4167. Creator: adminUserInfo.AdminUser.Id,
  4168. Modifier: adminUserInfo.AdminUser.Id,
  4169. WashpipeNurse: washpipe_nurse,
  4170. SchedualType: schedual_type,
  4171. ChangeNurse: change_nurse,
  4172. DifficultPunctureNurse: difficult_puncture_nurse,
  4173. NewFistulaNurse: new_fistula_nurse,
  4174. QualityNurseId: quality_nurse_id,
  4175. PunctureNeedle: puncture_needle,
  4176. PunctureWay: puncture_way,
  4177. DialysisDialyszers: dialysis_dialyszers,
  4178. DialysisIrrigation: dialysis_irrigation,
  4179. BloodAccessId: blood_access_id,
  4180. NucleinDate: theNucleinDate,
  4181. OrderRemark: order_remark,
  4182. ScheduleRemark: schedule_remark,
  4183. CatheterOperation: catheter_operation,
  4184. BloodFlowVolume: blood_flow_volume,
  4185. BloodDrawing: blood_drawing,
  4186. }
  4187. //修改床位号需要重新消毒
  4188. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4189. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4190. //查询第一条监测
  4191. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4192. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4193. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4194. redis := service.RedisClient()
  4195. //清空key 值
  4196. redis.Set(key, "", time.Second)
  4197. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4198. redis.Set(keyOne, "", time.Second)
  4199. defer redis.Close()
  4200. }
  4201. // 查询信息规挡的设置天数
  4202. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4203. if infor.ID > 0 && infor.WeekDay > 0 {
  4204. var cha_time int64
  4205. timeNowStr := time.Now().Format("2006-01-02")
  4206. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4207. //今日的日期减去设置的日期
  4208. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4209. if cha_time >= record_date {
  4210. //查询审核是否允许
  4211. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4212. //申请状态不允许的情况 拒绝修改
  4213. if infor.ApplicationStatus != 1 {
  4214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4215. return
  4216. }
  4217. }
  4218. }
  4219. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4220. order, _ := service.GetLastPatientOrder(record_id)
  4221. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4222. redis := service.RedisClient()
  4223. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4224. redis.Set(key, "", time.Second)
  4225. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4226. //清空key 值
  4227. redis.Set(keyOne, "", time.Second)
  4228. scheduleDateStartOne := startDate.Format("2006-01-02")
  4229. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4230. redis.Set(keyTwo, "", time.Second)
  4231. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4232. redis.Set(keyThree, "", time.Second)
  4233. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4234. redis.Set(keyFour, "", time.Second)
  4235. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4236. redis.Set(keyFive, "", time.Second)
  4237. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4238. redis.Set(keySix, "", time.Second)
  4239. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4240. redis.Set(keySeven, "", time.Second)
  4241. if updateErr != nil {
  4242. this.ErrorLog("修改上机失败:%v", updateErr)
  4243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4244. return
  4245. }
  4246. if updateErr == nil {
  4247. if tempDialysisRecord.Stage == 2 {
  4248. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4249. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4250. fmt.Println(value)
  4251. a, b := math.Modf(value)
  4252. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4253. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4254. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4255. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4256. redis := service.RedisClient()
  4257. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4258. redis.Set(key, "", time.Second)
  4259. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4260. redis.Set(keyOne, "", time.Second)
  4261. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4262. //清空key 值
  4263. redis.Set(keySix, "", time.Second)
  4264. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4265. redis.Set(keySeven, "", time.Second)
  4266. redis.Close()
  4267. if updateAssessmentErr != nil {
  4268. utils.ErrorLog("%v", updateAssessmentErr)
  4269. }
  4270. }
  4271. }
  4272. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4273. this.ServeSuccessJSON(map[string]interface{}{
  4274. "dialysis_order": dialysisRecords,
  4275. })
  4276. }
  4277. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4278. record_id, _ := c.GetInt64("id")
  4279. nurseID, _ := c.GetInt64("nurse")
  4280. end_time := c.GetString("end_time")
  4281. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4282. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4283. catheter := c.GetString("catheter")
  4284. cruor := c.GetString("cruor")
  4285. mission := c.GetString("mission")
  4286. condenser := c.GetString("condenser")
  4287. if record_id <= 0 || nurseID <= 0 {
  4288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4289. return
  4290. }
  4291. adminUserInfo := c.GetMobileAdminUserInfo()
  4292. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4293. if getNurseErr != nil {
  4294. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4296. return
  4297. } else if nurse == nil {
  4298. c.ErrorLog("护士不存在")
  4299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4300. return
  4301. }
  4302. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4303. if parseEndDateErr != nil {
  4304. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4306. return
  4307. }
  4308. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4309. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4310. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4311. // if getPermissionErr != nil {
  4312. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4313. // return
  4314. // } else if headNursePermission == nil {
  4315. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4316. // return
  4317. // }
  4318. //}
  4319. // 查询信息规挡的设置天数
  4320. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4321. if infor.ID > 0 {
  4322. var cha_time int64
  4323. timeNowStr := time.Now().Format("2006-01-02")
  4324. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4325. //今日的日期减去设置的日期
  4326. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4327. if cha_time >= tempDialysisRecords.DialysisDate {
  4328. //查询审核是否允许
  4329. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4330. //申请状态不允许的情况 拒绝修改
  4331. if infor.ApplicationStatus != 1 {
  4332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4333. return
  4334. }
  4335. }
  4336. }
  4337. dialysisRecord := &models.DialysisOrder{
  4338. ID: record_id,
  4339. UserOrgId: adminUserInfo.Org.Id,
  4340. EndTime: endDate.Unix(),
  4341. FinishNurse: nurseID,
  4342. FinishModifier: adminUserInfo.AdminUser.Id,
  4343. PuncturePointHaematoma: puncture_point_haematoma,
  4344. BloodAccessInternalFistula: blood_access_internal_fistula,
  4345. Catheter: catheter,
  4346. Cruor: cruor,
  4347. Mission: mission,
  4348. Condenser: condenser,
  4349. }
  4350. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4351. redis := service.RedisClient()
  4352. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4353. //清空key 值
  4354. redis.Set(key, "", time.Second)
  4355. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4356. //清空key 值
  4357. redis.Set(keyOne, "", time.Second)
  4358. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4359. redis.Set(keySeven, "", time.Second)
  4360. redis.Close()
  4361. if updateErr != nil {
  4362. c.ErrorLog("修改下机失败:%v", updateErr)
  4363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4364. return
  4365. }
  4366. if updateErr == nil {
  4367. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4368. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4369. a, b := math.Modf(value)
  4370. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4371. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4372. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4373. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4374. redis := service.RedisClient()
  4375. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4376. redis.Set(keyTen, "", time.Second)
  4377. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4378. redis.Set(keyTwo, "", time.Second)
  4379. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4380. redis.Set(key, "", time.Second)
  4381. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4382. redis.Set(keyThree, "", time.Second)
  4383. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4384. redis.Set(keySeven, "", time.Second)
  4385. defer redis.Close()
  4386. if updateAssessmentErr != nil {
  4387. utils.ErrorLog("%v", updateAssessmentErr)
  4388. }
  4389. }
  4390. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4391. c.ServeSuccessJSON(map[string]interface{}{
  4392. "dialysis_order": dialysisRecords,
  4393. })
  4394. }
  4395. func (c *DialysisAPIController) GetLongAdvice() {
  4396. patient_id, _ := c.GetInt64("id")
  4397. adminUserInfo := c.GetMobileAdminUserInfo()
  4398. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4399. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4400. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4401. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4402. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4403. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4404. c.ServeSuccessJSON(map[string]interface{}{
  4405. "status": "1",
  4406. })
  4407. return
  4408. } else { //开启推送提醒
  4409. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4410. var advice_three []*models.DoctorAdvice
  4411. recordDateStr := time.Now().Format("2006-01-02")
  4412. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4413. nowtime := recordDate.Unix()
  4414. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4415. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4416. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4417. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4418. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4419. for _, advice := range advices {
  4420. if advice.FrequencyType == 3 {
  4421. t := time.Now()
  4422. week := int(t.Weekday())
  4423. fmt.Println(t.Weekday())
  4424. fmt.Println(week)
  4425. switch week {
  4426. case 1:
  4427. if strings.Index(advice.WeekDay, "周一") == -1 {
  4428. advice_three = append(advice_three, advice)
  4429. }
  4430. break
  4431. case 2:
  4432. if strings.Index(advice.WeekDay, "周二") == -1 {
  4433. advice_three = append(advice_three, advice)
  4434. }
  4435. break
  4436. case 3:
  4437. if strings.Index(advice.WeekDay, "周三") == -1 {
  4438. advice_three = append(advice_three, advice)
  4439. }
  4440. break
  4441. case 4:
  4442. if strings.Index(advice.WeekDay, "周四") == -1 {
  4443. advice_three = append(advice_three, advice)
  4444. }
  4445. break
  4446. case 5:
  4447. if strings.Index(advice.WeekDay, "周五") == -1 {
  4448. advice_three = append(advice_three, advice)
  4449. }
  4450. break
  4451. case 6:
  4452. if strings.Index(advice.WeekDay, "周六") == -1 {
  4453. advice_three = append(advice_three, advice)
  4454. }
  4455. break
  4456. case 0:
  4457. if strings.Index(advice.WeekDay, "周日") == -1 {
  4458. advice_three = append(advice_three, advice)
  4459. }
  4460. break
  4461. }
  4462. }
  4463. }
  4464. for _, advice := range advices_two {
  4465. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4466. now := p.Unix()
  4467. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4468. dayStr2 := "-" + dayStr
  4469. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4470. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4471. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4472. for _, ad := range advices {
  4473. advice_three = append(advice_three, ad)
  4474. }
  4475. }
  4476. if err == nil {
  4477. c.ServeSuccessJSON(map[string]interface{}{
  4478. "status": "2",
  4479. "advices": advices,
  4480. "advices_two": RemoveRepeatedElement(advice_three),
  4481. "is_open_remind": config.IsOpenRemind,
  4482. "his_config_open": hisConfig.IsOpen,
  4483. "is_advice_open": is_advice_open.IsAdviceOpen,
  4484. "prescription_open": prescription_open.IsOpen,
  4485. })
  4486. }
  4487. }
  4488. }
  4489. func (c *DialysisAPIController) GetLongAdviceOne() {
  4490. patient_id, _ := c.GetInt64("id")
  4491. startTime := c.GetString("schedule_date")
  4492. timeLayout := "2006-01-02"
  4493. loc, _ := time.LoadLocation("Local")
  4494. var theStartTime int64
  4495. if len(startTime) > 0 {
  4496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4497. if err != nil {
  4498. utils.ErrorLog(err.Error())
  4499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4500. return
  4501. }
  4502. theStartTime = theTime.Unix()
  4503. }
  4504. adminUserInfo := c.GetMobileAdminUserInfo()
  4505. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4506. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4507. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4508. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4509. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4510. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4511. c.ServeSuccessJSON(map[string]interface{}{
  4512. "status": "1",
  4513. })
  4514. return
  4515. } else { //开启推送提醒
  4516. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4517. var advice_three []*models.DoctorAdvice
  4518. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4519. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4520. for _, advice := range advices {
  4521. if advice.FrequencyType == 3 {
  4522. t := time.Now()
  4523. week := int(t.Weekday())
  4524. fmt.Println(t.Weekday())
  4525. fmt.Println(week)
  4526. switch week {
  4527. case 1:
  4528. if strings.Index(advice.WeekDay, "周一") == -1 {
  4529. advice_three = append(advice_three, advice)
  4530. }
  4531. break
  4532. case 2:
  4533. if strings.Index(advice.WeekDay, "周二") == -1 {
  4534. advice_three = append(advice_three, advice)
  4535. }
  4536. break
  4537. case 3:
  4538. if strings.Index(advice.WeekDay, "周三") == -1 {
  4539. advice_three = append(advice_three, advice)
  4540. }
  4541. break
  4542. case 4:
  4543. if strings.Index(advice.WeekDay, "周四") == -1 {
  4544. advice_three = append(advice_three, advice)
  4545. }
  4546. break
  4547. case 5:
  4548. if strings.Index(advice.WeekDay, "周五") == -1 {
  4549. advice_three = append(advice_three, advice)
  4550. }
  4551. break
  4552. case 6:
  4553. if strings.Index(advice.WeekDay, "周六") == -1 {
  4554. advice_three = append(advice_three, advice)
  4555. }
  4556. break
  4557. case 0:
  4558. if strings.Index(advice.WeekDay, "周日") == -1 {
  4559. advice_three = append(advice_three, advice)
  4560. }
  4561. break
  4562. }
  4563. }
  4564. }
  4565. for _, advice := range advices_two {
  4566. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4567. now := p.Unix()
  4568. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4569. dayStr2 := "-" + dayStr
  4570. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4571. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4572. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4573. for _, ad := range advices {
  4574. advice_three = append(advice_three, ad)
  4575. }
  4576. }
  4577. if err == nil {
  4578. c.ServeSuccessJSON(map[string]interface{}{
  4579. "status": "2",
  4580. "advices": advices,
  4581. "advices_two": RemoveRepeatedElement(advice_three),
  4582. "is_open_remind": config.IsOpenRemind,
  4583. "his_config_open": hisConfig.IsOpen,
  4584. "is_advice_open": is_advice_open.IsAdviceOpen,
  4585. "prescription_open": prescription_open.IsOpen,
  4586. })
  4587. }
  4588. }
  4589. }
  4590. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4591. newArr = make([]*models.DoctorAdvice, 0)
  4592. for i := 0; i < len(arr); i++ {
  4593. repeat := false
  4594. for j := i + 1; j < len(arr); j++ {
  4595. if arr[i].ID == arr[j].ID {
  4596. repeat = true
  4597. break
  4598. }
  4599. }
  4600. if !repeat {
  4601. newArr = append(newArr, arr[i])
  4602. }
  4603. }
  4604. return
  4605. }
  4606. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4607. patient, _ := c.GetInt64("id", 0)
  4608. groupNo, _ := c.GetInt64("groupno", 0)
  4609. if patient <= 0 {
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4611. return
  4612. }
  4613. adminUserInfo := c.GetMobileAdminUserInfo()
  4614. dataBody := make(map[string]interface{}, 0)
  4615. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4616. if err != nil {
  4617. utils.ErrorLog(err.Error())
  4618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4619. return
  4620. }
  4621. utils.ErrorLog("%v", dataBody)
  4622. timeLayout := "2006-01-02 15:04"
  4623. loc, _ := time.LoadLocation("Local")
  4624. timeLayout2 := "2006-01-02"
  4625. loc2, _ := time.LoadLocation("Local")
  4626. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4627. utils.ErrorLog("advice_type")
  4628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4629. return
  4630. }
  4631. adviceType := int64(2)
  4632. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4633. utils.ErrorLog("advice_date")
  4634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4635. return
  4636. }
  4637. adviceDate, _ := dataBody["advice_date"].(string)
  4638. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4639. AdviceDate := theTime.Unix()
  4640. RecordDate := theTime.Unix()
  4641. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4642. utils.ErrorLog("start_time")
  4643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4644. return
  4645. }
  4646. startTime, _ := dataBody["start_time"].(string)
  4647. if len(startTime) == 0 {
  4648. utils.ErrorLog("len(start_time) == 0")
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4650. return
  4651. }
  4652. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4653. if err != nil {
  4654. utils.ErrorLog(err.Error())
  4655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4656. return
  4657. }
  4658. StartTime := theTime.Unix()
  4659. Remark := ""
  4660. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4661. remark, _ := dataBody["remark"].(string)
  4662. Remark = remark
  4663. }
  4664. var advices []*models.GroupAdvice
  4665. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4666. utils.ErrorLog("advices")
  4667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4668. return
  4669. }
  4670. adviceNames := dataBody["advices"].([]interface{})
  4671. for _, adviceNameMap := range adviceNames {
  4672. adviceNameM := adviceNameMap.(map[string]interface{})
  4673. var advice models.GroupAdvice
  4674. advice.Remark = Remark
  4675. advice.AdviceType = adviceType
  4676. advice.StartTime = StartTime
  4677. advice.AdviceDate = AdviceDate
  4678. advice.RecordDate = RecordDate
  4679. advice.Status = 1
  4680. advice.CreatedTime = time.Now().Unix()
  4681. advice.UpdatedTime = time.Now().Unix()
  4682. advice.StopState = 2
  4683. advice.ExecutionState = 2
  4684. advice.UserOrgId = adminUserInfo.Org.Id
  4685. advice.PatientId = patient
  4686. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4687. advice.IsSettle = 2
  4688. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4689. utils.ErrorLog("advice_name")
  4690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. return
  4692. }
  4693. adviceName, _ := adviceNameM["advice_name"].(string)
  4694. if len(adviceName) == 0 {
  4695. utils.ErrorLog("len(advice_name) == 0")
  4696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4697. return
  4698. }
  4699. advice.AdviceName = adviceName
  4700. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4701. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4702. advice.DrugSpec = drugSpec
  4703. }
  4704. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4705. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4706. advice.AdviceDesc = adviceDesc
  4707. }
  4708. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4709. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4710. advice.DrugSpecUnit = drugSpecUnit
  4711. }
  4712. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4713. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4714. // advice.SingleDose = singleDose
  4715. //}
  4716. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4717. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4718. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4719. }
  4720. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4721. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4722. advice.SingleDoseUnit = singleDoseUnit
  4723. }
  4724. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4725. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4726. // advice.PrescribingNumber = prescribingNumber
  4727. //}
  4728. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4729. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4730. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4731. }
  4732. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4733. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4734. advice.PrescribingNumberUnit = prescribingNumberUnit
  4735. }
  4736. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4737. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4738. advice.DeliveryWay = deliveryWay
  4739. }
  4740. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4741. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4742. advice.ExecutionFrequency = executionFrequency
  4743. }
  4744. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4745. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4746. advice.FrequencyType = frequency_type
  4747. }
  4748. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4749. day_count := int64(adviceNameM["day_count"].(float64))
  4750. advice.DayCount = day_count
  4751. }
  4752. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4753. week_day, _ := adviceNameM["week_day"].(string)
  4754. advice.WeekDay = week_day
  4755. }
  4756. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4757. way := int64(adviceNameM["way"].(float64))
  4758. advice.Way = way
  4759. }
  4760. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4761. drug_id := int64(adviceNameM["drug_id"].(float64))
  4762. advice.DrugId = drug_id
  4763. }
  4764. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4765. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4766. advice.DrugNameId = drug_name_id
  4767. }
  4768. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4769. remark, _ := adviceNameM["remark"].(string)
  4770. advice.Remark = remark
  4771. }
  4772. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4773. groupno := int64(adviceNameM["groupno"].(float64))
  4774. advice.GroupNo = groupno
  4775. }
  4776. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4777. template_id, _ := adviceNameM["template_id"].(string)
  4778. advice.TemplateId = template_id
  4779. }
  4780. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4781. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4782. advice.ExecutionFrequency = executionFrequency
  4783. }
  4784. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4785. children := adviceNameM["child"].([]interface{})
  4786. if len(children) > 0 {
  4787. for _, childrenMap := range children {
  4788. childMap := childrenMap.(map[string]interface{})
  4789. var child models.GroupAdvice
  4790. child.Remark = Remark
  4791. child.AdviceType = adviceType
  4792. child.StartTime = StartTime
  4793. child.AdviceDate = AdviceDate
  4794. child.RecordDate = RecordDate
  4795. child.Status = 1
  4796. child.CreatedTime = time.Now().Unix()
  4797. child.UpdatedTime = time.Now().Unix()
  4798. child.StopState = 2
  4799. child.ExecutionState = 2
  4800. child.UserOrgId = adminUserInfo.Org.Id
  4801. child.PatientId = patient
  4802. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4803. child.IsSettle = 1
  4804. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4805. utils.ErrorLog("child advice_name")
  4806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4807. return
  4808. }
  4809. childAdviceName, _ := childMap["advice_name"].(string)
  4810. if len(childAdviceName) == 0 {
  4811. utils.ErrorLog("len(child advice_name) == 0")
  4812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4813. return
  4814. }
  4815. child.AdviceName = childAdviceName
  4816. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4817. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4818. child.AdviceDesc = childAdviceDesc
  4819. }
  4820. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4821. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4822. child.DrugSpec = childDrugSpec
  4823. }
  4824. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4825. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4826. child.DrugSpecUnit = childDrugSpecUnit
  4827. }
  4828. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4829. child.SingleDose = childMap["single_dose"].(float64)
  4830. }
  4831. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4832. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4833. child.SingleDoseUnit = childSingleDoseUnit
  4834. }
  4835. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4836. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4837. }
  4838. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4839. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4840. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4841. }
  4842. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4843. groupno := int64(childMap["groupno"].(float64))
  4844. advice.GroupNo = groupno
  4845. }
  4846. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4847. remark, _ := childMap["remark"].(string)
  4848. child.Remark = remark
  4849. }
  4850. child.DeliveryWay = advice.DeliveryWay
  4851. child.ExecutionFrequency = advice.ExecutionFrequency
  4852. advice.Children = append(advice.Children, &child)
  4853. }
  4854. }
  4855. }
  4856. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4857. if temp_advice.ID == 0 {
  4858. advices = append(advices, &advice)
  4859. }
  4860. }
  4861. if len(advices) > 0 {
  4862. finish := models.XtDialysisFinish{
  4863. IsFinish: 1,
  4864. UserOrgId: adminUserInfo.Org.Id,
  4865. Status: 1,
  4866. Ctime: time.Now().Unix(),
  4867. Mtime: 0,
  4868. Module: 4,
  4869. RecordDate: AdviceDate,
  4870. Sourse: 1,
  4871. PatientId: patient,
  4872. }
  4873. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4874. if dialysisFinish.ID == 0 {
  4875. service.CreateDialysisFinish(finish)
  4876. }
  4877. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  4878. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4879. for _, item := range advices {
  4880. byterequest, _ := json.Marshal(item)
  4881. adviceLog := models.XtDoctorAdviceLog{
  4882. UserOrgId: adminUserInfo.Org.Id,
  4883. PatientId: patient,
  4884. AdminUserId: adminUserInfo.AdminUser.Id,
  4885. Module: 1,
  4886. ErrLog: string(byterequest),
  4887. Status: 1,
  4888. Ctime: time.Now().Unix(),
  4889. Mtime: 0,
  4890. Source: "手机端医嘱推送",
  4891. RecordDate: item.AdviceDate,
  4892. }
  4893. service.CreateDoctorAdviceLog(adviceLog)
  4894. }
  4895. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4896. redis := service.RedisClient()
  4897. //清空key 值
  4898. redis.Set(key, "", time.Second)
  4899. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4900. redis.Set(keyOne, "", time.Second)
  4901. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4902. defer redis.Close()
  4903. redis.Set(keyThree, "", time.Second)
  4904. if err != nil {
  4905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4906. return
  4907. }
  4908. c.ServeSuccessJSON(map[string]interface{}{
  4909. "msg": "ok",
  4910. "advices": list,
  4911. })
  4912. } else {
  4913. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4914. for _, item := range advices {
  4915. byterequest, _ := json.Marshal(item)
  4916. adviceLog := models.XtDoctorAdviceLog{
  4917. UserOrgId: adminUserInfo.Org.Id,
  4918. PatientId: patient,
  4919. AdminUserId: adminUserInfo.AdminUser.Id,
  4920. Module: 1,
  4921. ErrLog: string(byterequest),
  4922. Status: 1,
  4923. Ctime: time.Now().Unix(),
  4924. Mtime: 0,
  4925. Source: "手机端医嘱推送",
  4926. RecordDate: item.AdviceDate,
  4927. }
  4928. service.CreateDoctorAdviceLog(adviceLog)
  4929. }
  4930. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4931. redis := service.RedisClient()
  4932. //清空key 值
  4933. redis.Set(key, "", time.Second)
  4934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4935. redis.Set(keyOne, "", time.Second)
  4936. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4937. defer redis.Close()
  4938. redis.Set(keyThree, "", time.Second)
  4939. if err != nil {
  4940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4941. return
  4942. }
  4943. c.ServeSuccessJSON(map[string]interface{}{
  4944. "msg": "ok",
  4945. "advices": list,
  4946. })
  4947. }
  4948. } else {
  4949. c.ServeSuccessJSON(map[string]interface{}{
  4950. "msg": "ok",
  4951. })
  4952. }
  4953. return
  4954. }
  4955. func (c *DialysisAPIController) UploadDryWeight() {
  4956. patient_id, _ := c.GetInt64("id")
  4957. dry_weight, _ := c.GetFloat("dry_weight")
  4958. doctor_id, _ := c.GetInt64("doctor_id")
  4959. remark := c.GetString("remark")
  4960. adminUserInfo := c.GetMobileAdminUserInfo()
  4961. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4962. if err == gorm.ErrRecordNotFound {
  4963. dryWeight := &models.SgjPatientDryweight{
  4964. PatientId: patient_id,
  4965. DryWeight: dry_weight,
  4966. Remakes: remark,
  4967. Ctime: time.Now().Unix(),
  4968. Mtime: time.Now().Unix(),
  4969. Creator: doctor_id,
  4970. Status: 1,
  4971. UserOrgId: adminUserInfo.Org.Id,
  4972. AdjustedValue: "/",
  4973. UserId: adminUserInfo.AdminUser.Id,
  4974. }
  4975. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4976. redis := service.RedisClient()
  4977. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4978. redis.Set(keyOne, "", time.Second)
  4979. loc, _ := time.LoadLocation("Local")
  4980. nowTime := time.Now()
  4981. nowDay := nowTime.Format("2006-01-02")
  4982. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4984. redis.Set(key, "", time.Second)
  4985. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4986. redis.Set(keyTwo, "", time.Second)
  4987. redis.Close()
  4988. if createErr == nil {
  4989. c.ServeSuccessJSON(map[string]interface{}{
  4990. "msg": "提交成功",
  4991. "weight": dryWeight,
  4992. })
  4993. }
  4994. } else {
  4995. dryWeight := &models.SgjPatientDryweight{
  4996. PatientId: patient_id,
  4997. DryWeight: dry_weight,
  4998. Remakes: remark,
  4999. Ctime: time.Now().Unix(),
  5000. Mtime: time.Now().Unix(),
  5001. Creator: doctor_id,
  5002. Status: 1,
  5003. UserOrgId: adminUserInfo.Org.Id,
  5004. AdjustedValue: "/",
  5005. UserId: adminUserInfo.AdminUser.Id,
  5006. }
  5007. var value float64
  5008. value = dry_weight - weightAdjust.DryWeight
  5009. if value < 0 {
  5010. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5011. } else if value == 0 {
  5012. dryWeight.AdjustedValue = "/"
  5013. } else if value > 0 {
  5014. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5015. }
  5016. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5017. redis := service.RedisClient()
  5018. loc, _ := time.LoadLocation("Local")
  5019. nowTime := time.Now()
  5020. nowDay := nowTime.Format("2006-01-02")
  5021. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5022. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5023. redis.Set(keyOne, "", time.Second)
  5024. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5025. redis.Set(key, "", time.Second)
  5026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5027. redis.Set(keyTwo, "", time.Second)
  5028. redis.Close()
  5029. if createErr == nil {
  5030. c.ServeSuccessJSON(map[string]interface{}{
  5031. "msg": "提交成功",
  5032. "weight": dryWeight,
  5033. })
  5034. }
  5035. }
  5036. }
  5037. func (c *DialysisAPIController) GetSolution() {
  5038. patient_id, _ := c.GetInt64("patient_id")
  5039. mode_id, _ := c.GetInt64("mode_id")
  5040. adminUserInfo := c.GetMobileAdminUserInfo()
  5041. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5042. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5043. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5044. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5045. if err != nil {
  5046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5047. return
  5048. }
  5049. c.ServeSuccessJSON(map[string]interface{}{
  5050. "solution": solution,
  5051. "prescription": prescription,
  5052. "system_prescription": system_prescription,
  5053. "dialysisPrescription": dialysisPrescription,
  5054. })
  5055. }
  5056. func (c *DialysisAPIController) GetSchedule() {
  5057. schedual_type, _ := c.GetInt64("schedual_type")
  5058. adminUserInfo := c.GetMobileAdminUserInfo()
  5059. scheduleTime, _ := c.GetInt64("record_date")
  5060. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5061. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5062. c.ServeSuccessJSON(map[string]interface{}{
  5063. "number": deviceNumber,
  5064. "list": list,
  5065. })
  5066. }
  5067. func (c *DialysisAPIController) GetPatientId() {
  5068. id, _ := c.GetInt64("id")
  5069. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5070. patientId, _ := service.GetPatientId(id)
  5071. //获取该患者的所有传染病
  5072. list, _ := service.GetPatientInfectious(id)
  5073. c.ServeSuccessJSON(map[string]interface{}{
  5074. "patient": patientId,
  5075. "infectioulist": list,
  5076. })
  5077. }
  5078. func (this *DialysisAPIController) GetDialysisSchedule() {
  5079. schedualDate := this.GetString("date")
  5080. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5081. if parseDateErr != nil {
  5082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5083. return
  5084. }
  5085. adminInfo := this.GetMobileAdminUserInfo()
  5086. orgID := adminInfo.Org.Id
  5087. redis := service.RedisClient()
  5088. defer redis.Close()
  5089. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5090. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5091. if len(scheduals) > 0 {
  5092. //缓存数据
  5093. scheduals_json, err := json.Marshal(scheduals)
  5094. if err == nil {
  5095. redis.Set(key, scheduals_json, time.Second*30)
  5096. }
  5097. }
  5098. this.ServeSuccessJSON(map[string]interface{}{
  5099. "scheduals": scheduals,
  5100. })
  5101. }
  5102. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5103. change_type, _ := this.GetInt64("type", 0)
  5104. record_date := this.GetString("record_time")
  5105. patient_id, _ := this.GetInt64("patient_id", 0)
  5106. timeLayout := "2006-01-02"
  5107. loc, _ := time.LoadLocation("Local")
  5108. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5109. record_time := theAdviceRecordTime.Unix()
  5110. adminUserInfo := this.GetMobileAdminUserInfo()
  5111. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5112. if err == nil {
  5113. if len(advices) == 0 {
  5114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5115. return
  5116. } else {
  5117. this.ServeSuccessJSON(map[string]interface{}{
  5118. "advices": advices,
  5119. "schedule": sch,
  5120. })
  5121. return
  5122. }
  5123. } else {
  5124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5125. return
  5126. }
  5127. }
  5128. func (c *DialysisAPIController) CreateConsumables() {
  5129. record_date := c.GetString("record_time")
  5130. patient_id, _ := c.GetInt64("patient_id", 0)
  5131. active, _ := c.GetInt64("active")
  5132. adminUser := c.GetMobileAdminUserInfo()
  5133. timeLayout := "2006-01-02"
  5134. loc, _ := time.LoadLocation("Local")
  5135. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5136. record_time := theRecordTime.Unix()
  5137. // 查询信息规挡的设置天数
  5138. orgid := c.GetMobileAdminUserInfo().Org.Id
  5139. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5140. if infor.ID > 0 {
  5141. var cha_time int64
  5142. timeNowStr := time.Now().Format("2006-01-02")
  5143. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5144. //今日的日期减去设置的日期
  5145. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5146. if cha_time >= record_time {
  5147. //查询审核是否允许
  5148. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5149. //申请状态不允许的情况 拒绝修改
  5150. if infor.ApplicationStatus != 1 {
  5151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5152. return
  5153. }
  5154. }
  5155. }
  5156. dataBody := make(map[string]interface{}, 0)
  5157. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5158. if err != nil {
  5159. utils.ErrorLog(err.Error())
  5160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5161. return
  5162. }
  5163. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5164. var beforePrepares []*models.DialysisBeforePrepareGoods
  5165. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5166. var dialysisBefor []*models.DialysisBeforePrepare
  5167. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5168. goods, _ := dataBody["goods"].([]interface{})
  5169. if len(goods) > 0 {
  5170. for _, item := range goods {
  5171. items := item.(map[string]interface{})
  5172. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5173. utils.ErrorLog("good_id")
  5174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5175. return
  5176. }
  5177. good_id := int64(items["good_id"].(float64))
  5178. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5179. utils.ErrorLog("good_type_id")
  5180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5181. return
  5182. }
  5183. good_type_id := int64(items["good_type_id"].(float64))
  5184. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5185. utils.ErrorLog("count")
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5187. return
  5188. }
  5189. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5190. commdity_code := items["commdity_code"].(string)
  5191. fmt.Println("commdity", commdity_code)
  5192. prepareGoods := &models.DialysisBeforePrepareGoods{
  5193. GoodTypeId: good_type_id,
  5194. GoodId: good_id,
  5195. Count: count,
  5196. StorehouseId: houseConfig.StorehouseOutInfo,
  5197. }
  5198. beforePrepares = append(beforePrepares, prepareGoods)
  5199. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5200. GoodTypeId: good_type_id,
  5201. GoodId: good_id,
  5202. Count: count,
  5203. StorehouseId: houseConfig.StorehouseOutInfo,
  5204. }
  5205. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5206. prepare := &models.DialysisBeforePrepare{
  5207. GoodTypeId: good_type_id,
  5208. GoodId: good_id,
  5209. Count: count,
  5210. PatientId: patient_id,
  5211. RecordDate: record_time,
  5212. UserOrgId: adminUser.Org.Id,
  5213. Status: 1,
  5214. Ctime: time.Now().Unix(),
  5215. Creater: adminUser.AdminUser.Id,
  5216. CommdityCode: commdity_code,
  5217. StorehouseId: houseConfig.StorehouseOutInfo,
  5218. }
  5219. dialysisBefor = append(dialysisBefor, prepare)
  5220. }
  5221. }
  5222. //查询是否有库存
  5223. for _, item := range dialysisBefor {
  5224. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5225. if err == gorm.ErrRecordNotFound {
  5226. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5227. c.ServeSuccessJSON(map[string]interface{}{
  5228. "message": "1",
  5229. "good_name": goodObj.GoodName,
  5230. "specification_name": goodObj.SpecificationName,
  5231. })
  5232. return
  5233. }
  5234. if err != nil {
  5235. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5236. c.ServeSuccessJSON(map[string]interface{}{
  5237. "message": "1",
  5238. "good_name": goodObj.GoodName,
  5239. "specification_name": goodObj.SpecificationName,
  5240. })
  5241. return
  5242. }
  5243. }
  5244. //新增
  5245. if active == 1 && len(goods) > 0 {
  5246. for _, item := range dialysisBefor {
  5247. dialyPrepareOne := models.DialysisBeforePrepare{
  5248. GoodTypeId: item.GoodTypeId,
  5249. GoodId: item.GoodId,
  5250. PatientId: item.PatientId,
  5251. RecordDate: item.RecordDate,
  5252. UserOrgId: item.UserOrgId,
  5253. Count: item.Count,
  5254. Ctime: time.Now().Unix(),
  5255. Creater: item.Creater,
  5256. CommdityCode: item.CommdityCode,
  5257. Status: 1,
  5258. StorehouseId: houseConfig.StorehouseOutInfo,
  5259. }
  5260. //先清除再插入
  5261. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5262. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5263. //查询默认仓库
  5264. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5265. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5266. var total_count int64
  5267. for _, it := range stockList {
  5268. total_count += it.StockCount
  5269. }
  5270. //基础库插入数据
  5271. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5272. //更新库存
  5273. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5274. var flush_count int64
  5275. for _, it := range goodList {
  5276. flush_count += it.StockCount
  5277. }
  5278. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5279. }
  5280. if err == nil {
  5281. c.ServeSuccessJSON(map[string]interface{}{
  5282. "msg": "保存成功",
  5283. "message": "2",
  5284. })
  5285. return
  5286. } else {
  5287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5288. return
  5289. }
  5290. }
  5291. if len(beforePrepares) > 0 && active == 2 {
  5292. for _, item := range beforePrepares {
  5293. //1.查看该患者该耗材型号最后一次出库数量
  5294. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5295. //判断当前出库数量和最后一次出库数量的大小
  5296. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5297. if item.Count <= goodInfo.Count {
  5298. //退库
  5299. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5300. //查询今日出库数据
  5301. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5302. for _, it := range list {
  5303. prepare := models.DialysisBeforePrepare{
  5304. UserOrgId: it.OrgId,
  5305. PatientId: patient_id,
  5306. RecordDate: it.RecordTime,
  5307. GoodId: it.GoodId,
  5308. GoodTypeId: it.GoodTypeId,
  5309. Count: it.Count,
  5310. Ctime: time.Now().Unix(),
  5311. Creater: adminUser.AdminUser.Id,
  5312. Status: 1,
  5313. StorehouseId: houseConfig.StorehouseOutInfo,
  5314. }
  5315. //删除准备表数据
  5316. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5317. service.CreateDialysisBeforePrepareOne(&prepare)
  5318. }
  5319. }
  5320. var last_total int64
  5321. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5322. if item.Count >= goodInfo.Count {
  5323. //查询当前批次当前耗材最后一条出库数据
  5324. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5325. //计算当前出库和最后一次出库数据相差数据
  5326. last_total = item.Count - lastOutInfo.Count
  5327. //查询该批次剩余库存
  5328. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5329. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5330. if lastInfo.StockCount >= last_total {
  5331. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5332. //查询今日出库数据
  5333. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5334. for _, it := range list {
  5335. prepare := models.DialysisBeforePrepare{
  5336. UserOrgId: it.OrgId,
  5337. PatientId: patient_id,
  5338. RecordDate: it.RecordTime,
  5339. GoodId: it.GoodId,
  5340. GoodTypeId: it.GoodTypeId,
  5341. Count: it.Count,
  5342. Ctime: time.Now().Unix(),
  5343. Creater: adminUser.AdminUser.Id,
  5344. Status: 1,
  5345. StorehouseId: houseConfig.StorehouseOutInfo,
  5346. }
  5347. //删除准备表数据
  5348. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5349. service.CreateDialysisBeforePrepareOne(&prepare)
  5350. //查询默认仓库
  5351. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5352. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5353. var total_count int64
  5354. for _, it := range stockList {
  5355. total_count += it.StockCount
  5356. }
  5357. //基础库插入数据
  5358. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5359. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5360. var flush_count int64
  5361. for _, it := range goodList {
  5362. flush_count += it.StockCount
  5363. }
  5364. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5365. }
  5366. }
  5367. //如果库存不够,则出库到下一个批次
  5368. if lastInfo.StockCount < last_total {
  5369. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5370. //查询今日出库数据
  5371. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5372. for _, it := range list {
  5373. prepare := models.DialysisBeforePrepare{
  5374. UserOrgId: it.OrgId,
  5375. PatientId: patient_id,
  5376. RecordDate: it.RecordTime,
  5377. GoodId: it.GoodId,
  5378. GoodTypeId: it.GoodTypeId,
  5379. Count: it.Count,
  5380. Ctime: time.Now().Unix(),
  5381. Creater: adminUser.AdminUser.Id,
  5382. Status: 1,
  5383. StorehouseId: houseConfig.StorehouseOutInfo,
  5384. }
  5385. //删除准备表数据
  5386. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5387. service.CreateDialysisBeforePrepareOne(&prepare)
  5388. //查询默认仓库
  5389. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5390. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5391. var total_count int64
  5392. for _, it := range stockList {
  5393. total_count += it.StockCount
  5394. }
  5395. //基础库插入数据
  5396. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5397. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5398. var flush_count int64
  5399. for _, it := range goodList {
  5400. flush_count += it.StockCount
  5401. }
  5402. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5403. }
  5404. if err != nil {
  5405. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5406. c.ServeSuccessJSON(map[string]interface{}{
  5407. "message": "1",
  5408. "good_name": goodObj.GoodName,
  5409. "specification_name": goodObj.SpecificationName,
  5410. })
  5411. return
  5412. }
  5413. }
  5414. }
  5415. if err != nil {
  5416. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5417. c.ServeSuccessJSON(map[string]interface{}{
  5418. "message": "1",
  5419. "good_name": goodObj.GoodName,
  5420. "specification_name": goodObj.SpecificationName,
  5421. })
  5422. return
  5423. }
  5424. }
  5425. }
  5426. }
  5427. var errs error
  5428. if errs == nil {
  5429. c.ServeSuccessJSON(map[string]interface{}{
  5430. "msg": "提交成功",
  5431. "message": "2",
  5432. "good_name": "",
  5433. "specification_name": "",
  5434. })
  5435. return
  5436. } else {
  5437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5438. return
  5439. }
  5440. }
  5441. func (c *DialysisAPIController) CreateStockOutInfo() {
  5442. patient_id, _ := c.GetInt64("patient_id", 0)
  5443. record_date := c.GetString("record_time")
  5444. if patient_id <= 0 {
  5445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5446. return
  5447. }
  5448. adminInfo := c.GetMobileAdminUserInfo()
  5449. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5450. timeLayout := "2006-01-02"
  5451. loc, _ := time.LoadLocation("Local")
  5452. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5453. record_time := theRecordTime.Unix()
  5454. // 查询信息规挡的设置天数
  5455. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5456. if infor.ID > 0 && infor.WeekDay > 0 {
  5457. var cha_time int64
  5458. timeNowStr := time.Now().Format("2006-01-02")
  5459. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5460. //今日的日期减去设置的日期
  5461. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5462. if cha_time >= record_time {
  5463. //查询审核是否允许
  5464. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5465. //申请状态不允许的情况 拒绝修改
  5466. if infor.ApplicationStatus != 1 {
  5467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5468. return
  5469. }
  5470. }
  5471. }
  5472. //创建步骤表
  5473. finish := models.XtDialysisFinish{
  5474. IsFinish: 1,
  5475. UserOrgId: adminInfo.Org.Id,
  5476. Status: 1,
  5477. Ctime: time.Now().Unix(),
  5478. Mtime: 0,
  5479. Module: 11,
  5480. RecordDate: record_time,
  5481. Sourse: 1,
  5482. PatientId: patient_id,
  5483. }
  5484. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5485. if dialysisFinish.ID == 0 {
  5486. service.CreateDialysisFinish(finish)
  5487. }
  5488. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5489. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5490. //去重
  5491. consumables = RemoveRepeatedGood(consumables)
  5492. if adminInfo.Org.Id == 9919 {
  5493. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5494. //查询是否有库存
  5495. for _, item := range consumables {
  5496. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5497. if item.Count > warehouse.Count {
  5498. goodErrcode := models.XtGoodErrcode{
  5499. UserOrgId: item.UserOrgId,
  5500. Errcode: "自动出库库存不足",
  5501. GoodId: item.GoodId,
  5502. Status: 1,
  5503. Ctime: time.Now().Unix(),
  5504. Mtime: 0,
  5505. Count: 0,
  5506. StockCount: 0,
  5507. Creater: creator,
  5508. BatchNumberId: warehouse.ID,
  5509. WarehouseOutId: 0,
  5510. }
  5511. service.CreateGoodErrcode(goodErrcode)
  5512. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5513. c.ServeSuccessJSON(map[string]interface{}{
  5514. "message": "1",
  5515. "good_name": goodObj.GoodName,
  5516. "specification_name": goodObj.SpecificationName,
  5517. })
  5518. return
  5519. }
  5520. }
  5521. //查询是否有出库单
  5522. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5523. if err == gorm.ErrRecordNotFound {
  5524. //没有记录,则创建出库单
  5525. timeStr := time.Now().Format("2006-01-02")
  5526. timeArr := strings.Split(timeStr, "-")
  5527. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5528. total = total + 1
  5529. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5530. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5531. number = number + total
  5532. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5533. creater := adminInfo.AdminUser.Id
  5534. warehouseOut := models.WarehouseOut{
  5535. WarehouseOutOrderNumber: warehousing_out_order,
  5536. OperationTime: time.Now().Unix(),
  5537. OrgId: adminInfo.Org.Id,
  5538. Creater: creater,
  5539. Ctime: time.Now().Unix(),
  5540. Status: 1,
  5541. WarehouseOutTime: record_time,
  5542. Dealer: 0,
  5543. Manufacturer: 0,
  5544. Type: 1,
  5545. IsSys: 1,
  5546. StorehouseId: houseConfig.StorehouseOutInfo,
  5547. IsCheck: 1,
  5548. }
  5549. err := service.AddSigleWarehouseOut(&warehouseOut)
  5550. if err != nil {
  5551. goodErrcode := models.XtGoodErrcode{
  5552. UserOrgId: adminInfo.Org.Id,
  5553. Errcode: "创建出库单失败",
  5554. GoodId: 0,
  5555. Status: 1,
  5556. Ctime: time.Now().Unix(),
  5557. Mtime: 0,
  5558. Count: 0,
  5559. StockCount: 0,
  5560. Creater: creator,
  5561. BatchNumberId: 0,
  5562. WarehouseOutId: 0,
  5563. }
  5564. service.CreateGoodErrcode(goodErrcode)
  5565. utils.TraceLog("创建出库单失败 err = %v", err)
  5566. } else {
  5567. for _, item := range consumables {
  5568. //出库
  5569. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5570. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5571. if err == nil {
  5572. goodErrcode := models.XtGoodErrcode{
  5573. UserOrgId: adminInfo.Org.Id,
  5574. Errcode: "自动出库接口报错",
  5575. GoodId: 0,
  5576. Status: 1,
  5577. Ctime: time.Now().Unix(),
  5578. Mtime: 0,
  5579. Count: 0,
  5580. StockCount: 0,
  5581. Creater: creator,
  5582. BatchNumberId: 0,
  5583. WarehouseOutId: 0,
  5584. }
  5585. service.CreateGoodErrcode(goodErrcode)
  5586. utils.TraceLog("创建出库单失败 err = %v", err)
  5587. }
  5588. //查询
  5589. //出库数量相加
  5590. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5591. if errs != nil {
  5592. goodErrcode := models.XtGoodErrcode{
  5593. UserOrgId: item.UserOrgId,
  5594. Errcode: "创建剩余库存字段报错",
  5595. GoodId: item.GoodId,
  5596. Status: 1,
  5597. Ctime: time.Now().Unix(),
  5598. Mtime: 0,
  5599. Count: 0,
  5600. StockCount: 0,
  5601. Creater: creater,
  5602. BatchNumberId: 0,
  5603. WarehouseOutId: 0,
  5604. }
  5605. service.CreateGoodErrcode(goodErrcode)
  5606. }
  5607. }
  5608. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5609. if len(list) == 0 {
  5610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5611. return
  5612. }
  5613. for _, item := range list {
  5614. prepare := models.DialysisBeforePrepare{
  5615. UserOrgId: adminInfo.Org.Id,
  5616. PatientId: patient_id,
  5617. RecordDate: record_time,
  5618. GoodId: item.GoodId,
  5619. GoodTypeId: item.GoodTypeId,
  5620. Count: item.Count,
  5621. Creater: adminInfo.AdminUser.Id,
  5622. Status: 1,
  5623. Ctime: time.Now().Unix(),
  5624. StorehouseId: houseConfig.StorehouseOutInfo,
  5625. }
  5626. //清空准备表数据
  5627. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5628. if err != nil {
  5629. goodErrcode := models.XtGoodErrcode{
  5630. UserOrgId: item.OrgId,
  5631. Errcode: "自动出库清空准备表数据报错",
  5632. GoodId: item.GoodId,
  5633. Status: 1,
  5634. Ctime: time.Now().Unix(),
  5635. Mtime: 0,
  5636. Count: 0,
  5637. StockCount: 0,
  5638. Creater: creater,
  5639. BatchNumberId: 0,
  5640. WarehouseOutId: 0,
  5641. }
  5642. service.CreateGoodErrcode(goodErrcode)
  5643. }
  5644. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5645. if errs != nil {
  5646. goodErrcode := models.XtGoodErrcode{
  5647. UserOrgId: item.OrgId,
  5648. Errcode: "自动出库创建准备表数据报错",
  5649. GoodId: item.GoodId,
  5650. Status: 1,
  5651. Ctime: time.Now().Unix(),
  5652. Mtime: 0,
  5653. Count: 0,
  5654. StockCount: 0,
  5655. Creater: creater,
  5656. BatchNumberId: 0,
  5657. WarehouseOutId: 0,
  5658. }
  5659. service.CreateGoodErrcode(goodErrcode)
  5660. }
  5661. //查询默认仓库
  5662. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5663. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5664. var total_count int64
  5665. for _, it := range stockList {
  5666. total_count += it.StockCount
  5667. }
  5668. //基础库插入数据
  5669. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5670. if errcodes != nil {
  5671. goodErrcode := models.XtGoodErrcode{
  5672. UserOrgId: item.OrgId,
  5673. Errcode: "自动出库基础库插入数据",
  5674. GoodId: item.GoodId,
  5675. Status: 1,
  5676. Ctime: time.Now().Unix(),
  5677. Mtime: 0,
  5678. Count: 0,
  5679. StockCount: 0,
  5680. Creater: creater,
  5681. BatchNumberId: 0,
  5682. WarehouseOutId: 0,
  5683. }
  5684. service.CreateGoodErrcode(goodErrcode)
  5685. }
  5686. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5687. var flush_count int64
  5688. for _, it := range goodList {
  5689. flush_count += it.StockCount
  5690. }
  5691. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5692. if errsss != nil {
  5693. goodErrcode := models.XtGoodErrcode{
  5694. UserOrgId: item.OrgId,
  5695. Errcode: "自动出库剩余库存更新数据",
  5696. GoodId: item.GoodId,
  5697. Status: 1,
  5698. Ctime: time.Now().Unix(),
  5699. Mtime: 0,
  5700. Count: 0,
  5701. StockCount: 0,
  5702. Creater: creater,
  5703. BatchNumberId: 0,
  5704. WarehouseOutId: 0,
  5705. }
  5706. service.CreateGoodErrcode(goodErrcode)
  5707. }
  5708. }
  5709. }
  5710. //
  5711. } else if err == nil {
  5712. for _, item := range consumables {
  5713. //出库
  5714. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5715. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5716. if err != nil {
  5717. goodErrcode := models.XtGoodErrcode{
  5718. UserOrgId: adminInfo.Org.Id,
  5719. Errcode: "自动出库接口报错",
  5720. GoodId: 0,
  5721. Status: 1,
  5722. Ctime: time.Now().Unix(),
  5723. Mtime: 0,
  5724. Count: 0,
  5725. StockCount: 0,
  5726. Creater: creator,
  5727. BatchNumberId: 0,
  5728. WarehouseOutId: 0,
  5729. }
  5730. service.CreateGoodErrcode(goodErrcode)
  5731. }
  5732. //出库数量相加
  5733. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5734. if errss != nil {
  5735. goodErrcode := models.XtGoodErrcode{
  5736. UserOrgId: item.UserOrgId,
  5737. Errcode: "创建剩余库存字段报错",
  5738. GoodId: item.GoodId,
  5739. Status: 1,
  5740. Ctime: time.Now().Unix(),
  5741. Mtime: time.Now().Unix(),
  5742. Count: 0,
  5743. StockCount: 0,
  5744. Creater: item.Creater,
  5745. BatchNumberId: 0,
  5746. WarehouseOutId: 0,
  5747. }
  5748. service.CreateGoodErrcode(goodErrcode)
  5749. }
  5750. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5751. if len(list) == 0 {
  5752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5753. return
  5754. }
  5755. for _, item := range list {
  5756. prepare := models.DialysisBeforePrepare{
  5757. UserOrgId: adminInfo.Org.Id,
  5758. PatientId: patient_id,
  5759. RecordDate: record_time,
  5760. GoodId: item.GoodId,
  5761. GoodTypeId: item.GoodTypeId,
  5762. Count: item.Count,
  5763. Creater: adminInfo.AdminUser.Id,
  5764. Status: 1,
  5765. Ctime: time.Now().Unix(),
  5766. StorehouseId: houseConfig.StorehouseOutInfo,
  5767. }
  5768. //清空准备表数据
  5769. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5770. if errs != nil {
  5771. goodErrcode := models.XtGoodErrcode{
  5772. UserOrgId: adminInfo.Org.Id,
  5773. Errcode: "自动出库清空准备表数据报错",
  5774. GoodId: 0,
  5775. Status: 1,
  5776. Ctime: time.Now().Unix(),
  5777. Mtime: 0,
  5778. Count: 0,
  5779. StockCount: 0,
  5780. Creater: creator,
  5781. BatchNumberId: 0,
  5782. WarehouseOutId: 0,
  5783. }
  5784. service.CreateGoodErrcode(goodErrcode)
  5785. }
  5786. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5787. if errcodes != nil {
  5788. goodErrcode := models.XtGoodErrcode{
  5789. UserOrgId: adminInfo.Org.Id,
  5790. Errcode: "自动出库创建准备表数据报错",
  5791. GoodId: 0,
  5792. Status: 1,
  5793. Ctime: time.Now().Unix(),
  5794. Mtime: 0,
  5795. Count: 0,
  5796. StockCount: 0,
  5797. Creater: creator,
  5798. BatchNumberId: 0,
  5799. WarehouseOutId: 0,
  5800. }
  5801. service.CreateGoodErrcode(goodErrcode)
  5802. }
  5803. //查询默认仓库
  5804. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5805. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5806. var total_count int64
  5807. for _, it := range stockList {
  5808. total_count += it.StockCount
  5809. }
  5810. //基础库插入数据
  5811. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5812. if errcodes != nil {
  5813. goodErrcode := models.XtGoodErrcode{
  5814. UserOrgId: adminInfo.Org.Id,
  5815. Errcode: "自动出库基础库插入数据报错",
  5816. GoodId: 0,
  5817. Status: 1,
  5818. Ctime: time.Now().Unix(),
  5819. Mtime: 0,
  5820. Count: 0,
  5821. StockCount: 0,
  5822. Creater: creator,
  5823. BatchNumberId: 0,
  5824. WarehouseOutId: 0,
  5825. }
  5826. service.CreateGoodErrcode(goodErrcode)
  5827. }
  5828. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5829. var flush_count int64
  5830. for _, it := range goodList {
  5831. flush_count += it.StockCount
  5832. }
  5833. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5834. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5835. if errss != nil {
  5836. goodErrcode := models.XtGoodErrcode{
  5837. UserOrgId: item.OrgId,
  5838. Errcode: "自动出库剩余库存更新数据",
  5839. GoodId: item.GoodId,
  5840. Status: 1,
  5841. Ctime: time.Now().Unix(),
  5842. Mtime: 0,
  5843. Count: 0,
  5844. StockCount: 0,
  5845. Creater: creater,
  5846. BatchNumberId: 0,
  5847. WarehouseOutId: 0,
  5848. }
  5849. service.CreateGoodErrcode(goodErrcode)
  5850. }
  5851. }
  5852. }
  5853. }
  5854. c.ServeSuccessJSON(map[string]interface{}{
  5855. "msg": "提交成功",
  5856. "message": "2",
  5857. "good_name": "",
  5858. "specification_name": "",
  5859. })
  5860. return
  5861. }
  5862. if record.IsOpen == 1 {
  5863. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5864. //查询是否有库存
  5865. for _, item := range consumables {
  5866. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5867. if item.Count > warehouse.Count {
  5868. goodErrcode := models.XtGoodErrcode{
  5869. UserOrgId: item.UserOrgId,
  5870. Errcode: "自动出库库存不足",
  5871. GoodId: item.GoodId,
  5872. Status: 1,
  5873. Ctime: time.Now().Unix(),
  5874. Mtime: 0,
  5875. Count: 0,
  5876. StockCount: 0,
  5877. Creater: creator,
  5878. BatchNumberId: warehouse.ID,
  5879. WarehouseOutId: 0,
  5880. }
  5881. service.CreateGoodErrcode(goodErrcode)
  5882. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5883. c.ServeSuccessJSON(map[string]interface{}{
  5884. "message": "1",
  5885. "good_name": goodObj.GoodName,
  5886. "specification_name": goodObj.SpecificationName,
  5887. })
  5888. return
  5889. }
  5890. }
  5891. //查询是否有出库单
  5892. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5893. if err == gorm.ErrRecordNotFound {
  5894. //没有记录,则创建出库单
  5895. timeStr := time.Now().Format("2006-01-02")
  5896. timeArr := strings.Split(timeStr, "-")
  5897. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5898. total = total + 1
  5899. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5900. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5901. number = number + total
  5902. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5903. creater := adminInfo.AdminUser.Id
  5904. warehouseOut := models.WarehouseOut{
  5905. WarehouseOutOrderNumber: warehousing_out_order,
  5906. OperationTime: time.Now().Unix(),
  5907. OrgId: adminInfo.Org.Id,
  5908. Creater: creater,
  5909. Ctime: time.Now().Unix(),
  5910. Status: 1,
  5911. WarehouseOutTime: record_time,
  5912. Dealer: 0,
  5913. Manufacturer: 0,
  5914. Type: 1,
  5915. IsSys: 1,
  5916. StorehouseId: houseConfig.StorehouseOutInfo,
  5917. IsCheck: 1,
  5918. }
  5919. err := service.AddSigleWarehouseOut(&warehouseOut)
  5920. if err != nil {
  5921. goodErrcode := models.XtGoodErrcode{
  5922. UserOrgId: adminInfo.Org.Id,
  5923. Errcode: "创建出库单失败",
  5924. GoodId: 0,
  5925. Status: 1,
  5926. Ctime: time.Now().Unix(),
  5927. Mtime: 0,
  5928. Count: 0,
  5929. StockCount: 0,
  5930. Creater: creator,
  5931. BatchNumberId: 0,
  5932. WarehouseOutId: 0,
  5933. }
  5934. service.CreateGoodErrcode(goodErrcode)
  5935. utils.TraceLog("创建出库单失败 err = %v", err)
  5936. } else {
  5937. for _, item := range consumables {
  5938. //出库
  5939. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5940. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5941. if err == nil {
  5942. goodErrcode := models.XtGoodErrcode{
  5943. UserOrgId: adminInfo.Org.Id,
  5944. Errcode: "自动出库接口报错",
  5945. GoodId: 0,
  5946. Status: 1,
  5947. Ctime: time.Now().Unix(),
  5948. Mtime: 0,
  5949. Count: 0,
  5950. StockCount: 0,
  5951. Creater: creator,
  5952. BatchNumberId: 0,
  5953. WarehouseOutId: 0,
  5954. }
  5955. service.CreateGoodErrcode(goodErrcode)
  5956. utils.TraceLog("创建出库单失败 err = %v", err)
  5957. }
  5958. //查询
  5959. //出库数量相加
  5960. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5961. if errs != nil {
  5962. goodErrcode := models.XtGoodErrcode{
  5963. UserOrgId: item.UserOrgId,
  5964. Errcode: "创建剩余库存字段报错",
  5965. GoodId: item.GoodId,
  5966. Status: 1,
  5967. Ctime: time.Now().Unix(),
  5968. Mtime: 0,
  5969. Count: 0,
  5970. StockCount: 0,
  5971. Creater: creater,
  5972. BatchNumberId: 0,
  5973. WarehouseOutId: 0,
  5974. }
  5975. service.CreateGoodErrcode(goodErrcode)
  5976. }
  5977. }
  5978. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5979. if len(list) == 0 {
  5980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5981. return
  5982. }
  5983. for _, item := range list {
  5984. prepare := models.DialysisBeforePrepare{
  5985. UserOrgId: adminInfo.Org.Id,
  5986. PatientId: patient_id,
  5987. RecordDate: record_time,
  5988. GoodId: item.GoodId,
  5989. GoodTypeId: item.GoodTypeId,
  5990. Count: item.Count,
  5991. Creater: adminInfo.AdminUser.Id,
  5992. Status: 1,
  5993. Ctime: time.Now().Unix(),
  5994. StorehouseId: houseConfig.StorehouseOutInfo,
  5995. }
  5996. //清空准备表数据
  5997. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5998. if err != nil {
  5999. goodErrcode := models.XtGoodErrcode{
  6000. UserOrgId: item.OrgId,
  6001. Errcode: "自动出库清空准备表数据报错",
  6002. GoodId: item.GoodId,
  6003. Status: 1,
  6004. Ctime: time.Now().Unix(),
  6005. Mtime: 0,
  6006. Count: 0,
  6007. StockCount: 0,
  6008. Creater: creater,
  6009. BatchNumberId: 0,
  6010. WarehouseOutId: 0,
  6011. }
  6012. service.CreateGoodErrcode(goodErrcode)
  6013. }
  6014. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6015. if errs != nil {
  6016. goodErrcode := models.XtGoodErrcode{
  6017. UserOrgId: item.OrgId,
  6018. Errcode: "自动出库创建准备表数据报错",
  6019. GoodId: item.GoodId,
  6020. Status: 1,
  6021. Ctime: time.Now().Unix(),
  6022. Mtime: 0,
  6023. Count: 0,
  6024. StockCount: 0,
  6025. Creater: creater,
  6026. BatchNumberId: 0,
  6027. WarehouseOutId: 0,
  6028. }
  6029. service.CreateGoodErrcode(goodErrcode)
  6030. }
  6031. //查询默认仓库
  6032. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6033. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6034. var total_count int64
  6035. for _, it := range stockList {
  6036. total_count += it.StockCount
  6037. }
  6038. //基础库插入数据
  6039. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6040. if errcodes != nil {
  6041. goodErrcode := models.XtGoodErrcode{
  6042. UserOrgId: item.OrgId,
  6043. Errcode: "自动出库基础库插入数据",
  6044. GoodId: item.GoodId,
  6045. Status: 1,
  6046. Ctime: time.Now().Unix(),
  6047. Mtime: 0,
  6048. Count: 0,
  6049. StockCount: 0,
  6050. Creater: creater,
  6051. BatchNumberId: 0,
  6052. WarehouseOutId: 0,
  6053. }
  6054. service.CreateGoodErrcode(goodErrcode)
  6055. }
  6056. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6057. var flush_count int64
  6058. for _, it := range goodList {
  6059. flush_count += it.StockCount
  6060. }
  6061. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6062. if errsss != nil {
  6063. goodErrcode := models.XtGoodErrcode{
  6064. UserOrgId: item.OrgId,
  6065. Errcode: "自动出库剩余库存更新数据",
  6066. GoodId: item.GoodId,
  6067. Status: 1,
  6068. Ctime: time.Now().Unix(),
  6069. Mtime: 0,
  6070. Count: 0,
  6071. StockCount: 0,
  6072. Creater: creater,
  6073. BatchNumberId: 0,
  6074. WarehouseOutId: 0,
  6075. }
  6076. service.CreateGoodErrcode(goodErrcode)
  6077. }
  6078. }
  6079. }
  6080. //
  6081. } else if err == nil {
  6082. for _, item := range consumables {
  6083. //出库
  6084. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6085. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6086. if err != nil {
  6087. goodErrcode := models.XtGoodErrcode{
  6088. UserOrgId: adminInfo.Org.Id,
  6089. Errcode: "自动出库接口报错",
  6090. GoodId: 0,
  6091. Status: 1,
  6092. Ctime: time.Now().Unix(),
  6093. Mtime: 0,
  6094. Count: 0,
  6095. StockCount: 0,
  6096. Creater: creator,
  6097. BatchNumberId: 0,
  6098. WarehouseOutId: 0,
  6099. }
  6100. service.CreateGoodErrcode(goodErrcode)
  6101. }
  6102. //出库数量相加
  6103. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6104. if errss != nil {
  6105. goodErrcode := models.XtGoodErrcode{
  6106. UserOrgId: item.UserOrgId,
  6107. Errcode: "创建剩余库存字段报错",
  6108. GoodId: item.GoodId,
  6109. Status: 1,
  6110. Ctime: time.Now().Unix(),
  6111. Mtime: time.Now().Unix(),
  6112. Count: 0,
  6113. StockCount: 0,
  6114. Creater: item.Creater,
  6115. BatchNumberId: 0,
  6116. WarehouseOutId: 0,
  6117. }
  6118. service.CreateGoodErrcode(goodErrcode)
  6119. }
  6120. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6121. if len(list) == 0 {
  6122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6123. return
  6124. }
  6125. for _, item := range list {
  6126. prepare := models.DialysisBeforePrepare{
  6127. UserOrgId: adminInfo.Org.Id,
  6128. PatientId: patient_id,
  6129. RecordDate: record_time,
  6130. GoodId: item.GoodId,
  6131. GoodTypeId: item.GoodTypeId,
  6132. Count: item.Count,
  6133. Creater: adminInfo.AdminUser.Id,
  6134. Status: 1,
  6135. Ctime: time.Now().Unix(),
  6136. StorehouseId: houseConfig.StorehouseOutInfo,
  6137. }
  6138. //清空准备表数据
  6139. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6140. if errs != nil {
  6141. goodErrcode := models.XtGoodErrcode{
  6142. UserOrgId: adminInfo.Org.Id,
  6143. Errcode: "自动出库清空准备表数据报错",
  6144. GoodId: 0,
  6145. Status: 1,
  6146. Ctime: time.Now().Unix(),
  6147. Mtime: 0,
  6148. Count: 0,
  6149. StockCount: 0,
  6150. Creater: creator,
  6151. BatchNumberId: 0,
  6152. WarehouseOutId: 0,
  6153. }
  6154. service.CreateGoodErrcode(goodErrcode)
  6155. }
  6156. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6157. if errcodes != nil {
  6158. goodErrcode := models.XtGoodErrcode{
  6159. UserOrgId: adminInfo.Org.Id,
  6160. Errcode: "自动出库创建准备表数据报错",
  6161. GoodId: 0,
  6162. Status: 1,
  6163. Ctime: time.Now().Unix(),
  6164. Mtime: 0,
  6165. Count: 0,
  6166. StockCount: 0,
  6167. Creater: creator,
  6168. BatchNumberId: 0,
  6169. WarehouseOutId: 0,
  6170. }
  6171. service.CreateGoodErrcode(goodErrcode)
  6172. }
  6173. //查询默认仓库
  6174. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6175. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6176. var total_count int64
  6177. for _, it := range stockList {
  6178. total_count += it.StockCount
  6179. }
  6180. //基础库插入数据
  6181. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6182. if errcodes != nil {
  6183. goodErrcode := models.XtGoodErrcode{
  6184. UserOrgId: adminInfo.Org.Id,
  6185. Errcode: "自动出库基础库插入数据报错",
  6186. GoodId: 0,
  6187. Status: 1,
  6188. Ctime: time.Now().Unix(),
  6189. Mtime: 0,
  6190. Count: 0,
  6191. StockCount: 0,
  6192. Creater: creator,
  6193. BatchNumberId: 0,
  6194. WarehouseOutId: 0,
  6195. }
  6196. service.CreateGoodErrcode(goodErrcode)
  6197. }
  6198. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6199. var flush_count int64
  6200. for _, it := range goodList {
  6201. flush_count += it.StockCount
  6202. }
  6203. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6204. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6205. if errss != nil {
  6206. goodErrcode := models.XtGoodErrcode{
  6207. UserOrgId: item.OrgId,
  6208. Errcode: "自动出库剩余库存更新数据",
  6209. GoodId: item.GoodId,
  6210. Status: 1,
  6211. Ctime: time.Now().Unix(),
  6212. Mtime: 0,
  6213. Count: 0,
  6214. StockCount: 0,
  6215. Creater: creater,
  6216. BatchNumberId: 0,
  6217. WarehouseOutId: 0,
  6218. }
  6219. service.CreateGoodErrcode(goodErrcode)
  6220. }
  6221. }
  6222. }
  6223. }
  6224. c.ServeSuccessJSON(map[string]interface{}{
  6225. "msg": "提交成功",
  6226. "message": "2",
  6227. "good_name": "",
  6228. "specification_name": "",
  6229. })
  6230. return
  6231. } else {
  6232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6233. return
  6234. }
  6235. }
  6236. func (c *DialysisAPIController) EditConsumables() {
  6237. patient_id, _ := c.GetInt64("patient_id", 0)
  6238. record_date := c.GetString("record_time")
  6239. if patient_id <= 0 {
  6240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6241. return
  6242. }
  6243. adminInfo := c.GetMobileAdminUserInfo()
  6244. timeLayout := "2006-01-02"
  6245. loc, _ := time.LoadLocation("Local")
  6246. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6247. record_time := theRecordTime.Unix()
  6248. // 查询信息规挡的设置天数
  6249. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6250. if infor.ID > 0 && infor.WeekDay > 0 {
  6251. var cha_time int64
  6252. timeNowStr := time.Now().Format("2006-01-02")
  6253. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6254. //今日的日期减去设置的日期
  6255. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6256. if cha_time >= record_time {
  6257. //查询审核是否允许
  6258. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6259. //申请状态不允许的情况 拒绝修改
  6260. if infor.ApplicationStatus != 1 {
  6261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6262. return
  6263. }
  6264. }
  6265. }
  6266. dataBody := make(map[string]interface{}, 0)
  6267. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6268. if err != nil {
  6269. utils.ErrorLog(err.Error())
  6270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6271. return
  6272. }
  6273. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6274. var beforePrepares []*models.DialysisBeforePrepareGoods
  6275. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6276. var cancelbefor []*models.DialysisBeforePrepareGoods
  6277. var outbefor []*models.DialysisBeforePrepareGoods
  6278. //判断是否开启自动出库
  6279. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6280. if record.IsOpen == 1 {
  6281. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6282. goods, _ := dataBody["goods"].([]interface{})
  6283. if len(goods) > 0 {
  6284. for _, item := range goods {
  6285. items := item.(map[string]interface{})
  6286. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6287. utils.ErrorLog("good_id")
  6288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6289. return
  6290. }
  6291. good_id := int64(items["good_id"].(float64))
  6292. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6293. utils.ErrorLog("good_type_id")
  6294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6295. return
  6296. }
  6297. good_type_id := int64(items["good_type_id"].(float64))
  6298. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6299. utils.ErrorLog("count")
  6300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6301. return
  6302. }
  6303. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6304. commdity_code := items["commdity_code"].(string)
  6305. fmt.Println(commdity_code)
  6306. prepareGoods := &models.DialysisBeforePrepareGoods{
  6307. GoodTypeId: good_type_id,
  6308. GoodId: good_id,
  6309. Count: count,
  6310. StorehouseId: houseConfig.StorehouseOutInfo,
  6311. }
  6312. beforePrepares = append(beforePrepares, prepareGoods)
  6313. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6314. GoodTypeId: good_type_id,
  6315. GoodId: good_id,
  6316. Count: count,
  6317. StorehouseId: houseConfig.StorehouseOutInfo,
  6318. }
  6319. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6320. }
  6321. for _, item := range beforePrepares {
  6322. //1.查看该患者该耗材型号最后一次出库数量
  6323. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6324. //判断当前出库数量和最后一次出库数量的大小
  6325. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6326. if item.Count < goodInfo.Count {
  6327. cancelbefor = append(cancelbefor, item)
  6328. }
  6329. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6330. if item.Count > goodInfo.Count {
  6331. outbefor = append(outbefor, item)
  6332. }
  6333. //处理编辑耗材新增不了的问题
  6334. if goodInfo.Count == item.Count {
  6335. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6336. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6337. }
  6338. }
  6339. if len(cancelbefor) > 0 {
  6340. //退库
  6341. for _, item := range cancelbefor {
  6342. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6343. creater := adminInfo.AdminUser.Id
  6344. //查询该患者当天已经出库的耗材信息
  6345. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6346. var delete_count int64 = 0
  6347. delete_count = warehouseOutInfos.Count - item.Count
  6348. //增加库存数量
  6349. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6350. //减少实际出库库存数量
  6351. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6352. // 删除出库完成后,要增加对应批次的库存数量
  6353. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6354. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6355. //更新剩余库存
  6356. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6357. var flush_count int64
  6358. for _, it := range goodListOne {
  6359. flush_count += it.StockCount
  6360. }
  6361. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6362. //查询剩余库存
  6363. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6364. var sum_count int64
  6365. for _, item := range goodList {
  6366. sum_count += item.StockCount
  6367. }
  6368. // 在出库记录表里记录退库详情
  6369. warehouseOutInfo := &models.WarehouseOutInfo{
  6370. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6371. WarehouseOutId: warehouseOut.ID,
  6372. Status: 1,
  6373. Ctime: time.Now().Unix(),
  6374. OrgId: adminInfo.Org.Id,
  6375. Type: 1,
  6376. IsSys: 1,
  6377. SysRecordTime: record_time,
  6378. GoodTypeId: item.GoodTypeId,
  6379. GoodId: item.GoodId,
  6380. PatientId: patient_id,
  6381. ConsumableType: 2,
  6382. StorehouseId: houseConfig.StorehouseOutInfo,
  6383. IsCheck: 1,
  6384. OverCount: sum_count,
  6385. }
  6386. warehouseOutInfo.Count = item.Count
  6387. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6388. warehouseOutInfo.Price = stockInInfo.Price
  6389. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6390. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6391. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6392. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6393. warehouseOutInfo.Number = warehouseOutInfos.Number
  6394. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6395. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6396. //查找当天是否存在出库记录
  6397. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6398. if errcod == gorm.ErrRecordNotFound {
  6399. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6400. //插入详情明细表
  6401. stockFlow := models.VmStockFlow{
  6402. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6403. WarehouseOutId: warehouseOut.ID,
  6404. GoodId: item.GoodId,
  6405. Number: warehouseOutInfos.Number,
  6406. ProductDate: stockInInfo.ProductDate,
  6407. ExpireDate: stockInInfo.ExpiryDate,
  6408. Count: item.Count,
  6409. Price: stockInInfo.Price,
  6410. Status: 1,
  6411. Ctime: record_time,
  6412. UserOrgId: adminInfo.Org.Id,
  6413. Manufacturer: stockInInfo.Manufacturer,
  6414. Dealer: stockInInfo.Dealer,
  6415. LicenseNumber: stockInInfo.LicenseNumber,
  6416. IsEdit: 2,
  6417. Creator: creater,
  6418. SystemTime: record_time,
  6419. ConsumableType: 3,
  6420. WarehousingDetailId: 0,
  6421. IsSys: 1,
  6422. UpdateCreator: creater,
  6423. PatientId: patient_id,
  6424. StorehouseId: houseConfig.StorehouseOutInfo,
  6425. }
  6426. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6427. if errflow == gorm.ErrRecordNotFound {
  6428. //创建流水表
  6429. err := service.CreateStockFlowOne(stockFlow)
  6430. fmt.Println("err", err)
  6431. } else if errflow == nil {
  6432. //插入详情明细表
  6433. stockFlow := models.VmStockFlow{
  6434. ID: exsit.ID,
  6435. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6436. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6437. WarehouseOutId: warehouseOut.ID,
  6438. GoodId: item.GoodId,
  6439. Number: warehouseOutInfos.Number,
  6440. ProductDate: stockInInfo.ProductDate,
  6441. ExpireDate: stockInInfo.ExpiryDate,
  6442. Count: exsit.Count - delete_count,
  6443. Price: stockInInfo.Price,
  6444. Status: 1,
  6445. Ctime: record_time,
  6446. UserOrgId: adminInfo.Org.Id,
  6447. Manufacturer: stockInInfo.Manufacturer,
  6448. Dealer: stockInInfo.Dealer,
  6449. LicenseNumber: stockInInfo.LicenseNumber,
  6450. IsEdit: 2,
  6451. Creator: creater,
  6452. SystemTime: record_time,
  6453. ConsumableType: 3,
  6454. WarehousingDetailId: 0,
  6455. IsSys: 1,
  6456. UpdateCreator: creater,
  6457. PatientId: patient_id,
  6458. StorehouseId: houseConfig.StorehouseOutInfo,
  6459. }
  6460. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6461. }
  6462. } else if errcod == nil {
  6463. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6464. //查询剩余库存
  6465. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6466. var sum_count int64
  6467. for _, item := range goodList {
  6468. sum_count += item.StockCount
  6469. }
  6470. //创建退库单,生成退库数据
  6471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6472. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6473. operation_time := time.Now().Unix()
  6474. creater := adminInfo.AdminUser.Id
  6475. //创建退库单
  6476. timeStr := time.Now().Format("2006-01-02")
  6477. timeArr := strings.Split(timeStr, "-")
  6478. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6479. total = total + 1
  6480. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6481. cancelStock := models.CancelStock{
  6482. OrderNumber: orderNumber,
  6483. OperaTime: operation_time,
  6484. OrgId: adminInfo.Org.Id,
  6485. Creater: creater,
  6486. Ctime: time.Now().Unix(),
  6487. Status: 1,
  6488. ReturnTime: record_time,
  6489. Type: 1,
  6490. StorehouseId: houseConfig.StorehouseOutInfo,
  6491. IsCheck: 1,
  6492. }
  6493. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6494. if msgerrkonde == gorm.ErrRecordNotFound {
  6495. service.AddSigleCancelStock(&cancelStock)
  6496. }
  6497. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6498. //查询是否有出库
  6499. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6500. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6501. deaerler, _ := service.GetDealerById(info.Dealer)
  6502. if info.ID > 0 {
  6503. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6504. cancelStockInfo := models.CancelStockInfo{
  6505. GoodId: item.GoodId,
  6506. CancelStockId: cancel.ID,
  6507. GoodTypeId: good.GoodTypeId,
  6508. Count: delete_count,
  6509. Price: info.Price,
  6510. Total: 0,
  6511. ProductDate: info.ProductDate,
  6512. ExpiryDate: info.ExpiryDate,
  6513. Ctime: time.Now().Unix(),
  6514. Status: 1,
  6515. OrgId: adminInfo.Org.Id,
  6516. OrderNumber: cancel.OrderNumber,
  6517. Type: 0,
  6518. Dealer: deaerler.DealerName,
  6519. Manufacturer: manufacturer.ManufacturerName,
  6520. Number: info.Number,
  6521. RegisterAccount: "",
  6522. Remark: "",
  6523. WarehouseInfoId: info.WarehouseInfotId,
  6524. PatientId: info.PatientId,
  6525. RecordDate: info.SysRecordTime,
  6526. StorehouseId: houseConfig.StorehouseOutInfo,
  6527. IsCheck: 1,
  6528. }
  6529. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6530. //退库数量增加
  6531. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6532. //查询剩余库存
  6533. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6534. var over_count int64
  6535. for _, it := range goodList {
  6536. over_count += it.StockCount
  6537. }
  6538. flow := models.VmStockFlow{
  6539. WarehousingId: info.WarehouseInfotId,
  6540. GoodId: item.GoodId,
  6541. Number: info.Number,
  6542. LicenseNumber: info.LicenseNumber,
  6543. Count: delete_count,
  6544. UserOrgId: adminInfo.Org.Id,
  6545. PatientId: patient_id,
  6546. SystemTime: info.SysRecordTime,
  6547. ConsumableType: 7,
  6548. IsSys: 0,
  6549. WarehousingOrder: "",
  6550. WarehouseOutId: info.WarehouseOutId,
  6551. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6552. IsEdit: 0,
  6553. CancelStockId: cancel.ID,
  6554. CancelOrderNumber: cancel.OrderNumber,
  6555. Manufacturer: manufacturer.ID,
  6556. Dealer: 0,
  6557. Creator: adminInfo.AdminUser.Id,
  6558. UpdateCreator: 0,
  6559. Status: 1,
  6560. Ctime: record_time,
  6561. Mtime: 0,
  6562. Price: info.Price,
  6563. WarehousingDetailId: info.WarehouseInfotId,
  6564. WarehouseOutDetailId: info.ID,
  6565. CancelOutDetailId: cancelInfo.ID,
  6566. ProductDate: info.ProductDate,
  6567. ExpireDate: info.ExpiryDate,
  6568. StorehouseId: houseConfig.StorehouseOutInfo,
  6569. OverCount: over_count,
  6570. }
  6571. service.CreateStockFlowOne(flow)
  6572. }
  6573. }
  6574. //更改自动出库的表格
  6575. details := models.BloodAutomaticReduceDetail{
  6576. WarehouseOutId: warehouseOutInfo.ID,
  6577. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6578. PatientId: patient_id,
  6579. Ctime: time.Now().Unix(),
  6580. Mtime: time.Now().Unix(),
  6581. Status: 1,
  6582. RecordTime: record_time,
  6583. OrgId: adminInfo.Org.Id,
  6584. GoodId: item.GoodId,
  6585. GoodTypeId: item.GoodTypeId,
  6586. Count: item.Count,
  6587. StorehouseId: houseConfig.StorehouseOutInfo,
  6588. }
  6589. //查询当天耗材是否已经存在数据
  6590. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6591. if errcode == gorm.ErrRecordNotFound {
  6592. service.CreateAutoReduceRecord(&details)
  6593. } else if errcode == nil {
  6594. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6595. service.CreateAutoReduceRecord(&details)
  6596. }
  6597. //查询默认仓库
  6598. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6599. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6600. var total_count int64
  6601. for _, it := range stockList {
  6602. total_count += it.StockCount
  6603. }
  6604. //基础库插入数据
  6605. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6606. }
  6607. }
  6608. if len(outbefor) > 0 {
  6609. //出库
  6610. for _, item := range outbefor {
  6611. var last_total int64
  6612. //1.查看该患者该耗材型号最后一次出库数量
  6613. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6614. //计算当前出库和最后一次出库数据相差数据
  6615. last_total = item.Count - goodInfoOne.Count
  6616. //查询该耗材的总库存
  6617. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6618. // 如果库存差大于剩余库存则提示库存不足
  6619. if last_total > wareinfo.StockCount {
  6620. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6621. c.ServeSuccessJSON(map[string]interface{}{
  6622. "message": "1",
  6623. "good_name": goodObj.GoodName,
  6624. "specification_name": goodObj.SpecificationName,
  6625. })
  6626. return
  6627. } else {
  6628. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6629. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6630. if err == gorm.ErrRecordNotFound {
  6631. //没有记录,则创建出库单
  6632. timeStr := time.Now().Format("2006-01-02")
  6633. timeArr := strings.Split(timeStr, "-")
  6634. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6635. total = total + 1
  6636. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6637. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6638. number = number + total
  6639. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6640. warehouseOut := models.WarehouseOut{
  6641. WarehouseOutOrderNumber: warehousing_out_order,
  6642. OperationTime: time.Now().Unix(),
  6643. OrgId: adminInfo.Org.Id,
  6644. Creater: adminInfo.AdminUser.Id,
  6645. Ctime: time.Now().Unix(),
  6646. Status: 1,
  6647. WarehouseOutTime: record_time,
  6648. Dealer: 0,
  6649. Manufacturer: 0,
  6650. Type: 1,
  6651. IsSys: 1,
  6652. StorehouseId: houseConfig.StorehouseOutInfo,
  6653. IsCheck: 1,
  6654. }
  6655. service.AddSigleWarehouseOut(&warehouseOut)
  6656. }
  6657. //出库
  6658. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6659. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6660. //1.查看该患者该耗材型号最后一次出库数量
  6661. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6662. prepare := models.DialysisBeforePrepare{
  6663. UserOrgId: adminInfo.Org.Id,
  6664. PatientId: patient_id,
  6665. RecordDate: record_time,
  6666. GoodId: item.GoodId,
  6667. GoodTypeId: item.GoodTypeId,
  6668. Count: item.Count - goodInfoTwo.Count,
  6669. Ctime: time.Now().Unix(),
  6670. Mtime: 0,
  6671. Creater: adminInfo.AdminUser.Id,
  6672. Modifier: adminInfo.AdminUser.Id,
  6673. Status: 1,
  6674. CommdityCode: "",
  6675. NewCount: 0,
  6676. ProjectId: 0,
  6677. StorehouseId: houseConfig.StorehouseOutInfo,
  6678. }
  6679. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6680. //增加出库数量
  6681. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6682. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6683. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6684. var total_count int64
  6685. for _, it := range stockList {
  6686. total_count += it.StockCount
  6687. }
  6688. //基础库插入数据
  6689. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6690. //剩余库存
  6691. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6692. var flush_count int64
  6693. for _, it := range goodList {
  6694. flush_count += it.StockCount
  6695. }
  6696. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6697. }
  6698. }
  6699. }
  6700. //查询今日出库数据
  6701. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6702. for _, it := range list {
  6703. prepare := models.DialysisBeforePrepare{
  6704. UserOrgId: it.OrgId,
  6705. PatientId: patient_id,
  6706. RecordDate: it.RecordTime,
  6707. GoodId: it.GoodId,
  6708. GoodTypeId: it.GoodTypeId,
  6709. Count: it.Count,
  6710. Ctime: time.Now().Unix(),
  6711. Creater: adminInfo.AdminUser.Id,
  6712. Status: 1,
  6713. StorehouseId: houseConfig.StorehouseOutInfo,
  6714. ProjectId: it.ProjectId,
  6715. }
  6716. //删除准备表数据
  6717. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6718. service.CreateDialysisBeforePrepareOne(&prepare)
  6719. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6720. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6721. var total_count int64
  6722. for _, it := range stockList {
  6723. total_count += it.StockCount
  6724. }
  6725. //基础库插入数据
  6726. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6727. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6728. var flush_count int64
  6729. for _, it := range goodList {
  6730. flush_count += it.StockCount
  6731. }
  6732. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6733. }
  6734. }
  6735. }
  6736. //更新自动出库的地方
  6737. var errs error
  6738. if errs == nil {
  6739. c.ServeSuccessJSON(map[string]interface{}{
  6740. "msg": "修改成功",
  6741. "message": "2",
  6742. "good_name": "",
  6743. "specification_name": "",
  6744. })
  6745. return
  6746. } else {
  6747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6748. return
  6749. }
  6750. }
  6751. }
  6752. func (c *DialysisAPIController) GetDialysisGoods() {
  6753. schedualDate := c.GetString("schedule_date")
  6754. schedule_type, _ := c.GetInt64("schedule_type")
  6755. partition_id, _ := c.GetInt64("partition_id")
  6756. page, _ := c.GetInt("page")
  6757. patient_id, _ := c.GetInt64("patient_id")
  6758. schedualEndDate := int64(0)
  6759. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6760. if parseDateErr != nil && len(schedualDate) != 0 {
  6761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6762. return
  6763. }
  6764. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6765. if parseDateErr != nil && len(schedualDate) != 0 {
  6766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6767. return
  6768. }
  6769. schedualEndDate = endDate.Unix()
  6770. adminUser := c.GetMobileAdminUserInfo()
  6771. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6772. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6773. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6774. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6775. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6776. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6777. //获取当天该病人的透析处方
  6778. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6779. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6780. if err == gorm.ErrRecordNotFound {
  6781. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6782. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6783. if patient_id != 0 {
  6784. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6785. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6786. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6787. //获取患者总的出库数据
  6788. item.LastAutomaticReduceDetail = goodUser
  6789. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6790. item.Project = project
  6791. for _, it := range item.AutomaticReduceDetail {
  6792. var total int64
  6793. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6794. for _, its := range auto {
  6795. total += its.Count
  6796. }
  6797. it.Count = total
  6798. }
  6799. }
  6800. }
  6801. c.ServeSuccessJSON(map[string]interface{}{
  6802. "dialysis_goods": dialysisGoods,
  6803. "good_type": goodTypes,
  6804. "total": total,
  6805. "prescribe": prescribe,
  6806. "good_info": good_info,
  6807. "warehouseOutList": warehouseOutList,
  6808. "config": config,
  6809. "outConfig": outConfig,
  6810. "settleConfig": settleConfig,
  6811. })
  6812. return
  6813. } else if err == nil {
  6814. //获取当天排班的每个患者的库存使用情况
  6815. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6816. //获取患者总的出库数据
  6817. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6818. if patient_id != 0 {
  6819. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6820. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6821. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6822. item.Project = project
  6823. item.LastAutomaticReduceDetail = goodUser
  6824. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6825. for _, it := range item.AutomaticReduceDetail {
  6826. var total int64
  6827. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6828. for _, its := range auto {
  6829. total += its.Count
  6830. }
  6831. it.Count = total
  6832. }
  6833. }
  6834. }
  6835. if err == nil {
  6836. c.ServeSuccessJSON(map[string]interface{}{
  6837. "dialysis_goods": dialysisGoods,
  6838. "good_type": goodTypes,
  6839. "total": total,
  6840. "prescribe": prescribe,
  6841. "good_info": good_info,
  6842. "project": project,
  6843. "warehouseOutList": warehouseOutList,
  6844. "config": config,
  6845. "outConfig": outConfig,
  6846. "settleConfig": settleConfig,
  6847. })
  6848. return
  6849. } else {
  6850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6851. return
  6852. }
  6853. } else if err != nil {
  6854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6855. return
  6856. }
  6857. }
  6858. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6859. start_time := c.GetString("start_time")
  6860. end_time := c.GetString("end_time")
  6861. timeLayout := "2006-01-02"
  6862. loc, _ := time.LoadLocation("Local")
  6863. var theStartTime int64
  6864. if len(start_time) > 0 {
  6865. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6866. if err != nil {
  6867. utils.ErrorLog(err.Error())
  6868. }
  6869. theStartTime = theTime.Unix()
  6870. }
  6871. var theEndtTime int64
  6872. if len(end_time) > 0 {
  6873. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6874. if err != nil {
  6875. utils.ErrorLog(err.Error())
  6876. }
  6877. theEndtTime = theTime.Unix()
  6878. }
  6879. adminUser := c.GetMobileAdminUserInfo()
  6880. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6881. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6882. if err == nil {
  6883. c.ServeSuccessJSON(map[string]interface{}{
  6884. "stock_out": outInfo,
  6885. "stockCount": stockCount,
  6886. })
  6887. return
  6888. } else {
  6889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6890. return
  6891. }
  6892. }
  6893. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6894. patient_id, _ := c.GetInt64("patient_id", 0)
  6895. record_time := c.GetString("record_time")
  6896. adminUser := c.GetMobileAdminUserInfo()
  6897. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6898. if parseDateErr != nil && len(record_time) != 0 {
  6899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6900. return
  6901. }
  6902. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6903. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6904. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6905. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6906. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6907. //获取今日患者的透析处方参数
  6908. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6909. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6910. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6911. c.ServeSuccessJSON(map[string]interface{}{
  6912. "good_type": goodTypes,
  6913. "good_user": goodUser,
  6914. "good_info": good_info,
  6915. "last_good_user": lastGoodUserDetial,
  6916. "project": project,
  6917. "prescription": prescribe,
  6918. "outInfo": outInfo,
  6919. "configs": configs,
  6920. })
  6921. return
  6922. }
  6923. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6924. patient_id, _ := c.GetInt64("patient_id", 0)
  6925. record_date := c.GetString("record_time")
  6926. timeLayout := "2006-01-02"
  6927. loc, _ := time.LoadLocation("Local")
  6928. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6929. record_time := theRecordTime.Unix()
  6930. adminInfo := c.GetMobileAdminUserInfo()
  6931. dataBody := make(map[string]interface{}, 0)
  6932. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6933. if err != nil {
  6934. utils.ErrorLog(err.Error())
  6935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6936. return
  6937. }
  6938. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6939. var beforePrepares []*models.DialysisBeforePrepareGoods
  6940. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6941. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6942. goods, _ := dataBody["goods"].([]interface{})
  6943. if len(goods) > 0 {
  6944. for _, item := range goods {
  6945. items := item.(map[string]interface{})
  6946. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6947. utils.ErrorLog("good_id")
  6948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6949. return
  6950. }
  6951. good_id := int64(items["good_id"].(float64))
  6952. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6953. utils.ErrorLog("good_type_id")
  6954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6955. return
  6956. }
  6957. good_type_id := int64(items["good_type_id"].(float64))
  6958. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6959. utils.ErrorLog("count")
  6960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6961. return
  6962. }
  6963. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6964. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6965. utils.ErrorLog("project_id")
  6966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6967. return
  6968. }
  6969. project_id := int64(items["project_id"].(float64))
  6970. new_count := int64(items["new_count"].(float64))
  6971. old_count := int64(items["old_count"].(float64))
  6972. prepare := &models.DialysisBeforePrepareGoods{
  6973. GoodId: good_id,
  6974. GoodTypeId: good_type_id,
  6975. Count: count,
  6976. ProjectId: project_id,
  6977. StorehouseId: houseConfig.StorehouseOutInfo,
  6978. NewCount: new_count,
  6979. OldCount: old_count,
  6980. }
  6981. beforePrepares = append(beforePrepares, prepare)
  6982. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6983. GoodId: good_id,
  6984. GoodTypeId: good_type_id,
  6985. Count: count,
  6986. ProjectId: project_id,
  6987. StorehouseId: houseConfig.StorehouseOutInfo,
  6988. NewCount: new_count,
  6989. OldCount: old_count,
  6990. }
  6991. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6992. }
  6993. }
  6994. }
  6995. //查询是否有库存
  6996. for _, item := range beforePrepares {
  6997. if item.NewCount > 0 {
  6998. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6999. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7000. if item.Count > warehouse.Count {
  7001. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7002. c.ServeSuccessJSON(map[string]interface{}{
  7003. "message": "1",
  7004. "good_name": goodObj.GoodName,
  7005. "specification_name": goodObj.SpecificationName,
  7006. })
  7007. return
  7008. }
  7009. }
  7010. }
  7011. // 查询信息规挡的设置天数
  7012. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7013. if infor.ID > 0 && infor.WeekDay > 0 {
  7014. var cha_time int64
  7015. timeNowStr := time.Now().Format("2006-01-02")
  7016. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7017. //今日的日期减去设置的日期
  7018. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7019. if cha_time >= record_time {
  7020. //查询审核是否允许
  7021. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7022. //申请状态不允许的情况 拒绝修改
  7023. if infor.ApplicationStatus != 1 {
  7024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7025. return
  7026. }
  7027. }
  7028. }
  7029. //出库逻辑
  7030. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7031. if err != nil {
  7032. utils.ErrorLog(err.Error())
  7033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7034. return
  7035. }
  7036. finish := models.XtDialysisFinish{
  7037. IsFinish: 1,
  7038. UserOrgId: adminInfo.Org.Id,
  7039. Status: 1,
  7040. Ctime: time.Now().Unix(),
  7041. Mtime: 0,
  7042. Module: 11,
  7043. RecordDate: record_time,
  7044. Sourse: 1,
  7045. PatientId: patient_id,
  7046. }
  7047. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7048. if dialysisFinish.ID == 0 {
  7049. service.CreateDialysisFinish(finish)
  7050. }
  7051. //查询当天出库的数据
  7052. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7053. for _, item := range list {
  7054. prepare := models.DialysisBeforePrepare{
  7055. UserOrgId: item.OrgId,
  7056. PatientId: item.PatientId,
  7057. RecordDate: item.RecordTime,
  7058. GoodId: item.GoodId,
  7059. GoodTypeId: item.GoodTypeId,
  7060. Count: item.Count,
  7061. Creater: adminInfo.AdminUser.Id,
  7062. Status: 1,
  7063. Ctime: time.Now().Unix(),
  7064. ProjectId: item.ProjectId,
  7065. StorehouseId: houseConfig.StorehouseOutInfo,
  7066. }
  7067. //清空准备表的数据
  7068. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7069. //插入准备表数据
  7070. service.CreateDialysisBeforePrepareOne(&prepare)
  7071. //查询默认仓库
  7072. //查询默认仓库
  7073. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7074. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7075. var total_count int64
  7076. for _, it := range stockList {
  7077. total_count += it.StockCount
  7078. }
  7079. //基础库插入数据
  7080. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7081. ////更新剩余库存
  7082. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7083. var flush_count int64
  7084. for _, it := range goodList {
  7085. flush_count += it.StockCount
  7086. }
  7087. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7088. if errs != nil {
  7089. goodErrcode := models.XtGoodErrcode{
  7090. UserOrgId: item.OrgId,
  7091. Errcode: "手动出库更新剩余出库失败",
  7092. GoodId: item.GoodId,
  7093. Status: 1,
  7094. Ctime: time.Now().Unix(),
  7095. Mtime: 0,
  7096. Count: 0,
  7097. StockCount: 0,
  7098. Creater: adminInfo.AdminUser.Id,
  7099. BatchNumberId: 0,
  7100. WarehouseOutId: 0,
  7101. }
  7102. service.CreateGoodErrcode(goodErrcode)
  7103. }
  7104. }
  7105. //更新自动出库的地方
  7106. var errs error
  7107. if errs == nil {
  7108. c.ServeSuccessJSON(map[string]interface{}{
  7109. "msg": "修改成功",
  7110. "message": "2",
  7111. "good_name": "",
  7112. "specification_name": "",
  7113. })
  7114. return
  7115. } else {
  7116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7117. return
  7118. }
  7119. }
  7120. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7121. newArr = make([]*models.DialysisBeforePrepare, 0)
  7122. for i := 0; i < len(arr); i++ {
  7123. repeat := false
  7124. for j := i + 1; j < len(arr); j++ {
  7125. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7126. repeat = true
  7127. break
  7128. }
  7129. }
  7130. if !repeat {
  7131. newArr = append(newArr, arr[i])
  7132. }
  7133. }
  7134. return
  7135. }
  7136. func (c *DialysisAPIController) GetAllDrug() {
  7137. patient_id, _ := c.GetInt64("patient_id", 0)
  7138. adminInfo := c.GetMobileAdminUserInfo()
  7139. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7140. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7141. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7142. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7143. c.ServeSuccessJSON(map[string]interface{}{
  7144. "base_drug_config": drugStockConfig,
  7145. "private_drug_config": privateDrugConfig,
  7146. "base_drug_list": drugList,
  7147. "private_drug_list": privateDrugList,
  7148. })
  7149. }
  7150. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7151. newArr = make([]*models.DialysisBeforePrepare, 0)
  7152. for i := 0; i < len(arr); i++ {
  7153. repeat := false
  7154. for j := i + 1; j < len(arr); j++ {
  7155. if arr[i].GoodId == arr[j].GoodId {
  7156. repeat = true
  7157. break
  7158. }
  7159. }
  7160. if !repeat {
  7161. newArr = append(newArr, arr[i])
  7162. }
  7163. }
  7164. return
  7165. }
  7166. func (c *DialysisAPIController) GetDepartment() {
  7167. adminInfo := c.GetMobileAdminUserInfo()
  7168. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7169. if err == nil {
  7170. c.ServeSuccessJSON(map[string]interface{}{
  7171. "departments": departments,
  7172. })
  7173. } else {
  7174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7175. return
  7176. }
  7177. }
  7178. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7179. types, _ := c.GetInt("type", 0)
  7180. start_time := c.GetString("start_time")
  7181. end_time := c.GetString("end_time")
  7182. orgId := c.GetMobileAdminUserInfo().Org.Id
  7183. timeLayout := "2006-01-02"
  7184. loc, _ := time.LoadLocation("Local")
  7185. var startTime int64
  7186. if len(start_time) > 0 {
  7187. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7188. if err != nil {
  7189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7190. return
  7191. }
  7192. startTime = theTime.Unix()
  7193. }
  7194. var endTime int64
  7195. if len(end_time) > 0 {
  7196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7197. if err != nil {
  7198. utils.ErrorLog(err.Error())
  7199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7200. return
  7201. }
  7202. endTime = theTime.Unix()
  7203. }
  7204. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7205. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7206. if err != nil {
  7207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7208. } else {
  7209. c.ServeSuccessJSON(map[string]interface{}{
  7210. "list": list,
  7211. "type": types,
  7212. "stockTotal": stockTotal,
  7213. })
  7214. }
  7215. }
  7216. func (c *DialysisAPIController) GetPrescriptionList() {
  7217. start_time := c.GetString("start_time")
  7218. end_time := c.GetString("end_time")
  7219. schedule_type, _ := c.GetInt64("schedule_type")
  7220. partion_id, _ := c.GetInt64("partion_id")
  7221. orgId := c.GetMobileAdminUserInfo().Org.Id
  7222. timeLayout := "2006-01-02"
  7223. loc, _ := time.LoadLocation("Local")
  7224. var startTime int64
  7225. if len(start_time) > 0 {
  7226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7227. if err != nil {
  7228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7229. return
  7230. }
  7231. startTime = theTime.Unix()
  7232. }
  7233. var endTime int64
  7234. if len(end_time) > 0 {
  7235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7236. if err != nil {
  7237. utils.ErrorLog(err.Error())
  7238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7239. return
  7240. }
  7241. endTime = theTime.Unix()
  7242. }
  7243. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7244. fmt.Println("schedulelist22222222", schedulelist)
  7245. c.ServeSuccessJSON(map[string]interface{}{
  7246. "list": schedulelist,
  7247. })
  7248. return
  7249. }
  7250. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7251. ids := c.GetString("ids")
  7252. //patient_id, _ := c.GetInt64("patient_id")
  7253. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7254. idArray := strings.Split(ids, ",")
  7255. err := service.BatchDeleteMonitor(idArray)
  7256. fmt.Print("err", err)
  7257. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7258. //redis := service.RedisClient()
  7259. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7260. //redis.Set(key, "", time.Second)
  7261. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7262. //redis.Set(keyOne, "", time.Second)
  7263. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7264. //redis.Close()
  7265. c.ServeSuccessJSON(map[string]interface{}{
  7266. "msg": "批量删除成功",
  7267. })
  7268. return
  7269. }
  7270. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7271. id, _ := c.GetInt64("id")
  7272. timeLayout := "2006-01-02"
  7273. loc, _ := time.LoadLocation("Local")
  7274. //start_time := time.Now().Format("2006-01-02")
  7275. start_time := c.GetString("start_time")
  7276. end_time := c.GetString("end_time")
  7277. var startdateunix int64
  7278. if len(start_time) > 0 {
  7279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7280. if err != nil {
  7281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7282. return
  7283. }
  7284. startdateunix = theTime.Unix()
  7285. }
  7286. var enddateunix int64
  7287. if len(end_time) > 0 {
  7288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7289. if err != nil {
  7290. utils.ErrorLog(err.Error())
  7291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7292. return
  7293. }
  7294. enddateunix = theTime.Unix()
  7295. }
  7296. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7297. //nowTime := time.Now()
  7298. //endTime := nowTime.AddDate(-30, 0, 0)
  7299. //endTimes := endTime.Format("2006-01-02")
  7300. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7301. org_id := c.GetMobileAdminUserInfo().Org.Id
  7302. //if org_id == 10579 {
  7303. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7304. // c.ServeSuccessJSON(map[string]interface{}{
  7305. // "list": list,
  7306. // })
  7307. // return
  7308. //} else {
  7309. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7310. // c.ServeSuccessJSON(map[string]interface{}{
  7311. // "list": list,
  7312. // })
  7313. // return
  7314. //}
  7315. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7316. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7317. c.ServeSuccessJSON(map[string]interface{}{
  7318. "list": list,
  7319. })
  7320. return
  7321. } else {
  7322. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7323. c.ServeSuccessJSON(map[string]interface{}{
  7324. "list": list,
  7325. })
  7326. }
  7327. return
  7328. }
  7329. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7330. dataBody := make(map[string]interface{}, 0)
  7331. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7332. ids := c.GetString("ids")
  7333. idArray := strings.Split(ids, ",")
  7334. origin, _ := c.GetInt64("origin")
  7335. if origin == 1 {
  7336. err = service.BatchDeleteAdvice(idArray)
  7337. fmt.Print("err", err)
  7338. c.ServeSuccessJSON(map[string]interface{}{
  7339. "msg": "批量删除成功",
  7340. })
  7341. return
  7342. }
  7343. if origin == 2 {
  7344. service.BatchDeleteHisAdvice(idArray)
  7345. }
  7346. }
  7347. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7348. good_id, _ := c.GetInt64("good_id")
  7349. count, _ := c.GetInt64("count")
  7350. record_time, _ := c.GetInt64("record_time")
  7351. patient_id, _ := c.GetInt64("patient_id")
  7352. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7353. c.ServeSuccessJSON(map[string]interface{}{
  7354. "detail": detail,
  7355. })
  7356. return
  7357. }
  7358. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7359. good_id, _ := c.GetInt64("good_id")
  7360. record_time, _ := c.GetInt64("record_time")
  7361. patient_id, _ := c.GetInt64("patient_id")
  7362. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7363. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7364. fmt.Print("err", err)
  7365. c.ServeSuccessJSON(map[string]interface{}{
  7366. "msg": "批量删除成功",
  7367. })
  7368. return
  7369. }
  7370. func (c *DialysisAPIController) BatchAdviceCheck() {
  7371. ids := c.GetString("ids")
  7372. idArray := strings.Split(ids, ",")
  7373. creator, _ := c.GetInt64("creator")
  7374. origin, _ := c.GetInt64("origin")
  7375. if origin == 1 {
  7376. err := service.BatchAdviceCheck(idArray, creator)
  7377. fmt.Println(err)
  7378. list, _ := service.GetAdviceExecutionById(idArray)
  7379. c.ServeSuccessJSON(map[string]interface{}{
  7380. "list": list,
  7381. })
  7382. return
  7383. }
  7384. if origin == 2 {
  7385. service.BatchHisAdviceCheck(idArray, creator)
  7386. list, _ := service.GetHisAdviceExecutionById(idArray)
  7387. c.ServeSuccessJSON(map[string]interface{}{
  7388. "list": list,
  7389. })
  7390. return
  7391. }
  7392. }
  7393. func (c *DialysisAPIController) BatchAdviceExecution() {
  7394. ids := c.GetString("ids")
  7395. idArray := strings.Split(ids, ",")
  7396. executionTime := c.GetString("execution_time")
  7397. creator, _ := c.GetInt64("creator")
  7398. timeLayout := "2006-01-02 15:04:05"
  7399. loc, _ := time.LoadLocation("Local")
  7400. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7401. orgin, _ := c.GetInt64("origin")
  7402. if orgin == 1 {
  7403. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7404. list, _ := service.GetAdviceExecutionById(idArray)
  7405. fmt.Println(err)
  7406. c.ServeSuccessJSON(map[string]interface{}{
  7407. "list": list,
  7408. })
  7409. return
  7410. }
  7411. if orgin == 2 {
  7412. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7413. list, _ := service.GetHisAdviceExecutionById(idArray)
  7414. fmt.Println(err)
  7415. c.ServeSuccessJSON(map[string]interface{}{
  7416. "list": list,
  7417. })
  7418. return
  7419. }
  7420. }
  7421. func (c *DialysisAPIController) UpdateStockGoods() {
  7422. good_id, _ := c.GetInt64("good_id")
  7423. record_time, _ := c.GetInt64("record_time")
  7424. patient_id, _ := c.GetInt64("patient_id")
  7425. count, _ := c.GetInt64("count")
  7426. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7427. fmt.Print("err", err)
  7428. c.ServeSuccessJSON(map[string]interface{}{
  7429. "msg": "更新成功",
  7430. })
  7431. return
  7432. }
  7433. // 当前数据比上一次出库数据少
  7434. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7435. //查询该患者当天已经出库的耗材信息
  7436. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7437. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7438. for i := len(goods_yc) - 1; i >= 0; i-- {
  7439. goods_yc_temp := goods_yc[i]
  7440. for j := len(goods) - 1; j >= 0; j-- {
  7441. goods_temp := goods[j]
  7442. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7443. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7444. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7445. if goods_yc_temp.Count == goods_temp.Count {
  7446. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7447. goods = append(goods[:j], goods[j+1:]...)
  7448. break
  7449. }
  7450. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7451. if goods_yc_temp.Count > goods_temp.Count {
  7452. temp_count := goods_yc_temp.Count - goods_temp.Count
  7453. goods_yc[i].Count = temp_count
  7454. goods = append(goods[:j], goods[j+1:]...)
  7455. break
  7456. }
  7457. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7458. if goods_yc_temp.Count < goods_temp.Count {
  7459. temp_count := goods_temp.Count - goods_yc_temp.Count
  7460. goods[j].Count = temp_count
  7461. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7462. break
  7463. }
  7464. }
  7465. }
  7466. }
  7467. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7468. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7469. //退库
  7470. if len(goods_yc) > 0 {
  7471. for _, good_yc := range goods_yc {
  7472. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7473. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7474. }
  7475. }
  7476. return nil
  7477. }
  7478. // 耗材出库删除
  7479. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7480. // 先根据相关信息查询当天该耗材的出库信息
  7481. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7482. if err != nil {
  7483. return err
  7484. }
  7485. var delete_count int64 = 0
  7486. delete_count = warehouseOutInfos.Count - count
  7487. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7488. // 在出库记录表里记录退库详情
  7489. warehouseOutInfo := &models.WarehouseOutInfo{
  7490. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7491. WarehouseOutId: warehouseOut.ID,
  7492. Status: 1,
  7493. Ctime: time.Now().Unix(),
  7494. OrgId: orgID,
  7495. Type: 1,
  7496. IsSys: 1,
  7497. SysRecordTime: record_time,
  7498. GoodTypeId: good_yc.GoodTypeId,
  7499. GoodId: good_yc.GoodId,
  7500. PatientId: good_yc.PatientId,
  7501. ConsumableType: 2,
  7502. StorehouseId: houseConfig.StorehouseOutInfo,
  7503. IsCheck: 1,
  7504. }
  7505. warehouseOutInfo.Count = count
  7506. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7507. warehouseOutInfo.Price = stockInInfo.Price
  7508. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7509. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7510. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7511. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7512. warehouseOutInfo.Number = warehouseOutInfos.Number
  7513. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7514. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7515. //查找当天是否存在出库记录
  7516. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7517. if errcod == gorm.ErrRecordNotFound {
  7518. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7519. //插入详情明细表
  7520. stockFlow := models.VmStockFlow{
  7521. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7522. WarehouseOutId: warehouseOut.ID,
  7523. GoodId: good_yc.GoodId,
  7524. Number: warehouseOutInfos.Number,
  7525. ProductDate: stockInInfo.ProductDate,
  7526. ExpireDate: stockInInfo.ExpiryDate,
  7527. Count: count,
  7528. Price: stockInInfo.Price,
  7529. Status: 1,
  7530. Ctime: time.Now().Unix(),
  7531. UserOrgId: good_yc.OrgId,
  7532. Manufacturer: stockInInfo.Manufacturer,
  7533. Dealer: stockInInfo.Dealer,
  7534. LicenseNumber: stockInInfo.LicenseNumber,
  7535. IsEdit: 2,
  7536. Creator: creater,
  7537. SystemTime: record_time,
  7538. ConsumableType: 3,
  7539. WarehousingDetailId: 0,
  7540. IsSys: 1,
  7541. UpdateCreator: creater,
  7542. PatientId: patient_id,
  7543. StorehouseId: houseConfig.StorehouseOutInfo,
  7544. }
  7545. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7546. if errflow == gorm.ErrRecordNotFound {
  7547. //创建流水表
  7548. err := service.CreateStockFlowOne(stockFlow)
  7549. fmt.Println("err", err)
  7550. } else if errflow == nil {
  7551. //插入详情明细表
  7552. stockFlow := models.VmStockFlow{
  7553. ID: exsit.ID,
  7554. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7555. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7556. WarehouseOutId: warehouseOut.ID,
  7557. GoodId: good_yc.GoodId,
  7558. Number: warehouseOutInfos.Number,
  7559. ProductDate: stockInInfo.ProductDate,
  7560. ExpireDate: stockInInfo.ExpiryDate,
  7561. Count: exsit.Count - delete_count,
  7562. Price: stockInInfo.Price,
  7563. Status: 1,
  7564. Ctime: time.Now().Unix(),
  7565. UserOrgId: good_yc.OrgId,
  7566. Manufacturer: stockInInfo.Manufacturer,
  7567. Dealer: stockInInfo.Dealer,
  7568. LicenseNumber: stockInInfo.LicenseNumber,
  7569. IsEdit: 2,
  7570. Creator: creater,
  7571. SystemTime: record_time,
  7572. ConsumableType: 3,
  7573. WarehousingDetailId: 0,
  7574. IsSys: 1,
  7575. UpdateCreator: creater,
  7576. PatientId: patient_id,
  7577. StorehouseId: houseConfig.StorehouseOutInfo,
  7578. }
  7579. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7580. }
  7581. if errOne != nil {
  7582. return errOne
  7583. }
  7584. } else if errcod == nil {
  7585. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7586. //插入详情明细表
  7587. stockFlow := models.VmStockFlow{
  7588. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7589. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7590. WarehouseOutId: warehouseOut.ID,
  7591. GoodId: good_yc.GoodId,
  7592. Number: warehouseOutInfos.Number,
  7593. ProductDate: stockInInfo.ProductDate,
  7594. ExpireDate: stockInInfo.ExpiryDate,
  7595. Count: count,
  7596. Price: stockInInfo.Price,
  7597. Status: 1,
  7598. Ctime: time.Now().Unix(),
  7599. UserOrgId: good_yc.OrgId,
  7600. Manufacturer: stockInInfo.Manufacturer,
  7601. Dealer: stockInInfo.Dealer,
  7602. LicenseNumber: stockInInfo.LicenseNumber,
  7603. IsEdit: 2,
  7604. Creator: creater,
  7605. SystemTime: record_time,
  7606. ConsumableType: 3,
  7607. WarehousingDetailId: 0,
  7608. IsSys: 1,
  7609. UpdateCreator: creater,
  7610. PatientId: patient_id,
  7611. ReturnCount: delete_count,
  7612. StorehouseId: houseConfig.StorehouseOutInfo,
  7613. }
  7614. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7615. if errflows == gorm.ErrRecordNotFound {
  7616. //创建流水表
  7617. service.CreateStockFlowOne(stockFlow)
  7618. } else if errflows == nil {
  7619. stockFlow := models.VmStockFlow{
  7620. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7621. ID: exsit.ID,
  7622. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7623. WarehouseOutId: warehouseOut.ID,
  7624. GoodId: good_yc.GoodId,
  7625. Number: warehouseOutInfos.Number,
  7626. ProductDate: stockInInfo.ProductDate,
  7627. ExpireDate: stockInInfo.ExpiryDate,
  7628. Count: exsit.Count - delete_count,
  7629. Price: stockInInfo.Price,
  7630. Status: 1,
  7631. Ctime: time.Now().Unix(),
  7632. UserOrgId: good_yc.OrgId,
  7633. Manufacturer: stockInInfo.Manufacturer,
  7634. Dealer: stockInInfo.Dealer,
  7635. LicenseNumber: stockInInfo.LicenseNumber,
  7636. IsEdit: 2,
  7637. Creator: creater,
  7638. SystemTime: record_time,
  7639. ConsumableType: 3,
  7640. WarehousingDetailId: 0,
  7641. IsSys: 1,
  7642. UpdateCreator: creater,
  7643. PatientId: patient_id,
  7644. ReturnCount: delete_count,
  7645. StorehouseId: houseConfig.StorehouseOutInfo,
  7646. }
  7647. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7648. }
  7649. }
  7650. //更改自动出库的表格
  7651. details := models.BloodAutomaticReduceDetail{
  7652. WarehouseOutId: warehouseOutInfo.ID,
  7653. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7654. PatientId: patient_id,
  7655. Ctime: time.Now().Unix(),
  7656. Mtime: time.Now().Unix(),
  7657. Status: 1,
  7658. RecordTime: record_time,
  7659. OrgId: orgID,
  7660. GoodId: good_yc.GoodId,
  7661. GoodTypeId: good_yc.GoodTypeId,
  7662. Count: count,
  7663. StorehouseId: houseConfig.StorehouseOutInfo,
  7664. }
  7665. //查询当天耗材是否已经存在数据
  7666. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7667. if errcode == gorm.ErrRecordNotFound {
  7668. errTwo := service.CreateAutoReduceRecord(&details)
  7669. if errTwo != nil {
  7670. return errTwo
  7671. }
  7672. } else if errcode == nil {
  7673. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7674. service.CreateAutoReduceRecord(&details)
  7675. }
  7676. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7677. //增加出库库存数量
  7678. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7679. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7680. fmt.Println("errOne", errOne)
  7681. // 删除出库完成后,要增加对应批次的库存数量
  7682. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7683. if errThree != nil {
  7684. return errThree
  7685. }
  7686. if good_yc.Count == 0 {
  7687. return nil
  7688. } else {
  7689. return errors.New("退库和出库数据不匹配")
  7690. }
  7691. }
  7692. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7693. //查询该患者当天已经出库的耗材信息
  7694. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7695. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7696. for i := len(goods_yc) - 1; i >= 0; i-- {
  7697. goods_yc_temp := goods_yc[i]
  7698. for j := len(goods) - 1; j >= 0; j-- {
  7699. goods_temp := goods[j]
  7700. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7701. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7702. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7703. if goods_yc_temp.Count == goods_temp.Count {
  7704. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7705. goods = append(goods[:j], goods[j+1:]...)
  7706. break
  7707. }
  7708. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7709. if goods_yc_temp.Count > goods_temp.Count {
  7710. temp_count := goods_yc_temp.Count - goods_temp.Count
  7711. goods_yc[i].Count = temp_count
  7712. goods = append(goods[:j], goods[j+1:]...)
  7713. break
  7714. }
  7715. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7716. if goods_yc_temp.Count < goods_temp.Count {
  7717. temp_count := goods_temp.Count - goods_yc_temp.Count
  7718. goods[j].Count = temp_count
  7719. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7720. break
  7721. }
  7722. }
  7723. }
  7724. }
  7725. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7726. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7727. fmt.Println("剩余需要出库的", len(goods))
  7728. if len(goods) > 0 {
  7729. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7730. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7731. if err == gorm.ErrRecordNotFound {
  7732. //没有记录,则创建出库单
  7733. timeStr := time.Now().Format("2006-01-02")
  7734. timeArr := strings.Split(timeStr, "-")
  7735. total, _ := service.FindAllWarehouseOut(orgID)
  7736. total = total + 1
  7737. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7738. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7739. number = number + total
  7740. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7741. warehouseOut := models.WarehouseOut{
  7742. WarehouseOutOrderNumber: warehousing_out_order,
  7743. OperationTime: time.Now().Unix(),
  7744. OrgId: orgID,
  7745. Creater: creater,
  7746. Ctime: time.Now().Unix(),
  7747. Status: 1,
  7748. WarehouseOutTime: record_time,
  7749. Dealer: 0,
  7750. Manufacturer: 0,
  7751. Type: 1,
  7752. IsSys: 1,
  7753. StorehouseId: houseConfig.StorehouseOutInfo,
  7754. IsCheck: 1,
  7755. }
  7756. err := service.AddSigleWarehouseOut(&warehouseOut)
  7757. if err != nil {
  7758. utils.TraceLog("创建出库单失败 err = %v", err)
  7759. return err
  7760. } else {
  7761. out = warehouseOut
  7762. }
  7763. }
  7764. for _, item := range goods {
  7765. var newCount int64 = 0
  7766. for _, it := range goodOne {
  7767. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7768. newCount = it.Count
  7769. }
  7770. }
  7771. prepare := models.DialysisBeforePrepare{
  7772. GoodTypeId: item.GoodTypeId,
  7773. GoodId: item.GoodId,
  7774. Count: item.Count,
  7775. StorehouseId: houseConfig.StorehouseOutInfo,
  7776. }
  7777. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7778. //增加出库数量
  7779. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7780. }
  7781. }
  7782. if len(goods_yc) > 0 {
  7783. for _, good_yc := range goods_yc {
  7784. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7785. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7786. }
  7787. }
  7788. return nil
  7789. }
  7790. // 耗材出库删除
  7791. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7792. // 先根据相关信息查询当天该耗材的出库信息
  7793. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7794. if err != nil {
  7795. return err
  7796. }
  7797. var delete_count int64 = 0
  7798. for _, ware := range warehouseOutInfos {
  7799. // 判断当前出库的数据和删除出库数量
  7800. if good_yc.Count <= ware.Count {
  7801. delete_count = good_yc.Count
  7802. } else {
  7803. delete_count = ware.Count
  7804. }
  7805. warehouseOutInfo := &models.WarehouseOutInfo{
  7806. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7807. WarehouseOutId: warehouseOut.ID,
  7808. Status: 1,
  7809. Ctime: time.Now().Unix(),
  7810. Remark: "",
  7811. OrgId: orgID,
  7812. Type: 1,
  7813. Manufacturer: 0,
  7814. Dealer: 0,
  7815. IsSys: 0,
  7816. SysRecordTime: record_time,
  7817. GoodTypeId: good_yc.GoodTypeId,
  7818. GoodId: good_yc.GoodId,
  7819. StorehouseId: warehouseOut.StorehouseId,
  7820. IsCheck: 1,
  7821. }
  7822. warehouseOutInfo.Count = delete_count
  7823. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7824. warehouseOutInfo.Price = stockInInfo.Price
  7825. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7826. if errOne != nil {
  7827. return errOne
  7828. }
  7829. // 删除出库完成后,要改变流水库存(有疑问)
  7830. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7831. fmt.Println("errOne", errOne)
  7832. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7833. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7834. //扣减出库数量
  7835. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7836. if errThree != nil {
  7837. return errThree
  7838. }
  7839. }
  7840. if good_yc.Count == 0 {
  7841. return nil
  7842. } else {
  7843. return errors.New("退库和出库数据不匹配")
  7844. }
  7845. }
  7846. func (this *DialysisAPIController) GetMobileScheduleList() {
  7847. limit, _ := this.GetInt64("limit")
  7848. page, _ := this.GetInt64("page")
  7849. type_options_visible, _ := this.GetInt64("type_options_visible")
  7850. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7851. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7852. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7853. }
  7854. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7855. newArr = make([]*models.HisPrescriptionProject, 0)
  7856. for i := 0; i < len(arr); i++ {
  7857. repeat := false
  7858. for j := i + 1; j < len(arr); j++ {
  7859. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  7860. repeat = true
  7861. break
  7862. }
  7863. }
  7864. if !repeat {
  7865. newArr = append(newArr, arr[i])
  7866. }
  7867. }
  7868. return
  7869. }
  7870. func (this *DialysisAPIController) GetRoleList() {
  7871. admin_user_id, _ := this.GetInt64("admin_user_id")
  7872. orgid := this.GetMobileAdminUserInfo().Org.Id
  7873. list, err := service.GetRoleList(orgid, admin_user_id)
  7874. fmt.Println(err)
  7875. this.ServeSuccessJSON(map[string]interface{}{
  7876. "list": list,
  7877. })
  7878. return
  7879. }
  7880. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7881. // 先根据相关信息查询当天该耗材的出库信息
  7882. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7883. if err != nil {
  7884. return err
  7885. }
  7886. var delete_count int64 = 0
  7887. delete_count = warehouseOutInfos.Count - count
  7888. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7889. // 删除出库完成后,要增加对应批次的库存数量
  7890. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7891. if errThree != nil {
  7892. return errThree
  7893. }
  7894. //增加退库数量
  7895. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7896. //扣减出库数量
  7897. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7898. //查询剩余库存
  7899. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7900. var sum_count int64
  7901. for _, item := range goodList {
  7902. sum_count += item.StockCount
  7903. }
  7904. // 在出库记录表里记录退库详情
  7905. warehouseOutInfo := &models.WarehouseOutInfo{
  7906. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7907. WarehouseOutId: warehouseOut.ID,
  7908. Status: 1,
  7909. Ctime: time.Now().Unix(),
  7910. OrgId: orgID,
  7911. Type: 1,
  7912. IsSys: 1,
  7913. SysRecordTime: record_time,
  7914. GoodTypeId: good_yc.GoodTypeId,
  7915. GoodId: good_yc.GoodId,
  7916. PatientId: good_yc.PatientId,
  7917. ConsumableType: 2,
  7918. StorehouseId: houseConfig.StorehouseOutInfo,
  7919. IsCheck: 1,
  7920. OverCount: sum_count,
  7921. }
  7922. warehouseOutInfo.Count = count
  7923. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7924. warehouseOutInfo.Price = stockInInfo.Price
  7925. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7926. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7927. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7928. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7929. warehouseOutInfo.Number = warehouseOutInfos.Number
  7930. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7931. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7932. //查找当天是否存在出库记录
  7933. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7934. if errcod == gorm.ErrRecordNotFound {
  7935. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7936. //插入详情明细表
  7937. if errOne != nil {
  7938. return errOne
  7939. }
  7940. //插入详情明细表
  7941. stockFlow := models.VmStockFlow{
  7942. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7943. WarehouseOutId: warehouseOut.ID,
  7944. GoodId: good_yc.GoodId,
  7945. Number: warehouseOutInfos.Number,
  7946. ProductDate: stockInInfo.ProductDate,
  7947. ExpireDate: stockInInfo.ExpiryDate,
  7948. Count: count,
  7949. Price: stockInInfo.Price,
  7950. Status: 1,
  7951. Ctime: record_time,
  7952. UserOrgId: good_yc.OrgId,
  7953. Manufacturer: stockInInfo.Manufacturer,
  7954. Dealer: stockInInfo.Dealer,
  7955. LicenseNumber: stockInInfo.LicenseNumber,
  7956. IsEdit: 2,
  7957. Creator: creater,
  7958. SystemTime: record_time,
  7959. ConsumableType: 3,
  7960. WarehousingDetailId: 0,
  7961. IsSys: 1,
  7962. UpdateCreator: creater,
  7963. PatientId: patient_id,
  7964. StorehouseId: houseConfig.StorehouseOutInfo,
  7965. OverCount: sum_count,
  7966. ProjectId: good_yc.ProjectId,
  7967. }
  7968. err := service.CreateStockFlowOne(stockFlow)
  7969. fmt.Println("err", err)
  7970. } else if errcod == nil {
  7971. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7972. }
  7973. //创建退库单
  7974. operation_time := time.Now().Unix()
  7975. //创建退库单
  7976. timeStr := time.Now().Format("2006-01-02")
  7977. timeArr := strings.Split(timeStr, "-")
  7978. total, _ := service.FindAllCancelStockTotal(orgID)
  7979. total = total + 1
  7980. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7981. cancelStock := models.CancelStock{
  7982. OrderNumber: orderNumber,
  7983. OperaTime: operation_time,
  7984. OrgId: orgID,
  7985. Creater: warehouseOut.Creater,
  7986. Ctime: time.Now().Unix(),
  7987. Status: 1,
  7988. ReturnTime: record_time,
  7989. Type: 1,
  7990. StorehouseId: stockInInfo.StorehouseId,
  7991. IsCheck: 1,
  7992. }
  7993. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7994. if msgerrkonde == gorm.ErrRecordNotFound {
  7995. service.AddSigleCancelStock(&cancelStock)
  7996. }
  7997. cancel, _ := service.GetLastCancelStockById(orgID)
  7998. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7999. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8000. cancelStockInfo := models.CancelStockInfo{
  8001. GoodId: stockInInfo.GoodId,
  8002. CancelStockId: cancel.ID,
  8003. GoodTypeId: stockInInfo.GoodTypeId,
  8004. Count: delete_count,
  8005. Price: stockInInfo.PackingPrice,
  8006. Total: 0,
  8007. ProductDate: stockInInfo.ProductDate,
  8008. ExpiryDate: stockInInfo.ExpiryDate,
  8009. Ctime: record_time,
  8010. Status: 1,
  8011. OrgId: orgID,
  8012. OrderNumber: cancel.OrderNumber,
  8013. Type: 0,
  8014. Dealer: deaerler.DealerName,
  8015. Manufacturer: manufacturer.ManufacturerName,
  8016. Number: stockInInfo.Number,
  8017. RegisterAccount: "",
  8018. Remark: "",
  8019. WarehouseInfoId: stockInInfo.ID,
  8020. PatientId: patient_id,
  8021. RecordDate: record_time,
  8022. StorehouseId: stockInInfo.StorehouseId,
  8023. IsCheck: 1,
  8024. }
  8025. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8026. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8027. flow := models.VmStockFlow{
  8028. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8029. GoodId: good_yc.GoodId,
  8030. Number: warehouseOutInfos.Number,
  8031. LicenseNumber: stockInInfo.LicenseNumber,
  8032. Count: delete_count,
  8033. UserOrgId: orgID,
  8034. PatientId: patient_id,
  8035. SystemTime: record_time,
  8036. ConsumableType: 7,
  8037. IsSys: 0,
  8038. WarehousingOrder: "",
  8039. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8040. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8041. IsEdit: 0,
  8042. CancelStockId: cancel.ID,
  8043. CancelOrderNumber: cancel.OrderNumber,
  8044. Manufacturer: manufacturer.ID,
  8045. Dealer: 0,
  8046. Creator: warehouseOut.Creater,
  8047. UpdateCreator: 0,
  8048. Status: 1,
  8049. Ctime: record_time,
  8050. Mtime: 0,
  8051. Price: stockInInfo.Price,
  8052. WarehousingDetailId: stockInInfo.ID,
  8053. WarehouseOutDetailId: warehouseOutInfos.ID,
  8054. CancelOutDetailId: cancelInfo.ID,
  8055. ProductDate: stockInInfo.ProductDate,
  8056. ExpireDate: stockInInfo.ExpiryDate,
  8057. StorehouseId: houseConfig.StorehouseOutInfo,
  8058. OverCount: sum_count,
  8059. }
  8060. service.CreateStockFlowOne(flow)
  8061. //更改自动出库的表格
  8062. details := models.BloodAutomaticReduceDetail{
  8063. WarehouseOutId: warehouseOutInfo.ID,
  8064. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8065. PatientId: patient_id,
  8066. Ctime: time.Now().Unix(),
  8067. Mtime: time.Now().Unix(),
  8068. Status: 1,
  8069. RecordTime: record_time,
  8070. OrgId: orgID,
  8071. GoodId: good_yc.GoodId,
  8072. GoodTypeId: good_yc.GoodTypeId,
  8073. Count: count,
  8074. StorehouseId: houseConfig.StorehouseOutInfo,
  8075. }
  8076. //查询当天耗材是否已经存在数据
  8077. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8078. if errcode == gorm.ErrRecordNotFound {
  8079. errTwo := service.CreateAutoReduceRecord(&details)
  8080. if errTwo != nil {
  8081. return errTwo
  8082. }
  8083. } else if errcode == nil {
  8084. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8085. service.CreateAutoReduceRecord(&details)
  8086. }
  8087. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8088. //增加出库库存数量
  8089. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8090. if good_yc.Count == 0 {
  8091. return nil
  8092. } else {
  8093. return errors.New("退库和出库数据不匹配")
  8094. }
  8095. }
  8096. func (this *DialysisAPIController) SavePatientSign() {
  8097. adminUserInfo := this.GetMobileAdminUserInfo()
  8098. patient_id, _ := this.GetInt64("patient_id")
  8099. dialysis_date, _ := this.GetInt64("dialysis_date")
  8100. orgid := adminUserInfo.Org.Id
  8101. var esdata models.DialysisOrder
  8102. var err error
  8103. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8105. return
  8106. }
  8107. esdata.Hash = esdata.Hash
  8108. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8109. order := models.DialysisOrder{
  8110. Hash: esdata.Hash,
  8111. Url: esdata.Url,
  8112. }
  8113. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8114. redis := service.RedisClient()
  8115. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8116. redis.Set(key, "", time.Second)
  8117. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8118. //清空key 值
  8119. redis.Set(keyOne, "", time.Second)
  8120. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8121. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8122. //redis.Set(keyTwo, "", time.Second)
  8123. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8124. redis.Set(keyThree, "", time.Second)
  8125. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8126. redis.Set(keyFour, "", time.Second)
  8127. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8128. redis.Set(keyFive, "", time.Second)
  8129. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8130. redis.Set(keySix, "", time.Second)
  8131. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8132. redis.Set(keySeven, "", time.Second)
  8133. if err != nil {
  8134. fmt.Println(err)
  8135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8136. return
  8137. }
  8138. this.ServeSuccessJSON(map[string]interface{}{
  8139. "electronic_signature": esdata,
  8140. })
  8141. }
  8142. func (this *DialysisAPIController) GetPatientSign() {
  8143. patient_id, _ := this.GetInt64("patient_id")
  8144. dialysis_date, _ := this.GetInt64("dialysis_date")
  8145. adminUserInfo := this.GetMobileAdminUserInfo()
  8146. orgId := adminUserInfo.Org.Id
  8147. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8148. if err != nil {
  8149. fmt.Println(err)
  8150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8151. return
  8152. }
  8153. this.ServeSuccessJSON(map[string]interface{}{
  8154. "dialysisOrder": dialysisOrder,
  8155. })
  8156. }
  8157. func (this *DialysisAPIController) GetScheduleByPatient() {
  8158. patient_id, _ := this.GetInt64("patient_id")
  8159. schedule_date, _ := this.GetInt64("schedule_date")
  8160. orgid := this.GetMobileAdminUserInfo().Org.Id
  8161. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8162. this.ServeSuccessJSON(map[string]interface{}{
  8163. "schedule": schedule,
  8164. })
  8165. }
  8166. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8167. org_id := this.GetMobileAdminUserInfo().Org.Id
  8168. patient_id, _ := this.GetInt64("patient_id")
  8169. schedule_date, _ := this.GetInt64("schedule_date")
  8170. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8171. this.ServeSuccessJSON(map[string]interface{}{
  8172. "order": order,
  8173. })
  8174. }
  8175. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8176. org_id := this.GetMobileAdminUserInfo().Org.Id
  8177. schedule_date := this.GetString("schedule_date")
  8178. schedule_type, _ := this.GetInt64("schedule_type")
  8179. timeLayout := "2006-01-02"
  8180. loc, _ := time.LoadLocation("Local")
  8181. var startdateunix int64
  8182. if len(schedule_date) > 0 {
  8183. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8184. if err != nil {
  8185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8186. return
  8187. }
  8188. startdateunix = theTime.Unix()
  8189. }
  8190. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8191. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8192. devices, _ := service.GetAllDevicetByListSix(org_id)
  8193. for key, item := range scheduals {
  8194. // 床位信息
  8195. for _, device := range devices {
  8196. if item.BedId == device.ID {
  8197. scheduals[key].DeviceNumber = device
  8198. break
  8199. }
  8200. }
  8201. }
  8202. this.ServeSuccessJSON(map[string]interface{}{
  8203. "list": list,
  8204. "scheduals": scheduals,
  8205. })
  8206. }
  8207. func (this *DialysisAPIController) SavePatientPicture() {
  8208. patient_id, _ := this.GetInt64("patient_id")
  8209. dialysis_date, _ := this.GetInt64("schedule_date")
  8210. avatar := this.GetString("avatar")
  8211. fmt.Println("patient_id", patient_id)
  8212. orgId := this.GetMobileAdminUserInfo().Org.Id
  8213. order := models.DialysisOrder{
  8214. Url: avatar,
  8215. }
  8216. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8217. redis := service.RedisClient()
  8218. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8219. redis.Set(key, "", time.Second)
  8220. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8221. //清空key 值
  8222. redis.Set(keyOne, "", time.Second)
  8223. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8224. redis.Set(keyThree, "", time.Second)
  8225. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8226. redis.Set(keyFour, "", time.Second)
  8227. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8228. redis.Set(keyFive, "", time.Second)
  8229. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8230. redis.Set(keySix, "", time.Second)
  8231. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8232. redis.Set(keySeven, "", time.Second)
  8233. if err != nil {
  8234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8235. return
  8236. }
  8237. this.ServeSuccessJSON(map[string]interface{}{
  8238. "order": order,
  8239. })
  8240. }
  8241. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8242. ids := this.GetString("ids")
  8243. idSplit := strings.Split(ids, ",")
  8244. orgId := this.GetMobileAdminUserInfo().Org.Id
  8245. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8246. execution_time := this.GetString("exce_time")
  8247. timeLayout2 := "2006-01-02 15:04:05"
  8248. loc, _ := time.LoadLocation("Local")
  8249. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8250. if errs != nil {
  8251. utils.ErrorLog(errs.Error())
  8252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8253. return
  8254. }
  8255. //his客户
  8256. if config.IsOpen == 1 {
  8257. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8258. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8259. for _, item := range list {
  8260. for _, it := range adviceList {
  8261. if item.DrugId == it.DrugId {
  8262. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8263. }
  8264. }
  8265. }
  8266. for _, item := range list {
  8267. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8268. var sum_out_count int64
  8269. for _, itemThree := range item.ChildDoctorAdvice {
  8270. var prescribing_number int64
  8271. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8272. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8273. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8274. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8275. }
  8276. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8277. prescribing_number = parseIntPrescribingNumber
  8278. }
  8279. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8280. prescribing_number = parseIntPrescribingNumber
  8281. }
  8282. sum_out_count += prescribing_number
  8283. }
  8284. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8285. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8286. //库存不足
  8287. if sum_out_count > drugStockOut.FlushCount {
  8288. this.ServeSuccessJSON(map[string]interface{}{
  8289. "msg": "2",
  8290. "drug": medical,
  8291. "ids": ids,
  8292. })
  8293. return
  8294. }
  8295. }
  8296. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8297. //执行医嘱
  8298. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8299. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8300. for _, item := range advices {
  8301. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8302. redis := service.RedisClient()
  8303. //清空key 值
  8304. redis.Set(key, "", time.Second)
  8305. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8306. redis.Set(keyTwo, "", time.Second)
  8307. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8308. redis.Set(keyThree, "", time.Second)
  8309. recordDate := theTime.Format("2006-01-02")
  8310. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8311. redis.Set(keyFour, "", time.Second)
  8312. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8313. redis.Set(keyFive, "", time.Second)
  8314. defer redis.Close()
  8315. }
  8316. if errs == nil {
  8317. //药品管理信息
  8318. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8319. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8320. if drugStockConfig.IsOpen == 1 {
  8321. for _, item := range advices {
  8322. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8323. config, _ := service.GetDrugOpenConfigOne(orgId)
  8324. if config.IsOpen != 1 {
  8325. //查询该药品是否有库存
  8326. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8327. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8328. if medical.IsUse == 2 {
  8329. if config.IsOpen != 1 {
  8330. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8331. service.HisDrugsDelivery(orgId, creater, &advice)
  8332. if orgId == 3877 || orgId == 10265 {
  8333. //查询该药品是否有出库记录
  8334. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8335. if len(flowMap) == 0 {
  8336. errs := service.UpdateHisAdviceById(advice.ID)
  8337. if errs != nil {
  8338. drugError := models.XtDrugError{
  8339. UserOrgId: orgId,
  8340. DrugId: item.DrugId,
  8341. RecordDate: item.AdviceDate,
  8342. PatientId: item.PatientId,
  8343. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8344. Status: 1,
  8345. Ctime: time.Now().Unix(),
  8346. Mtime: 0,
  8347. SumCount: 0,
  8348. Prescribingnumber: advice.PrescribingNumber,
  8349. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8350. }
  8351. service.CreateDrugError(drugError)
  8352. }
  8353. this.ServeSuccessJSON(map[string]interface{}{
  8354. "msg": "2",
  8355. "drug": medical,
  8356. "ids": ids,
  8357. })
  8358. return
  8359. }
  8360. }
  8361. }
  8362. if pharmacyConfig.IsOpen != 1 {
  8363. service.HisDrugsDelivery(orgId, creater, &advice)
  8364. if orgId == 3877 || orgId == 10265 {
  8365. //查询该药品是否有出库记录
  8366. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8367. if len(flowMap) == 0 {
  8368. errs := service.UpdateHisAdviceById(advice.ID)
  8369. if errs != nil {
  8370. drugError := models.XtDrugError{
  8371. UserOrgId: orgId,
  8372. DrugId: item.DrugId,
  8373. RecordDate: item.AdviceDate,
  8374. PatientId: item.PatientId,
  8375. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8376. Status: 1,
  8377. Ctime: time.Now().Unix(),
  8378. Mtime: 0,
  8379. SumCount: 0,
  8380. Prescribingnumber: advice.PrescribingNumber,
  8381. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8382. }
  8383. service.CreateDrugError(drugError)
  8384. }
  8385. this.ServeSuccessJSON(map[string]interface{}{
  8386. "msg": "2",
  8387. "drug": medical,
  8388. "ids": ids,
  8389. })
  8390. return
  8391. }
  8392. }
  8393. }
  8394. //更新字典里面的库存
  8395. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8396. var sum_count int64
  8397. for _, its := range stockInfo {
  8398. if its.MaxUnit == medical.MaxUnit {
  8399. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8400. }
  8401. sum_count += its.StockMaxNumber + its.StockMinNumber
  8402. }
  8403. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8404. //剩余库存
  8405. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8406. }
  8407. }
  8408. }
  8409. }
  8410. }
  8411. this.ServeSuccessJSON(map[string]interface{}{
  8412. "msg": "1",
  8413. "ids": ids,
  8414. })
  8415. return
  8416. } else {
  8417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8418. }
  8419. }
  8420. //血透客户
  8421. if config.IsOpen == 2 || config.IsOpen == 0 {
  8422. //药品管理信息
  8423. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8424. if drugStockConfig.IsOpen == 1 {
  8425. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8426. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8427. for _, item := range list {
  8428. for _, it := range adviceList {
  8429. if item.DrugId == it.DrugId {
  8430. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8431. }
  8432. }
  8433. }
  8434. for _, item := range list {
  8435. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8436. var sum_out_count int64
  8437. for _, itemThree := range item.ChildDoctorAdvice {
  8438. var prescribing_number int64
  8439. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8440. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8441. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8442. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8443. }
  8444. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8445. prescribing_number = parseIntPrescribingNumber
  8446. }
  8447. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8448. prescribing_number = parseIntPrescribingNumber
  8449. }
  8450. sum_out_count += prescribing_number
  8451. }
  8452. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8453. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8454. //库存不足
  8455. if sum_out_count > drugStockOut.FlushCount {
  8456. this.ServeSuccessJSON(map[string]interface{}{
  8457. "msg": "2",
  8458. "drug": medical,
  8459. "ids": ids,
  8460. })
  8461. return
  8462. }
  8463. }
  8464. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8465. //执行医嘱
  8466. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8467. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8468. for _, item := range advices {
  8469. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8470. redis := service.RedisClient()
  8471. //清空key 值
  8472. redis.Set(key, "", time.Second)
  8473. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8474. redis.Set(keyTwo, "", time.Second)
  8475. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8476. redis.Set(keyThree, "", time.Second)
  8477. recordDate := theTime.Format("2006-01-02")
  8478. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8479. redis.Set(keyFour, "", time.Second)
  8480. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8481. redis.Set(keyFive, "", time.Second)
  8482. defer redis.Close()
  8483. }
  8484. if errs == nil {
  8485. for _, item := range advices {
  8486. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8487. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8488. //查询是否出库按钮开启
  8489. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8490. if adviceSetting.IsAdviceOpen == 1 {
  8491. //查询是否出库按钮开启
  8492. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8493. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8494. if prescriptionConfig.IsOpen == 1 {
  8495. if medical.IsUse == 2 {
  8496. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8497. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8498. }
  8499. if pharmacyConfig.IsOpen != 1 {
  8500. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8501. }
  8502. //更新字典里面的库存
  8503. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8504. var sum_count int64
  8505. for _, its := range stockInfo {
  8506. if its.MaxUnit == medical.MaxUnit {
  8507. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8508. }
  8509. sum_count += its.StockMaxNumber + its.StockMinNumber
  8510. }
  8511. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8512. //剩余库存
  8513. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8514. }
  8515. }
  8516. } else {
  8517. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8518. if medical.IsUse == 2 {
  8519. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8520. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8521. }
  8522. if pharmacyConfig.IsOpen != 1 {
  8523. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8524. }
  8525. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8526. var sum_count int64
  8527. for _, its := range stockInfo {
  8528. if its.MaxUnit == medical.MaxUnit {
  8529. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8530. }
  8531. sum_count += its.StockMaxNumber + its.StockMinNumber
  8532. }
  8533. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8534. //剩余库存
  8535. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8536. }
  8537. }
  8538. }
  8539. }
  8540. this.ServeSuccessJSON(map[string]interface{}{
  8541. "msg": "1",
  8542. "ids": ids,
  8543. })
  8544. return
  8545. } else {
  8546. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8547. //执行医嘱
  8548. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8549. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8550. for _, item := range advices {
  8551. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8552. redis := service.RedisClient()
  8553. //清空key 值
  8554. redis.Set(key, "", time.Second)
  8555. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8556. redis.Set(keyTwo, "", time.Second)
  8557. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8558. redis.Set(keyThree, "", time.Second)
  8559. recordDate := theTime.Format("2006-01-02")
  8560. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8561. redis.Set(keyFour, "", time.Second)
  8562. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8563. redis.Set(keyFive, "", time.Second)
  8564. defer redis.Close()
  8565. }
  8566. this.ServeSuccessJSON(map[string]interface{}{
  8567. "msg": "1",
  8568. "ids": ids,
  8569. })
  8570. return
  8571. }
  8572. }
  8573. }
  8574. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8575. ids := this.GetString("ids")
  8576. idSplit := strings.Split(ids, ",")
  8577. orgId := this.GetMobileAdminUserInfo().Org.Id
  8578. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8579. if config.IsOpen == 1 {
  8580. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8581. this.ServeSuccessJSON(map[string]interface{}{
  8582. "msg": "1",
  8583. "ids": ids,
  8584. })
  8585. return
  8586. }
  8587. if config.IsOpen == 0 || config.IsOpen == 2 {
  8588. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8589. this.ServeSuccessJSON(map[string]interface{}{
  8590. "msg": "1",
  8591. "ids": ids,
  8592. })
  8593. return
  8594. }
  8595. }
  8596. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8597. ids := this.GetString("ids")
  8598. idSplit := strings.Split(ids, ",")
  8599. orgId := this.GetMobileAdminUserInfo().Org.Id
  8600. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8601. //his
  8602. if config.IsOpen == 1 {
  8603. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8604. theTime := time.Now()
  8605. advices := models.HisDoctorAdviceThirty{
  8606. CheckTime: theTime.Unix(),
  8607. Checker: checker,
  8608. UpdatedTime: time.Now().Unix(),
  8609. }
  8610. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8611. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8612. for _, item := range list {
  8613. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8614. redis := service.RedisClient()
  8615. //清空key 值
  8616. redis.Set(key, "", time.Second)
  8617. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8618. redis.Set(keyTwo, "", time.Second)
  8619. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8620. redis.Set(keyThree, "", time.Second)
  8621. recordDate := theTime.Format("2006-01-02")
  8622. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8623. redis.Set(keyFour, "", time.Second)
  8624. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8625. redis.Set(keyFive, "", time.Second)
  8626. defer redis.Close()
  8627. }
  8628. this.ServeSuccessJSON(map[string]interface{}{
  8629. "msg": "1",
  8630. "ids": ids,
  8631. })
  8632. return
  8633. }
  8634. //血透
  8635. if config.IsOpen == 0 || config.IsOpen == 2 {
  8636. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8637. theTime := time.Now()
  8638. advices := models.DoctorAdvice{
  8639. CheckTime: theTime.Unix(),
  8640. Checker: checker,
  8641. UpdatedTime: time.Now().Unix(),
  8642. }
  8643. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8644. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8645. for _, item := range list {
  8646. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8647. redis := service.RedisClient()
  8648. //清空key 值
  8649. redis.Set(key, "", time.Second)
  8650. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8651. redis.Set(keyTwo, "", time.Second)
  8652. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8653. redis.Set(keyThree, "", time.Second)
  8654. recordDate := theTime.Format("2006-01-02")
  8655. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8656. redis.Set(keyFour, "", time.Second)
  8657. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8658. redis.Set(keyFive, "", time.Second)
  8659. defer redis.Close()
  8660. }
  8661. this.ServeSuccessJSON(map[string]interface{}{
  8662. "msg": "1",
  8663. "ids": ids,
  8664. })
  8665. return
  8666. }
  8667. }
  8668. func (this *DialysisAPIController) CheckSchedule() {
  8669. patientID, _ := this.GetInt64("patient_id")
  8670. recordDateStr := this.GetString("record_date")
  8671. nurseID, _ := this.GetInt64("start_nurse")
  8672. schedual_type, _ := this.GetInt64("schedual_type")
  8673. bedID, _ := this.GetInt64("bed")
  8674. start_time := this.GetString("start_time")
  8675. fmt.Println("patientID", patientID)
  8676. fmt.Println("recordDateStr", recordDateStr)
  8677. fmt.Println("nurseID", nurseID)
  8678. fmt.Println("schedual_type------", schedual_type)
  8679. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8681. return
  8682. }
  8683. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8684. if parseStartDateErr != nil {
  8685. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8687. return
  8688. }
  8689. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8690. if parseErr != nil {
  8691. this.ErrorLog("时间解析失败:%v", parseErr)
  8692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8693. return
  8694. }
  8695. adminUserInfo := this.GetMobileAdminUserInfo()
  8696. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8697. if getPatientErr != nil {
  8698. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8700. return
  8701. } else if patient == nil {
  8702. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8703. return
  8704. }
  8705. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8706. if getNurseErr != nil {
  8707. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8709. return
  8710. } else if nurse == nil {
  8711. this.ErrorLog("护士不存在")
  8712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8713. return
  8714. }
  8715. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8716. if getDeviceNumberErr != nil {
  8717. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8719. return
  8720. } else if deviceNumber == nil {
  8721. this.ErrorLog("床位号不存在")
  8722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8723. return
  8724. }
  8725. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8726. if getRecordErr != nil {
  8727. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8729. return
  8730. } else if dialysisRecord != nil {
  8731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8732. return
  8733. }
  8734. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8735. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8736. timeLayout := "2006-01-02 15:04:05"
  8737. loc, _ := time.LoadLocation("Local")
  8738. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8739. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8740. schedulestartTime := theStartTime.Unix()
  8741. scheduleendTime := theEndTime.Unix()
  8742. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8743. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8744. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8745. //查询该床位是否有人用了
  8746. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8747. if err == nil {
  8748. if schedule.ID == 0 {
  8749. this.ServeSuccessJSON(map[string]interface{}{
  8750. "status": 0,
  8751. "msg": "请求失败",
  8752. })
  8753. } else {
  8754. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8755. if order.ID > 0 { //该机位被其他人占用了
  8756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8757. return
  8758. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8759. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8760. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8761. this.ServeSuccessJSON(map[string]interface{}{
  8762. "status": 1,
  8763. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8764. })
  8765. return
  8766. } else {
  8767. this.ServeSuccessJSON(map[string]interface{}{
  8768. "status": 0,
  8769. "msg": "",
  8770. })
  8771. }
  8772. }
  8773. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8774. this.ServeSuccessJSON(map[string]interface{}{
  8775. "status": 2,
  8776. "msg": "当前机位已有患者在使用,请重新选择!",
  8777. })
  8778. }
  8779. }
  8780. } else {
  8781. this.ServeSuccessJSON(map[string]interface{}{
  8782. "status": 0,
  8783. "msg": "",
  8784. })
  8785. }
  8786. }
  8787. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8788. orgId := this.GetMobileAdminUserInfo().Org.Id
  8789. schedule_type, _ := this.GetInt64("schedule_type")
  8790. partion_type, _ := this.GetInt64("partion_type")
  8791. start_time := this.GetString("start_time")
  8792. timeLayout := "2006-01-02"
  8793. loc, _ := time.LoadLocation("Local")
  8794. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8795. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8796. _, config := service.FindXTHisRecordByOrgId(orgId)
  8797. appId := this.GetMobileAdminUserInfo().App.Id
  8798. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8799. if err == nil {
  8800. this.ServeSuccessJSON(map[string]interface{}{
  8801. "list": list,
  8802. "config": config,
  8803. "doctorList": doctorList,
  8804. })
  8805. return
  8806. } else {
  8807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8808. return
  8809. }
  8810. }
  8811. func (this *DialysisAPIController) SaveMobileInformation() {
  8812. patient_id, _ := this.GetInt64("patient_id")
  8813. record_date, _ := this.GetInt64("record_date")
  8814. startTime := this.GetString("start_time")
  8815. module, _ := this.GetInt64("module")
  8816. remark := this.GetString("remark")
  8817. timeLayout := "2006-01-02 15:04"
  8818. loc, _ := time.LoadLocation("Local")
  8819. if len(startTime) == 0 {
  8820. utils.ErrorLog("len(start_time) == 0")
  8821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8822. return
  8823. }
  8824. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8825. if err != nil {
  8826. utils.ErrorLog(err.Error())
  8827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8828. return
  8829. }
  8830. StartTime := theTime.Unix()
  8831. fmt.Println("startime-------------", StartTime)
  8832. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8833. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8834. information := models.XtDialysisInformation{
  8835. Module: module,
  8836. PatientId: patient_id,
  8837. RecordDate: record_date,
  8838. ApplicationDate: StartTime,
  8839. Creater: creater,
  8840. ApplicationStatus: 2,
  8841. Checker: 0,
  8842. CheckTime: 0,
  8843. Remark: remark,
  8844. UserOrgId: user_org_id,
  8845. Ctime: time.Now().Unix(),
  8846. Status: 1,
  8847. Mtime: 0,
  8848. }
  8849. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8850. if infor.ID == 0 {
  8851. service.SaveDialysisInformation(information)
  8852. }
  8853. if infor.ID > 0 {
  8854. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8855. }
  8856. this.ServeSuccessJSON(map[string]interface{}{
  8857. "information": information,
  8858. })
  8859. return
  8860. }
  8861. func (this *DialysisAPIController) GetMobileInformation() {
  8862. limit, _ := this.GetInt64("limit")
  8863. page, _ := this.GetInt64("page")
  8864. orgid := this.GetMobileAdminUserInfo().Org.Id
  8865. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8866. appid := this.GetMobileAdminUserInfo().App.Id
  8867. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8868. patients, _ := service.GetAllpatientThirty(orgid)
  8869. this.ServeSuccessJSON(map[string]interface{}{
  8870. "information": information,
  8871. "total": total,
  8872. "doclist": doclist,
  8873. "patients": patients,
  8874. })
  8875. return
  8876. }
  8877. func (this *DialysisAPIController) GetMobileInformationOne() {
  8878. limit, _ := this.GetInt64("limit")
  8879. page, _ := this.GetInt64("page")
  8880. orgid := this.GetMobileAdminUserInfo().Org.Id
  8881. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8882. appid := this.GetMobileAdminUserInfo().App.Id
  8883. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8884. patients, _ := service.GetAllpatientThirty(orgid)
  8885. this.ServeSuccessJSON(map[string]interface{}{
  8886. "information": information,
  8887. "total": total,
  8888. "doclist": doclist,
  8889. "patients": patients,
  8890. })
  8891. return
  8892. }
  8893. func (this *DialysisAPIController) CheckMobileInformation() {
  8894. id, _ := this.GetInt64("id")
  8895. application_status, _ := this.GetInt64("application_status")
  8896. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8897. checktime := time.Now().Unix()
  8898. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8899. if err == nil {
  8900. this.ServeSuccessJSON(map[string]interface{}{
  8901. "msg": "ok",
  8902. })
  8903. return
  8904. }
  8905. }
  8906. func (c *DialysisAPIController) GetControlMonitorList() {
  8907. partition, _ := c.GetInt64("partition")
  8908. monitorDate := c.GetString("date")
  8909. patient_id, _ := c.GetInt64("patient_id")
  8910. pat_type, _ := c.GetInt64("pat_type")
  8911. timeLayout := "2006-01-02"
  8912. loc, _ := time.LoadLocation("Local")
  8913. var theStartTime int64
  8914. if len(monitorDate) > 0 {
  8915. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8916. if err != nil {
  8917. theStartTime = 0
  8918. }
  8919. theStartTime = theTime.Unix()
  8920. }
  8921. adminInfo := c.GetMobileAdminUserInfo()
  8922. orgID := adminInfo.Org.Id
  8923. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8924. if err != nil {
  8925. c.ErrorLog("获取排班信息失败:%v", err)
  8926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8927. } else {
  8928. if len(monitor) > 0 {
  8929. //获取所有床位
  8930. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8931. //获取所有分区
  8932. zoneList, _ := service.GetAllZoneByList(orgID)
  8933. //获取透析处方
  8934. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8935. //获取透前评估
  8936. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8937. //获取上机
  8938. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8939. //获取透后
  8940. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8941. //获取透后监测
  8942. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8943. //获取所有的患者
  8944. patients, _ := service.GetAllPatientListByListOne(orgID)
  8945. //获取所有透析模式
  8946. treatments, _ := service.GetAllTreatModeByList(orgID)
  8947. //获取所有医嘱
  8948. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8949. //获取双人核对
  8950. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8951. //治疗小结
  8952. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8953. //待消毒
  8954. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8955. for key, item := range monitor {
  8956. // 获取床位信息
  8957. for _, it := range numberList {
  8958. if item.BedId == it.ID {
  8959. monitor[key].DeviceNumber = it
  8960. break
  8961. }
  8962. }
  8963. //获取分区信息
  8964. for _, it := range zoneList {
  8965. if item.PartitionId == it.ID {
  8966. monitor[key].DeviceZone = it
  8967. }
  8968. }
  8969. for _, prescription := range prescriptions {
  8970. if item.PatientId == prescription.PatientId {
  8971. monitor[key].Prescription = prescription
  8972. break
  8973. }
  8974. }
  8975. for _, it := range checkList {
  8976. if item.PatientId == it.PatientId {
  8977. monitor[key].DoubleCheck = it
  8978. break
  8979. }
  8980. }
  8981. for _, it := range summaryList {
  8982. if item.PatientId == it.PatientId {
  8983. monitor[key].TreatmentSummaryForList = it
  8984. break
  8985. }
  8986. }
  8987. // 透前评估
  8988. for _, assessmentBefore := range assessmentBefores {
  8989. if item.PatientId == assessmentBefore.PatientId {
  8990. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8991. break
  8992. }
  8993. }
  8994. // 透析上下机
  8995. for _, dialysisOrder := range dialysisOrders {
  8996. if item.PatientId == dialysisOrder.PatientId {
  8997. monitor[key].DialysisOrder = dialysisOrder
  8998. break
  8999. }
  9000. }
  9001. // 治疗小节
  9002. for _, afterDislysis := range AssessmentAfterDislysis {
  9003. if item.PatientId == afterDislysis.PatientId {
  9004. monitor[key].AssessmentAfterDislysis = afterDislysis
  9005. break
  9006. }
  9007. }
  9008. for _, it := range monitorlist {
  9009. if item.PatientId == it.PatientId {
  9010. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9011. }
  9012. }
  9013. for _, it := range adviceList {
  9014. if item.PatientId == it.PatientId {
  9015. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9016. }
  9017. }
  9018. for _, patient := range patients {
  9019. if item.PatientId == patient.ID {
  9020. monitor[key].MonitorPatients = patient
  9021. break
  9022. }
  9023. }
  9024. for _, treatment := range treatments {
  9025. if item.ModeId == treatment.ID {
  9026. monitor[key].TreatmentMode = treatment
  9027. break
  9028. }
  9029. }
  9030. for _, infor := range informationList {
  9031. if item.PatientId == infor.PatientId {
  9032. monitor[key].NewDeviceInformation = infor
  9033. break
  9034. }
  9035. }
  9036. }
  9037. }
  9038. }
  9039. patients, err := service.GetAllpatientFourty(orgID)
  9040. var mds []*models.NewMonitorDialysisScheduleList
  9041. if pat_type == 0 {
  9042. for _, item := range monitor {
  9043. mds = append(mds, item)
  9044. }
  9045. }
  9046. //待医嘱核对
  9047. if pat_type == 1 {
  9048. for _, item := range monitor {
  9049. if len(item.AdviceList) > 0 {
  9050. mds = append(mds, item)
  9051. }
  9052. }
  9053. }
  9054. //待开小结
  9055. if pat_type == 2 {
  9056. for _, item := range monitor {
  9057. if item.TreatmentSummaryForList == nil {
  9058. mds = append(mds, item)
  9059. }
  9060. }
  9061. }
  9062. //待下机
  9063. if pat_type == 3 {
  9064. for _, item := range monitor {
  9065. if item.DialysisOrder != nil {
  9066. if item.DialysisOrder.ID > 0 {
  9067. mds = append(mds, item)
  9068. }
  9069. }
  9070. }
  9071. }
  9072. //待消毒
  9073. if pat_type == 4 {
  9074. for _, item := range monitor {
  9075. if item.NewDeviceInformation == nil {
  9076. mds = append(mds, item)
  9077. }
  9078. }
  9079. }
  9080. //待双人核对
  9081. if pat_type == 5 {
  9082. for _, item := range monitor {
  9083. if item.DoubleCheck == nil {
  9084. mds = append(mds, item)
  9085. }
  9086. }
  9087. }
  9088. //医嘱未执行
  9089. if pat_type == 6 {
  9090. for _, item := range monitor {
  9091. if len(item.AdviceList) > 0 {
  9092. mds = append(mds, item)
  9093. }
  9094. }
  9095. }
  9096. //患者未签名
  9097. if pat_type == 7 {
  9098. for _, item := range monitor {
  9099. if item.DialysisOrder != nil {
  9100. if item.DialysisOrder.ID > 0 {
  9101. mds = append(mds, item)
  9102. }
  9103. }
  9104. }
  9105. }
  9106. //目标超滤于实际超滤不同
  9107. if pat_type == 8 {
  9108. for _, item := range monitor {
  9109. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9110. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9111. mds = append(mds, item)
  9112. }
  9113. }
  9114. }
  9115. }
  9116. //血压少于5次
  9117. if pat_type == 9 {
  9118. for _, item := range monitor {
  9119. if len(item.MonitoringRecord) < 5 {
  9120. mds = append(mds, item)
  9121. }
  9122. }
  9123. }
  9124. if pat_type == 10 {
  9125. for _, item := range monitor {
  9126. if len(item.MonitoringRecord) == 0 {
  9127. mds = append(mds, item)
  9128. }
  9129. }
  9130. }
  9131. if pat_type == 11 {
  9132. for _, item := range monitor {
  9133. if len(item.MonitoringRecord) > 0 {
  9134. mds = append(mds, item)
  9135. }
  9136. }
  9137. }
  9138. if pat_type == 12 {
  9139. for _, item := range monitor {
  9140. if len(item.MonitoringRecord) > 0 {
  9141. mds = append(mds, item)
  9142. }
  9143. }
  9144. }
  9145. if err == nil {
  9146. c.ServeSuccessJSON(map[string]interface{}{
  9147. "monitor": mds,
  9148. "patients": patients,
  9149. })
  9150. } else {
  9151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9152. }
  9153. }
  9154. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9155. admin_user_id, _ := c.GetInt64("admin_user_id")
  9156. timeStr := time.Now().Format("2006-01-02")
  9157. timeLayout := "2006-01-02 15:04:05"
  9158. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9159. timenow := timeStringToTime.Unix()
  9160. orgId := c.GetMobileAdminUserInfo().Org.Id
  9161. //查询当前护士的患者
  9162. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9163. var patientIds []int64
  9164. for _, item := range orderList {
  9165. patientIds = append(patientIds, item.PatientId)
  9166. }
  9167. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9168. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9169. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9170. //药品管理信息
  9171. _, drugStockConfig := service.FindHisConfig(orgId)
  9172. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9173. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9174. c.ServeSuccessJSON(map[string]interface{}{
  9175. "adviceList": adviceList,
  9176. "hisAdviceList": hisAdviceList,
  9177. "projectList": projectList,
  9178. "drugStockConfig": drugStockConfig,
  9179. "patientList": patientList,
  9180. "projectConfig": projectConfig,
  9181. })
  9182. }
  9183. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9184. patient_id, _ := c.GetInt64("patient_id")
  9185. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9186. c.ServeSuccessJSON(map[string]interface{}{
  9187. "recrods": recrods,
  9188. })
  9189. }
  9190. func (c *DialysisAPIController) ExMobileChangeSch() {
  9191. id_one, _ := c.GetInt64("id_one")
  9192. id_two, _ := c.GetInt64("id_two")
  9193. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9194. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9195. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9196. //if order2.ID > 0 {
  9197. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9198. // return
  9199. //}
  9200. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9201. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9202. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9203. if count > 0 {
  9204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9205. return
  9206. }
  9207. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9208. if count1 > 0 {
  9209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9210. return
  9211. }
  9212. }
  9213. err := service.UpdateScheduleThree(sch, sch_two)
  9214. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9215. if order.ID > 0 {
  9216. //查询该患者的排班机位
  9217. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9218. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9219. redis := service.RedisClient()
  9220. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9221. redis.Set(key, "", time.Second)
  9222. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9223. //清空key 值
  9224. redis.Set(keyOne, "", time.Second)
  9225. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9226. //return
  9227. }
  9228. if err == nil {
  9229. //去除当天患者排班中重复数据,保留最后一条数据
  9230. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9231. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9232. c.ServeSuccessJSON(map[string]interface{}{
  9233. "msg": "交换成功",
  9234. })
  9235. } else {
  9236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9237. return
  9238. }
  9239. }
  9240. func (c *DialysisAPIController) MobileCoverSch() {
  9241. id_one, _ := c.GetInt64("id_one")
  9242. id_two, _ := c.GetInt64("id_two")
  9243. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9244. //针对凤凰医院
  9245. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9246. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9247. if len(advice) > 0 {
  9248. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9249. }
  9250. }
  9251. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9252. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9253. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9254. if len(hisAdvice) > 0 {
  9255. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9256. }
  9257. if len(project) > 0 {
  9258. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9259. }
  9260. }
  9261. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9262. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9263. if order.ID > 0 {
  9264. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9265. redis := service.RedisClient()
  9266. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9267. redis.Set(key, "", time.Second)
  9268. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9269. //清空key 值
  9270. redis.Set(keyOne, "", time.Second)
  9271. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9272. //return
  9273. }
  9274. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9275. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9276. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9277. if count > 0 {
  9278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9279. return
  9280. }
  9281. }
  9282. var new_sch models.Schedule
  9283. new_sch = sch
  9284. new_sch.BedId = sch_two.BedId
  9285. new_sch.ScheduleDate = sch_two.ScheduleDate
  9286. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9287. new_sch.PartitionId = sch_two.PartitionId
  9288. new_sch.ScheduleType = sch_two.ScheduleType
  9289. new_sch.ID = 0
  9290. //删除原来的排班
  9291. err := service.SaveSchTwo(sch, sch_two)
  9292. //生成新的排班
  9293. if err == nil {
  9294. err2 := service.SaveSch(&new_sch)
  9295. if err2 == nil {
  9296. //去除当天患者排班中重复数据,保留最后一条数据
  9297. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9298. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9299. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9300. c.ServeSuccessJSON(map[string]interface{}{
  9301. "msg": "覆盖成功",
  9302. "new_sch": new_sch,
  9303. })
  9304. } else {
  9305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9306. return
  9307. }
  9308. } else {
  9309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9310. return
  9311. }
  9312. }
  9313. //func BatchExectime() {
  9314. //
  9315. //}