dialysis_api_controller.go 479KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. sterilization_water := c.GetString("sterilization_water")
  1771. five_glucose := c.GetString("five_glucose")
  1772. fifty_glucose := c.GetString("fifty_glucose")
  1773. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  1774. calcium_gluconate := c.GetString("calcium_gluconate")
  1775. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  1776. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  1777. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  1778. new_sty := c.GetString("new_sty")
  1779. var first_sup int64
  1780. if first_super == "是" {
  1781. first_sup = 1
  1782. }
  1783. if first_super == "否" {
  1784. first_sup = 2
  1785. }
  1786. if first_super == "请选择" {
  1787. first_sup = 0
  1788. }
  1789. is_sequential := c.GetString("is_sequential")
  1790. var is_sequent int64
  1791. if is_sequential == "是" {
  1792. is_sequent = 1
  1793. }
  1794. if is_sequential == "否" {
  1795. is_sequent = 2
  1796. }
  1797. if is_sequential == "请选择" {
  1798. is_sequent = 0
  1799. }
  1800. conduct := c.GetString("conduct")
  1801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1802. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1803. //
  1804. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1805. // if appRole.UserType == 3 {
  1806. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1807. // if getPermissionErr != nil {
  1808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1809. // return
  1810. // } else if headNursePermission == nil {
  1811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1812. // return
  1813. // }
  1814. // }
  1815. //}
  1816. // 查询信息规挡的设置天数
  1817. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1818. if infor.ID > 0 && infor.WeekDay > 0 {
  1819. var cha_time int64
  1820. timeNowStr := time.Now().Format("2006-01-02")
  1821. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1822. //今日的日期减去设置的日期
  1823. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1824. if cha_time >= recordDate.Unix() {
  1825. //查询审核是否允许
  1826. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1827. //申请状态不允许的情况 拒绝修改
  1828. if infor.ApplicationStatus != 1 {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1830. return
  1831. }
  1832. }
  1833. }
  1834. if mode_id > 0 {
  1835. var str string
  1836. //查找该机构用的是什么透析器
  1837. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1838. if filedConfig.ID > 0 {
  1839. str = dialyzerPerfusionApparatus
  1840. } else {
  1841. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1842. }
  1843. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1844. }
  1845. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1846. var dialysis_dialyszers_id int64
  1847. var dialysis_strainer_id int64
  1848. var dialysis_irrigation_id int64
  1849. if len(goodList) > 0 {
  1850. for _, item := range goodList {
  1851. if item.SpecificationName == dialysis_dialyszers {
  1852. dialysis_dialyszers_id = item.ID
  1853. }
  1854. if item.SpecificationName == dialysis_irrigation {
  1855. dialysis_irrigation_id = item.ID
  1856. }
  1857. if item.SpecificationName == dialysis_strainer {
  1858. dialysis_strainer_id = item.ID
  1859. }
  1860. }
  1861. }
  1862. //TODO 需要根据角色去判断
  1863. prescription := models.DialysisPrescription{
  1864. UserOrgId: adminUserInfo.Org.Id,
  1865. PatientId: id,
  1866. RecordDate: recordDate.Unix(),
  1867. ModeId: mode_id,
  1868. DialysisDuration: dialysis_duration,
  1869. Dialyzer: dialyzer,
  1870. PerfusionApparatus: perfusion_apparatus,
  1871. BloodFlowVolume: blood_flow_volume,
  1872. DewaterAmount: dewater_amount,
  1873. DisplaceLiqui: displace_liqui,
  1874. ReplacementWay: replacement_way,
  1875. Anticoagulant: anticoagulant,
  1876. AnticoagulantShouji: anticoagulant_shouji,
  1877. AnticoagulantWeichi: anticoagulant_weichi,
  1878. AnticoagulantZongliang: anticoagulant_zongliang,
  1879. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1880. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1881. Kalium: kalium,
  1882. Sodium: sodium,
  1883. Calcium: calcium,
  1884. Bicarbonate: bicarbonate,
  1885. Glucose: glucose,
  1886. // DryWeight: dry_weight,
  1887. DialysateFlow: dialysate_flow,
  1888. DialysateTemperature: dialysate_temperature,
  1889. // PrescriptionDoctor: prescription_doctor,
  1890. ReplacementTotal: replacement_total,
  1891. Conductivity: conductivity,
  1892. Remark: remark,
  1893. Status: 1,
  1894. CreatedTime: time.Now().Unix(),
  1895. UpdatedTime: time.Now().Unix(),
  1896. DialysisDurationMinute: dialysisDurationMinute,
  1897. DialysisDurationHour: dialysisDurationHour,
  1898. TargetUltrafiltration: targetUltrafiltration,
  1899. DialysateFormulation: dialysateFormulation,
  1900. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1901. BodyFluid: body_fluid,
  1902. SpecialMedicine: special_medicine,
  1903. SpecialMedicineOther: special_medicine_other,
  1904. DisplaceLiquiPart: displace_liqui_part,
  1905. DisplaceLiquiValue: displace_liqui_value,
  1906. BloodAccess: blood_access,
  1907. Ultrafiltration: ultrafiltration,
  1908. BodyFluidOther: body_fluid_other,
  1909. Niprocart: niprocart,
  1910. Jms: jms,
  1911. FistulaNeedleSet: fistula_needle_set,
  1912. FistulaNeedleSet16: fistula_needle_set_16,
  1913. Hemoperfusion: hemoperfusion,
  1914. DialyserSterilised: dialyser_sterilised,
  1915. Filtryzer: filtryzer,
  1916. Dialyzers: dialyzers,
  1917. Injector: injector,
  1918. Bloodlines: bloodlines,
  1919. TubingHemodialysis: tubing_hemodialysis,
  1920. Package: safe_package,
  1921. ALiquid: a_liquid,
  1922. TargetKtv: target_ktv,
  1923. PreImpulse: pre_impulse,
  1924. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1925. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1926. Blood: blood,
  1927. DialysisDialyszers: dialysis_dialyszers,
  1928. DialysisIrrigation: dialysis_irrigation,
  1929. AntioxidantCommodityName: antioxidant_commodity_name,
  1930. DisplaceSpeed: displace_speed,
  1931. Illness: illness,
  1932. Amylaceum: amylaceum,
  1933. SingleTime: single_time,
  1934. SingleWater: single_water,
  1935. ReplacementFlow: replacement_flow,
  1936. PlasmaSeparator: plasma_separator,
  1937. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1938. OxygenUptake: oxygen_uptake,
  1939. OxygenFlow: oxygen_flow,
  1940. OxygenTime: oxygen_time,
  1941. HemodialysisPipelines: hemodialysis_pipelines,
  1942. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1943. PunctureNeedle: puncture_needle,
  1944. PunctureNeedleCount: puncture_needle_count,
  1945. Epo: epo,
  1946. EpoCount: epo_count,
  1947. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1948. AdminUserId: admin_user_id,
  1949. IsWater: is_war,
  1950. DrhyWater: drhy_water,
  1951. DryWaterHour: dry_water_hour,
  1952. WaterMachine: water_machine,
  1953. AddAmount: add_amount,
  1954. ReduceAmount: reduce_amount,
  1955. DialysisRemark: dialysis_remark,
  1956. PrescribingNumber: prescribing_number,
  1957. StartSodium: start_sodium,
  1958. SodiumCurve: sodium_curve,
  1959. TreatmentRemark: treatment_remark,
  1960. PrescriptionSodium: prescription_sodium,
  1961. DialysisFluidFlow: dialysis_fluid_flow,
  1962. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1963. PrescriptionWater: prescription_water,
  1964. DialysisStrainer: dialysis_strainer,
  1965. Chaptalization: chaptalization,
  1966. WashingTime: washing_time,
  1967. WarshCount: warsh_count,
  1968. BloodAccessPartId: blood_access_part_id,
  1969. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1970. Dialyzate: dialyzate,
  1971. DialysisDialyszersId: dialysis_dialyszers_id,
  1972. DialysisIrrigationId: dialysis_irrigation_id,
  1973. DialysisStrainerId: dialysis_strainer_id,
  1974. FirstSuper: first_sup,
  1975. IsSequential: is_sequent,
  1976. Conduct: conduct,
  1977. SterilizationWater: sterilization_water,
  1978. FiveGlucose: five_glucose,
  1979. FiftyGlucose: fifty_glucose,
  1980. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1981. CalciumGluconate: calcium_gluconate,
  1982. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1983. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1984. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1985. NewSty: new_sty,
  1986. }
  1987. if prescription.ModeId != 13 {
  1988. prescription.SterilizationWater = ""
  1989. prescription.FiveGlucose = ""
  1990. prescription.FiftyGlucose = ""
  1991. prescription.MagnesiumSulfateInjection = ""
  1992. prescription.CalciumGluconate = ""
  1993. prescription.FivePotassiumChlorideInjection = ""
  1994. prescription.TenPotassiumChlorideInjection = ""
  1995. prescription.FiveSodiumBicarbonateInjection = ""
  1996. prescription.NewSty = ""
  1997. }
  1998. if adminUserInfo.Org.Id == 10721 {
  1999. if prescription.ModeId == 2 {
  2000. if prescription.ReplacementTotal == 0 {
  2001. prescription.ReplacementTotal = 15
  2002. }
  2003. }
  2004. }
  2005. //查询最近透析准备表里是否存在 透析器 灌流器
  2006. //
  2007. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2008. //
  2009. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2010. //
  2011. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2012. //if len(mation)>0{
  2013. // for _, item := range splitStr {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. //
  2017. // //查询最近一次的透析器
  2018. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2019. //
  2020. // if errcode == gorm.ErrRecordNotFound{
  2021. // //插入数据
  2022. // prepare := models.DialysisBeforePrepare{
  2023. // UserOrgId: adminUserInfo.Org.Id,
  2024. // PatientId: id,
  2025. // RecordDate: recordDate.Unix(),
  2026. // GoodTypeId: it.GoodTypeId,
  2027. // GoodId: it.ID,
  2028. // Count: 1,
  2029. // Ctime: time.Now().Unix(),
  2030. // Creater: adminUserInfo.AdminUser.Id,
  2031. // Status:1,
  2032. //
  2033. // }
  2034. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2035. // fmt.Println("",errcode)
  2036. // }
  2037. // }
  2038. // }
  2039. //
  2040. // }
  2041. //
  2042. // for _, item := range splitIrrigation {
  2043. // for _,it := range mation{
  2044. // if(item == it.SpecificationName){
  2045. // //查询最近一次的透析器
  2046. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2047. // if errcode == gorm.ErrRecordNotFound{
  2048. // //插入数据
  2049. // prepare := models.DialysisBeforePrepare{
  2050. // UserOrgId: adminUserInfo.Org.Id,
  2051. // PatientId: id,
  2052. // RecordDate: recordDate.Unix(),
  2053. // GoodTypeId: it.GoodTypeId,
  2054. // GoodId: it.ID,
  2055. // Count: 1,
  2056. // Ctime: time.Now().Unix(),
  2057. // Creater: adminUserInfo.AdminUser.Id,
  2058. // Status:1,
  2059. //
  2060. // }
  2061. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2062. // fmt.Println(errcode)
  2063. // }
  2064. // }
  2065. // }
  2066. // }
  2067. //}
  2068. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. if dialysisPrescription.ID == 0 { //新增
  2070. if appRole.UserType == 2 || appRole.UserType == 1 {
  2071. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2072. }
  2073. prescription.Creater = adminUserInfo.AdminUser.Id
  2074. //针对河间咸得
  2075. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2076. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2077. prescription.DisplaceLiquiPart = 0
  2078. prescription.DisplaceLiquiValue = 0
  2079. }
  2080. }
  2081. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2082. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2083. }
  2084. err := service.AddSigleRecord(&prescription)
  2085. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2086. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2087. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2088. if len(monitorList) > 0 {
  2089. var ultrafiltration_rate float64
  2090. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2091. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2092. var replacement_rate float64
  2093. if adminUserInfo.Org.Id == 10721 {
  2094. //乘10 除10是为了保留一位小数
  2095. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2096. }
  2097. if adminUserInfo.Org.Id == 9478 {
  2098. //乘10 除10是为了保留一位小数
  2099. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2100. }
  2101. if adminUserInfo.Org.Id == 10766 {
  2102. //乘10 除10是为了保留一位小数
  2103. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2104. }
  2105. var firstOpeateTime = monitorList[0].OperateTime
  2106. for _, item := range monitorList {
  2107. //超滤率
  2108. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2109. //置换率
  2110. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2111. //超滤量
  2112. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2113. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2114. //置换量
  2115. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2116. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2117. }
  2118. }
  2119. }
  2120. //记录日志
  2121. byterequest, _ := json.Marshal(prescription)
  2122. prescriptionLog := models.XtDialysisPrescriptionLog{
  2123. UserOrgId: prescription.UserOrgId,
  2124. Ctime: time.Now().Unix(),
  2125. Mtime: 0,
  2126. ErrLog: string(byterequest),
  2127. AdminUserId: adminUserInfo.AdminUser.Id,
  2128. RecordDate: prescription.RecordDate,
  2129. PatientId: prescription.PatientId,
  2130. Source: "手机端新增保存处方",
  2131. Status: 1,
  2132. }
  2133. service.CreatePrescriptionLog(prescriptionLog)
  2134. finish := models.XtDialysisFinish{
  2135. IsFinish: 1,
  2136. UserOrgId: adminUserInfo.Org.Id,
  2137. Status: 1,
  2138. Ctime: time.Now().Unix(),
  2139. Mtime: 0,
  2140. Module: 1,
  2141. RecordDate: recordDate.Unix(),
  2142. Sourse: 1,
  2143. PatientId: id,
  2144. }
  2145. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2146. if dialysisFinish.ID == 0 {
  2147. service.CreateDialysisFinish(finish)
  2148. }
  2149. //长沙南雅医院,自动生成抗凝剂的临时处方
  2150. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2151. if prescribing_number == 0 {
  2152. prescribing_number = 1
  2153. }
  2154. if prescribing_number == 0 && id == 14682 {
  2155. prescribing_number = 2
  2156. }
  2157. if prescribing_number == 0 && id == 18560 {
  2158. prescribing_number = 2
  2159. }
  2160. advice := models.DoctorAdvice{
  2161. UserOrgId: adminUserInfo.Org.Id,
  2162. PatientId: id,
  2163. GroupNo: 0,
  2164. AdviceType: 2,
  2165. RecordDate: recordDate.Unix(),
  2166. AdviceDate: recordDate.Unix(),
  2167. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2168. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2169. AdviceDesc: "",
  2170. ReminderDate: 0,
  2171. SingleDose: anticoagulant_zongliang,
  2172. SingleDoseUnit: "iu",
  2173. DrugSpec: 0,
  2174. DrugSpecUnit: "",
  2175. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2176. PrescribingNumberUnit: "支",
  2177. DeliveryWay: "静脉注射",
  2178. ExecutionFrequency: "上机前",
  2179. AdviceDoctor: 0,
  2180. Status: 1,
  2181. CreatedTime: time.Now().Unix(),
  2182. UpdatedTime: time.Now().Unix(),
  2183. IsPrescription: 1,
  2184. ExecutionState: 2,
  2185. StopState: 2,
  2186. IsSettle: 2,
  2187. }
  2188. // 查询排班信息
  2189. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2190. if schedulePatient.ID > 0 {
  2191. if schedulePatient.ScheduleType == 1 {
  2192. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2193. }
  2194. if schedulePatient.ScheduleType == 2 {
  2195. advice.StartTime = recordDate.Unix() + 9*60*60
  2196. }
  2197. }
  2198. // 抗凝剂名称
  2199. switch anticoagulant {
  2200. case 1:
  2201. advice.AdviceName = "无肝素"
  2202. break
  2203. case 2:
  2204. advice.AdviceName = "普通肝素"
  2205. break
  2206. case 3:
  2207. advice.AdviceName = "低分子肝素"
  2208. break
  2209. case 4:
  2210. advice.AdviceName = "阿加曲班"
  2211. break
  2212. case 5:
  2213. advice.AdviceName = "枸橼酸钠"
  2214. break
  2215. case 6:
  2216. advice.AdviceName = "低分子肝素钙"
  2217. break
  2218. case 7:
  2219. advice.AdviceName = "低分子肝素钠"
  2220. break
  2221. case 8:
  2222. advice.AdviceName = "依诺肝素"
  2223. break
  2224. case 9:
  2225. advice.AdviceName = "达肝素"
  2226. break
  2227. case 10:
  2228. advice.AdviceName = "体外抗凝"
  2229. break
  2230. case 11:
  2231. advice.AdviceName = "那曲肝素"
  2232. break
  2233. case 12:
  2234. advice.AdviceName = "无抗凝剂"
  2235. break
  2236. }
  2237. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2238. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2239. advice.AdviceDoctor = appRole.AdminUserId
  2240. }
  2241. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2242. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2243. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2244. advice.AdviceName = "低分子肝素钠注射液"
  2245. // 修改患者临时医嘱里的抗凝剂医嘱
  2246. advice.ID = advicePrescription.ID
  2247. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2248. } else {
  2249. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2250. advice.AdviceName = "低分子肝素钠注射液"
  2251. // 新增患者临时医嘱里的抗凝剂医嘱
  2252. service.CreateDoctorAdvice(&advice)
  2253. }
  2254. }
  2255. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2256. redis := service.RedisClient()
  2257. defer redis.Close()
  2258. //清空key 值
  2259. redis.Set(key, "", time.Second)
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2261. redis.Set(keyOne, "", time.Second)
  2262. }
  2263. //获取key,清空redis
  2264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2265. redis := service.RedisClient()
  2266. //清空key 值
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2269. //清空key 值
  2270. redis.Set(keyOne, "", time.Second)
  2271. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2272. //清空key 值
  2273. redis.Set(keyTwo, "", time.Second)
  2274. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2275. redis.Set(keySix, "", time.Second)
  2276. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2277. redis.Set(keySeven, "", time.Second)
  2278. if err == nil {
  2279. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2280. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2281. //清空key 值
  2282. redis.Set(keyThree, "", time.Second)
  2283. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2284. //清空key 值
  2285. redis.Set(keyFour, "", time.Second)
  2286. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2287. redis.Set(keyFive, "", time.Second)
  2288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2289. redis.Set(keySix, "", time.Second)
  2290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2291. redis.Set(keySeven, "", time.Second)
  2292. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2293. //清空key 值
  2294. redis.Set(keyOne, "", time.Second)
  2295. if updateErr != nil {
  2296. utils.ErrorLog("%v", updateErr)
  2297. }
  2298. defer redis.Close()
  2299. c.ServeSuccessJSON(map[string]interface{}{
  2300. "prescription": prescription,
  2301. })
  2302. }
  2303. } else { //修改
  2304. //if mode_id > 0 {
  2305. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2306. //}
  2307. //if template.TemplateId == 1 {
  2308. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2309. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2310. // if getPermissionErr != nil {
  2311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. // return
  2313. // } else if headNursePermission == nil {
  2314. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2315. // return
  2316. // }
  2317. // }
  2318. //}
  2319. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2320. prescription.Modifier = adminUserInfo.AdminUser.Id
  2321. if appRole.UserType == 2 || appRole.UserType == 1 {
  2322. prescription_doctor := adminUserInfo.AdminUser.Id
  2323. prescription.PrescriptionDoctor = prescription_doctor
  2324. } else {
  2325. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2326. }
  2327. if dialysisPrescription.Creater == 0 { //体重称
  2328. prescription.Creater = adminUserInfo.AdminUser.Id
  2329. } else {
  2330. prescription.Creater = dialysisPrescription.Creater
  2331. if adminUserInfo.Org.Id == 9882 {
  2332. if appRole.UserType == 2 || appRole.UserType == 1 {
  2333. prescription_doctor := adminUserInfo.AdminUser.Id
  2334. prescription.PrescriptionDoctor = prescription_doctor
  2335. prescription.Creater = prescription_doctor
  2336. }
  2337. }
  2338. }
  2339. prescription.ID = dialysisPrescription.ID
  2340. if adminUserInfo.Org.Id == 10721 {
  2341. if prescription.ModeId == 2 {
  2342. if prescription.ReplacementTotal == 0 {
  2343. prescription.ReplacementTotal = 15
  2344. }
  2345. }
  2346. }
  2347. service.UpDateDialysisPrescription(&prescription)
  2348. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2349. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2350. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2351. if len(monitorList) > 0 {
  2352. var ultrafiltration_rate float64
  2353. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2354. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2355. var replacement_rate float64
  2356. if adminUserInfo.Org.Id == 10721 {
  2357. //乘10 除10是为了保留一位小数
  2358. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2359. }
  2360. if adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2361. //乘10 除10是为了保留一位小数
  2362. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2363. }
  2364. var firstOpeateTime = monitorList[0].OperateTime
  2365. for _, item := range monitorList {
  2366. //超滤率
  2367. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2368. //置换率
  2369. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2370. //超滤量
  2371. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2372. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2373. //置换量
  2374. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2375. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2376. }
  2377. }
  2378. }
  2379. //记录日志
  2380. byterequest, _ := json.Marshal(prescription)
  2381. prescriptionLog := models.XtDialysisPrescriptionLog{
  2382. UserOrgId: prescription.UserOrgId,
  2383. Ctime: time.Now().Unix(),
  2384. Mtime: 0,
  2385. ErrLog: string(byterequest),
  2386. AdminUserId: adminUserInfo.AdminUser.Id,
  2387. RecordDate: prescription.RecordDate,
  2388. PatientId: prescription.PatientId,
  2389. Source: "手机端修改处方",
  2390. Status: 1,
  2391. }
  2392. service.CreatePrescriptionLog(prescriptionLog)
  2393. finish := models.XtDialysisFinish{
  2394. IsFinish: 1,
  2395. UserOrgId: adminUserInfo.Org.Id,
  2396. Status: 1,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: 0,
  2399. Module: 1,
  2400. RecordDate: recordDate.Unix(),
  2401. Sourse: 1,
  2402. PatientId: id,
  2403. }
  2404. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2405. if dialysisFinish.ID == 0 {
  2406. service.CreateDialysisFinish(finish)
  2407. }
  2408. //修改处方
  2409. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2410. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2411. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2412. if advicePrescription.ID > 0 {
  2413. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2415. redis := service.RedisClient()
  2416. defer redis.Close()
  2417. //清空key 值
  2418. redis.Set(key, "", time.Second)
  2419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2420. redis.Set(keyOne, "", time.Second)
  2421. }
  2422. }
  2423. //获取key,清空redis
  2424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2425. redis := service.RedisClient()
  2426. //清空key 值
  2427. redis.Set(key, "", time.Second)
  2428. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2429. //清空key 值
  2430. redis.Set(keyOne, "", time.Second)
  2431. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2432. redis.Set(keySix, "", time.Second)
  2433. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2434. redis.Set(keySeven, "", time.Second)
  2435. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2436. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2437. //清空key 值
  2438. redis.Set(keyTwoOne, "", time.Second)
  2439. defer redis.Close()
  2440. if updateErr != nil {
  2441. utils.ErrorLog("%v", updateErr)
  2442. }
  2443. c.ServeSuccessJSON(map[string]interface{}{
  2444. "prescription": prescription,
  2445. })
  2446. }
  2447. }
  2448. func (c *DialysisAPIController) Finish() {
  2449. id, _ := c.GetInt64("patient", 0)
  2450. recordDateStr := c.GetString("record_date")
  2451. nurseID, _ := c.GetInt64("nurse")
  2452. end_time := c.GetString("end_time")
  2453. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2454. internal_fistula := c.GetString("blood_access_internal_fistula")
  2455. catheter := c.GetString("catheter")
  2456. cruor := c.GetString("cruor")
  2457. mission := c.GetString("mission")
  2458. condenser := c.GetString("condenser")
  2459. if id <= 0 || nurseID <= 0 {
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2461. return
  2462. }
  2463. adminUserInfo := c.GetMobileAdminUserInfo()
  2464. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2465. if patient.ID == 0 {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2467. return
  2468. }
  2469. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2470. if getNurseErr != nil {
  2471. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. } else if nurse == nil {
  2475. c.ErrorLog("护士不存在")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. if len(recordDateStr) == 0 {
  2480. recordDateStr = time.Now().Format("2006-01-02")
  2481. }
  2482. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2483. if parseDateErr != nil {
  2484. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2486. return
  2487. }
  2488. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2489. if parseEndDateErr != nil {
  2490. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. // 查询信息规挡的设置天数
  2495. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2496. if infor.ID > 0 && infor.WeekDay > 0 {
  2497. var cha_time int64
  2498. timeNowStr := time.Now().Format("2006-01-02")
  2499. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2500. //今日的日期减去设置的日期
  2501. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2502. if cha_time >= recordDate.Unix() {
  2503. //查询审核是否允许
  2504. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2505. //申请状态不允许的情况 拒绝修改
  2506. if infor.ApplicationStatus != 1 {
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2508. return
  2509. }
  2510. }
  2511. }
  2512. //now := time.Now()
  2513. //year, month, day := now.Date()
  2514. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2515. //todayTimeStamp := today_time.Unix()
  2516. // 获取当天的第一条透析纪录
  2517. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2518. if getMonitorRecordsErr != nil {
  2519. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2521. return
  2522. }
  2523. // 获取当前的最后一条透析纪录
  2524. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2525. if getMonitorRecordsErr != nil {
  2526. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. return
  2529. }
  2530. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2531. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2532. if getAADErr != nil {
  2533. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2535. return
  2536. }
  2537. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2538. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2539. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2540. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2541. if assessmentAfterDislysis != nil {
  2542. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2543. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2544. } else {
  2545. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2546. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2547. tempassessmentAfterDislysis.Status = 1
  2548. tempassessmentAfterDislysis.PatientId = id
  2549. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2550. }
  2551. //长沙南雅
  2552. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2553. //获取最后一条透析处方数据
  2554. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2555. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2556. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2557. }
  2558. if dialysisOrder.Stage == 1 {
  2559. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2560. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2561. fmt.Println(value)
  2562. a, b := math.Modf(value)
  2563. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2564. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2565. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2566. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2567. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2568. }
  2569. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2570. //var num1 int64
  2571. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2572. //fmt.Println(num1)
  2573. //sub := float64(num1 / 3600)
  2574. //fmt.Println(sub)
  2575. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2576. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2577. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2578. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2579. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2580. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2581. if adminUserInfo.Org.Id != 10375 {
  2582. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2583. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2584. }
  2585. if adminUserInfo.Org.Id == 10766 {
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2587. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2588. }
  2589. if adminUserInfo.Org.Id != 10445 {
  2590. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2591. }
  2592. //北方营口医院
  2593. if adminUserInfo.Org.Id == 10445 {
  2594. //获取最后一条透析处方数据
  2595. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2597. } else {
  2598. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2599. }
  2600. //新化博翔
  2601. if adminUserInfo.Org.Id == 10447 {
  2602. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2603. }
  2604. //阳春
  2605. if adminUserInfo.Org.Id == 10485 {
  2606. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2607. }
  2608. if adminUserInfo.Org.Id == 10551 {
  2609. //获取最后一条透析处方数据
  2610. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2612. }
  2613. if adminUserInfo.Org.Id == 10580 {
  2614. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2615. }
  2616. if adminUserInfo.Org.Id == 10612 {
  2617. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2618. }
  2619. //孝康
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2622. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2623. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2624. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2625. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2626. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2627. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2628. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2629. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2630. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2631. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2632. }
  2633. if adminUserInfo.Org.Id == 10721 {
  2634. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2635. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2636. }
  2637. if adminUserInfo.Org.Id == 10697 {
  2638. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2639. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2640. lastWeightAfter.LastAfterWeight = floatAfeter
  2641. }
  2642. if adminUserInfo.Org.Id == 10624 {
  2643. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2644. }
  2645. }
  2646. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10766 {
  2647. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2648. if adminUserInfo.Org.Id != 10702 {
  2649. if evaluation.SystolicBloodPressure == 0 {
  2650. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2651. if adminUserInfo.Org.Id == 10693 {
  2652. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2653. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2654. }
  2655. pre := models.PredialysisEvaluation{
  2656. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2657. }
  2658. fmt.Println("prew", pre)
  2659. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2662. redis := service.RedisClient()
  2663. redis.Set(key, "", time.Second)
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id != 10702 {
  2670. if evaluation.DiastolicBloodPressure == 0 {
  2671. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2672. if adminUserInfo.Org.Id == 10693 {
  2673. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2674. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2675. }
  2676. pres := models.PredialysisEvaluation{
  2677. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2678. }
  2679. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2681. redis := service.RedisClient()
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2684. redis.Set(keyOne, "", time.Second)
  2685. defer redis.Close()
  2686. fmt.Println(getNurseErr)
  2687. }
  2688. }
  2689. if adminUserInfo.Org.Id != 10702 {
  2690. if evaluation.PulseFrequency == 0 {
  2691. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2692. if adminUserInfo.Org.Id == 10693 {
  2693. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2694. evaluation.PulseFrequency = pulseFrequency
  2695. }
  2696. press := models.PredialysisEvaluation{
  2697. PulseFrequency: evaluation.PulseFrequency,
  2698. }
  2699. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2701. redis := service.RedisClient()
  2702. redis.Set(key, "", time.Second)
  2703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2704. redis.Set(keyOne, "", time.Second)
  2705. defer redis.Close()
  2706. fmt.Println(getNurseErr)
  2707. }
  2708. }
  2709. if evaluation.Temperature == 0 {
  2710. evaluation.Temperature = fmonitorRecords.Temperature
  2711. press := models.PredialysisEvaluation{
  2712. Temperature: evaluation.Temperature,
  2713. }
  2714. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2715. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2716. redis := service.RedisClient()
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2719. redis.Set(keyOne, "", time.Second)
  2720. defer redis.Close()
  2721. fmt.Println(getNurseErr)
  2722. }
  2723. }
  2724. if adminUserInfo.Org.Id == 9583 {
  2725. //获取透析处方的最后一条数据
  2726. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2727. if diaerr != nil {
  2728. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2733. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2734. }
  2735. }
  2736. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2737. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2738. }
  2739. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2740. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2741. }
  2742. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2743. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2744. }
  2745. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2746. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2747. }
  2748. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2749. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2750. }
  2751. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2752. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2753. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2754. }
  2755. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2756. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2757. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2758. }
  2759. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2760. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2761. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2762. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2763. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2764. }
  2765. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2766. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2767. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2768. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2769. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2774. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2775. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2776. }
  2777. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2780. }
  2781. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2782. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. }
  2785. if lastAssessmentAfterDislysis != nil {
  2786. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2787. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2788. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2789. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2790. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2791. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2792. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2793. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2794. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2795. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2796. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2797. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2798. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2799. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2800. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2801. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2802. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2803. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2804. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2805. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2806. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2807. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2808. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2809. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2810. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2811. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2812. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2813. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2814. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2815. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2816. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2817. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2818. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2819. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2820. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2821. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2822. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2823. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2824. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2825. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2826. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2827. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2828. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2829. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2830. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2831. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2832. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2833. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2834. if tempassessmentAfterDislysis.PatientId == 18695 {
  2835. tempassessmentAfterDislysis.ActualDisplacement = 0
  2836. }
  2837. if adminUserInfo.Org.Id != 10375 {
  2838. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2839. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2840. }
  2841. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2842. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2843. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2844. }
  2845. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2846. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2847. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2848. }
  2849. }
  2850. finish := models.XtDialysisFinish{
  2851. IsFinish: 1,
  2852. UserOrgId: adminUserInfo.Org.Id,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Module: 9,
  2857. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2858. Sourse: 1,
  2859. PatientId: tempassessmentAfterDislysis.PatientId,
  2860. }
  2861. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2862. if dialysisFinish.ID == 0 {
  2863. service.CreateDialysisFinish(finish)
  2864. }
  2865. //孝康
  2866. if adminUserInfo.Org.Id == 10693 {
  2867. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2868. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2869. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2870. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2871. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2872. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2873. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2874. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2875. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2876. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2877. }
  2878. if adminUserInfo.Org.Id == 10697 {
  2879. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2880. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2881. lastWeightAfter.LastAfterWeight = floatAfeter
  2882. }
  2883. if adminUserInfo.Org.Id == 10721 {
  2884. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2885. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2886. }
  2887. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2888. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2889. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2890. redis := service.RedisClient()
  2891. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2892. redis.Set(keyOne, "", time.Second)
  2893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2894. redis.Set(keyTwo, "", time.Second)
  2895. defer redis.Close()
  2896. //清空key 值
  2897. redis.Set(key, "", time.Second)
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. if dialysisOrder == nil {
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2904. return
  2905. }
  2906. if dialysisOrder.Stage == 2 {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2908. return
  2909. }
  2910. if dialysisOrder.Stage == 1 {
  2911. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2912. finish := models.XtDialysisFinish{
  2913. IsFinish: 1,
  2914. UserOrgId: adminUserInfo.Org.Id,
  2915. Status: 1,
  2916. Ctime: time.Now().Unix(),
  2917. Mtime: 0,
  2918. Module: 8,
  2919. RecordDate: recordDate.Unix(),
  2920. Sourse: 1,
  2921. PatientId: id,
  2922. }
  2923. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2924. if dialysisFinish.ID == 0 {
  2925. service.CreateDialysisFinish(finish)
  2926. }
  2927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2928. redis := service.RedisClient()
  2929. defer redis.Close()
  2930. //清空key 值
  2931. redis.Set(key, "", time.Second)
  2932. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2933. redis.Set(keyOne, "", time.Second)
  2934. //结束时候透析次数加1
  2935. service.UpdateSolutionByPatientId(id)
  2936. //下机完自动消毒,针对长沙南雅
  2937. if dialysisOrder.Stage == 1 {
  2938. 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 {
  2939. //根据床位号获取设备型号
  2940. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2941. //查询使用消毒最后一条消毒记录
  2942. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2943. fmt.Println("err", err)
  2944. if err == gorm.ErrRecordNotFound {
  2945. //查找排班
  2946. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2947. //查询改设备是否有消毒计划
  2948. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2949. //根据床位号获取设备id
  2950. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2951. //查询病人信息
  2952. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2953. var con = ""
  2954. if patients.IsInfectious == 0 {
  2955. con = ""
  2956. }
  2957. if patients.IsInfectious == 1 {
  2958. con = "无"
  2959. }
  2960. if patients.IsInfectious == 2 {
  2961. con = "有"
  2962. }
  2963. if errcode == nil {
  2964. var end_time int64
  2965. end_time = endDate.Unix() + plan.DisinfecTime*60
  2966. //新增消毒
  2967. information := models.DeviceInformation{
  2968. Date: dialysisOrder.DialysisDate,
  2969. Zone: dialysisOrder.ZoneId,
  2970. Class: dialysisOrder.SchedualType,
  2971. BedNumber: dialysisOrder.BedID,
  2972. PatientId: dialysisOrder.PatientId,
  2973. DialysisMode: scheduleByPatient.ModeId,
  2974. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2975. Disinfection: 1,
  2976. DialysisConcentration: 1,
  2977. DisinfectionStatus: 1,
  2978. Move: 1,
  2979. UserOrgId: dialysisOrder.UserOrgId,
  2980. DisinfectType: plan.Way,
  2981. DisinfectantType: plan.MachineDisinfectant,
  2982. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2983. Disinfectant: plan.Disinfectant,
  2984. Ctime: time.Now().Unix(),
  2985. Status: 1,
  2986. SignName: nurseID,
  2987. EquimentId: addmacher.ID,
  2988. DisinfectionResidue: 2,
  2989. Bed: addmacher.BedNumber,
  2990. StartTime: dialysisOrder.StartTime,
  2991. EndTime: dialysisOrder.EndTime,
  2992. Contagion: con,
  2993. WeightLoss: 0,
  2994. Hyperfiltratio: 0,
  2995. DialysisHour: "",
  2996. MachineRun: 1,
  2997. DisinfecStartime: endDate.Unix(),
  2998. DisinfecEndtime: end_time,
  2999. }
  3000. err := service.CreateInformationTwo(&information)
  3001. fmt.Println("报错", err)
  3002. }
  3003. }
  3004. }
  3005. }
  3006. dialysisOrder.Stage = 2
  3007. dialysisOrder.FinishNurse = nurseID
  3008. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  3009. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  3010. dialysisOrder.EndTime = endDate.Unix()
  3011. // 长沙南雅需求
  3012. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  3013. //获取最后1条监测的数据
  3014. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3015. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3016. var accumulatedBloodVolume float64
  3017. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  3018. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  3019. fmt.Println(err)
  3020. // 查询未执行的医嘱
  3021. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  3022. for _, item := range doctorAdvice {
  3023. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  3024. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  3025. redis := service.RedisClient()
  3026. //清空key 值
  3027. redis.Set(key, "", time.Second)
  3028. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  3029. redis.Set(keyTwo, "", time.Second)
  3030. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3031. redis.Set(keyThree, "", time.Second)
  3032. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  3033. theTime := toTime.Format("2006-01-02")
  3034. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3035. redis.Set(keyFour, "", time.Second)
  3036. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3037. redis.Set(keyFive, "", time.Second)
  3038. defer redis.Close()
  3039. }
  3040. }
  3041. go func() {
  3042. ssoDomain := beego.AppConfig.String("call_domain")
  3043. api := ssoDomain + "/index/downpatient"
  3044. values := make(url.Values)
  3045. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3046. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3047. values.Set("patient_id", strconv.FormatInt(id, 10))
  3048. http.PostForm(api, values)
  3049. }()
  3050. if err == nil {
  3051. c.ServeSuccessJSON(map[string]interface{}{
  3052. "dialysisOrder": dialysisOrder,
  3053. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3054. })
  3055. } else {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3057. }
  3058. }
  3059. //查找是否开启配置
  3060. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3061. ////开启下机扣减
  3062. //if orderSetting.IsOpen == 1 {
  3063. //
  3064. // //查询今日患者排班的模式
  3065. // db := service.XTWriteDB()
  3066. // // 开始外部循环的事务
  3067. // tx := db.Begin()
  3068. // // 在函数结束时处理事务回滚
  3069. // defer func() {
  3070. // if r := recover(); r != nil {
  3071. // tx.Rollback()
  3072. // }
  3073. // }()
  3074. //
  3075. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3076. //
  3077. // if schedule.ModeId == 1 {
  3078. // //扣减库存
  3079. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3080. //
  3081. // patient, _ := service.GetSfPatientById(tx, id)
  3082. // var over_count int64
  3083. // if schedule.ModeId == 1 {
  3084. // over_count = patient.HdCount
  3085. // }
  3086. // if schedule.ModeId == 2 {
  3087. // over_count = patient.HdfCount
  3088. // }
  3089. //
  3090. // if schedule.ModeId == 3 {
  3091. // over_count = patient.HdhpCount
  3092. // }
  3093. // if schedule.ModeId == 4 {
  3094. // over_count = patient.HpCount
  3095. // }
  3096. // if schedule.ModeId == 5 {
  3097. // over_count = patient.OtherCount
  3098. // }
  3099. // patientCountFlow := models.SfPatientCountFlow{
  3100. // PatientId: id,
  3101. // ModeId: schedule.ModeId,
  3102. // Count: 1,
  3103. // Status: 1,
  3104. // Ctime: time.Now().Unix(),
  3105. // Mtime: time.Now().Unix(),
  3106. // RecordDate: recordDate.Unix(),
  3107. // UserOrgId: adminUserInfo.Org.Id,
  3108. // Creater: adminUserInfo.AdminUser.Id,
  3109. // IsType: 1,
  3110. // OverCount: over_count,
  3111. // WarehouseOutId: 0,
  3112. // }
  3113. //
  3114. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3115. // }
  3116. //
  3117. // if schedule.ModeId == 2 {
  3118. //
  3119. // //扣减库存
  3120. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3121. //
  3122. // patient, _ := service.GetSfPatientById(tx, id)
  3123. // var over_count int64
  3124. // if schedule.ModeId == 1 {
  3125. // over_count = patient.HdCount
  3126. // }
  3127. // if schedule.ModeId == 2 {
  3128. // over_count = patient.HdfCount
  3129. // }
  3130. //
  3131. // if schedule.ModeId == 3 {
  3132. // over_count = patient.HdhpCount
  3133. // }
  3134. // if schedule.ModeId == 4 {
  3135. // over_count = patient.HpCount
  3136. // }
  3137. // if schedule.ModeId == 5 {
  3138. // over_count = patient.OtherCount
  3139. // }
  3140. // patientCountFlow := models.SfPatientCountFlow{
  3141. // PatientId: id,
  3142. // ModeId: schedule.ModeId,
  3143. // Count: 1,
  3144. // Status: 1,
  3145. // Ctime: time.Now().Unix(),
  3146. // Mtime: time.Now().Unix(),
  3147. // RecordDate: recordDate.Unix(),
  3148. // UserOrgId: adminUserInfo.Org.Id,
  3149. // Creater: adminUserInfo.AdminUser.Id,
  3150. // IsType: 2,
  3151. // OverCount: over_count,
  3152. // WarehouseOutId: 0,
  3153. // }
  3154. //
  3155. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3156. // }
  3157. //
  3158. // if schedule.ModeId == 3 {
  3159. //
  3160. // //扣减库存
  3161. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3162. //
  3163. // patient, _ := service.GetSfPatientById(tx, id)
  3164. // var over_count int64
  3165. // if schedule.ModeId == 1 {
  3166. // over_count = patient.HdCount
  3167. // }
  3168. // if schedule.ModeId == 2 {
  3169. // over_count = patient.HdfCount
  3170. // }
  3171. //
  3172. // if schedule.ModeId == 3 {
  3173. // over_count = patient.HdhpCount
  3174. // }
  3175. // if schedule.ModeId == 4 {
  3176. // over_count = patient.HpCount
  3177. // }
  3178. // if schedule.ModeId == 5 {
  3179. // over_count = patient.OtherCount
  3180. // }
  3181. // patientCountFlow := models.SfPatientCountFlow{
  3182. // PatientId: id,
  3183. // ModeId: schedule.ModeId,
  3184. // Count: 1,
  3185. // Status: 1,
  3186. // Ctime: time.Now().Unix(),
  3187. // Mtime: time.Now().Unix(),
  3188. // RecordDate: recordDate.Unix(),
  3189. // UserOrgId: adminUserInfo.Org.Id,
  3190. // Creater: adminUserInfo.AdminUser.Id,
  3191. // IsType: 3,
  3192. // OverCount: over_count,
  3193. // WarehouseOutId: 0,
  3194. // }
  3195. //
  3196. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3197. // }
  3198. // if schedule.ModeId == 4 {
  3199. //
  3200. // //扣减库存
  3201. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3202. //
  3203. // patient, _ := service.GetSfPatientById(tx, id)
  3204. // var over_count int64
  3205. // if schedule.ModeId == 1 {
  3206. // over_count = patient.HdCount
  3207. // }
  3208. // if schedule.ModeId == 2 {
  3209. // over_count = patient.HdfCount
  3210. // }
  3211. //
  3212. // if schedule.ModeId == 3 {
  3213. // over_count = patient.HdhpCount
  3214. // }
  3215. // if schedule.ModeId == 4 {
  3216. // over_count = patient.HpCount
  3217. // }
  3218. // if schedule.ModeId == 5 {
  3219. // over_count = patient.OtherCount
  3220. // }
  3221. // patientCountFlow := models.SfPatientCountFlow{
  3222. // PatientId: id,
  3223. // ModeId: schedule.ModeId,
  3224. // Count: 1,
  3225. // Status: 1,
  3226. // Ctime: time.Now().Unix(),
  3227. // Mtime: time.Now().Unix(),
  3228. // RecordDate: recordDate.Unix(),
  3229. // UserOrgId: adminUserInfo.Org.Id,
  3230. // Creater: adminUserInfo.AdminUser.Id,
  3231. // IsType: 4,
  3232. // OverCount: over_count,
  3233. // WarehouseOutId: 0,
  3234. // }
  3235. //
  3236. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3237. // }
  3238. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3239. //
  3240. // //扣减库存
  3241. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3242. //
  3243. // patient, _ := service.GetSfPatientById(tx, id)
  3244. // var over_count int64
  3245. // if schedule.ModeId == 1 {
  3246. // over_count = patient.HdCount
  3247. // }
  3248. // if schedule.ModeId == 2 {
  3249. // over_count = patient.HdfCount
  3250. // }
  3251. //
  3252. // if schedule.ModeId == 3 {
  3253. // over_count = patient.HdhpCount
  3254. // }
  3255. // if schedule.ModeId == 4 {
  3256. // over_count = patient.HpCount
  3257. // }
  3258. // if schedule.ModeId == 5 {
  3259. // over_count = patient.OtherCount
  3260. // }
  3261. // patientCountFlow := models.SfPatientCountFlow{
  3262. // PatientId: id,
  3263. // ModeId: schedule.ModeId,
  3264. // Count: 1,
  3265. // Status: 1,
  3266. // Ctime: time.Now().Unix(),
  3267. // Mtime: time.Now().Unix(),
  3268. // RecordDate: recordDate.Unix(),
  3269. // UserOrgId: adminUserInfo.Org.Id,
  3270. // Creater: adminUserInfo.AdminUser.Id,
  3271. // IsType: 5,
  3272. // OverCount: over_count,
  3273. // WarehouseOutId: 0,
  3274. // }
  3275. //
  3276. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3277. // }
  3278. //
  3279. // tx.Commit()
  3280. // return
  3281. //}
  3282. }
  3283. func (c *DialysisAPIController) GetAllZone() {
  3284. adminUserInfo := c.GetMobileAdminUserInfo()
  3285. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3286. if err == nil {
  3287. c.ServeSuccessJSON(map[string]interface{}{
  3288. "zone": zone,
  3289. })
  3290. }
  3291. }
  3292. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3293. adminUserInfo := c.GetMobileAdminUserInfo()
  3294. page, _ := c.GetInt64("page", 1)
  3295. limit, _ := c.GetInt64("limit", 10)
  3296. schedulType, _ := c.GetInt64("schedul_type", 0)
  3297. startTime, _ := c.GetInt64("schedul_time", 0)
  3298. partitionType, _ := c.GetInt64("partition_type", 0)
  3299. keywords := c.GetString("keywords")
  3300. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3301. if err == nil {
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "schedule": dialysisSchedule,
  3304. })
  3305. }
  3306. return
  3307. }
  3308. // /m/api/dialysis/start [post]
  3309. // @param patient_id:int
  3310. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3311. // @param nurse:int 上机护士
  3312. // @param bed:int 床位号
  3313. func (this *DialysisAPIController) StartDialysis() {
  3314. patientID, _ := this.GetInt64("patient_id")
  3315. recordDateStr := this.GetString("record_date")
  3316. nurseID, _ := this.GetInt64("start_nurse")
  3317. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3318. blood_drawing, _ := this.GetInt64("blood_drawing")
  3319. schedual_type, _ := this.GetInt64("schedual_type")
  3320. bedID, _ := this.GetInt64("bed")
  3321. start_time := this.GetString("start_time")
  3322. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3323. change_nurse, _ := this.GetInt64("change_nurse")
  3324. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3325. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3326. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3327. puncture_needle := this.GetString("puncture_needle")
  3328. puncture_way := this.GetString("puncture_way")
  3329. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3330. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3331. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3332. zone_id, _ := this.GetInt64("zone_id")
  3333. elecsign := this.GetString("url")
  3334. nuclein_date_str := this.GetString("nuclein_date_str")
  3335. schedule_remark := this.GetString("schedule_remark")
  3336. order_remark := this.GetString("order_remark")
  3337. catheter_operation := this.GetString("catheter_operation")
  3338. blood_flow_volume := this.GetString("blood_flow_volume")
  3339. dialysis_strainer := this.GetString("dialysis_strainer")
  3340. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3345. if parseStartDateErr != nil {
  3346. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3351. if parseErr != nil {
  3352. this.ErrorLog("时间解析失败:%v", parseErr)
  3353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. adminUserInfo := this.GetMobileAdminUserInfo()
  3357. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3358. if getPatientErr != nil {
  3359. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. } else if patient == nil {
  3363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3364. return
  3365. }
  3366. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3367. if getNurseErr != nil {
  3368. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. return
  3371. } else if nurse == nil {
  3372. this.ErrorLog("护士不存在")
  3373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3374. return
  3375. }
  3376. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3377. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3378. if getDeviceNumberErr != nil {
  3379. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3381. return
  3382. } else if deviceNumber == nil {
  3383. this.ErrorLog("床位号不存在")
  3384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3385. return
  3386. }
  3387. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3388. if getRecordErr != nil {
  3389. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. } else if dialysisRecord != nil {
  3393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3394. return
  3395. }
  3396. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3397. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3398. timeLayout := "2006-01-02 15:04:05"
  3399. loc, _ := time.LoadLocation("Local")
  3400. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3401. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3402. schedulestartTime := theStartTime.Unix()
  3403. scheduleendTime := theEndTime.Unix()
  3404. var theNucleinDate int64
  3405. timeLayoutOne := "2006-01-02"
  3406. if len(nuclein_date_str) > 0 {
  3407. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3408. if err != nil {
  3409. utils.ErrorLog(err.Error())
  3410. }
  3411. theNucleinDate = theTime.Unix()
  3412. }
  3413. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3414. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3415. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3416. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3417. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3418. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3419. if record.ID == 0 {
  3420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3421. return
  3422. }
  3423. advices, _ := service.GetDialysisPrescriptionDoctorAdviceList(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3424. if len(advices) == 0 {
  3425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3426. return
  3427. }
  3428. }
  3429. //查询该床位是否有人用了
  3430. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3431. if err == gorm.ErrRecordNotFound { //空床位
  3432. // 修改了床位逻辑
  3433. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3434. if daySchedule.ID > 0 {
  3435. daySchedule.PartitionId = deviceNumber.ZoneID
  3436. daySchedule.BedId = bedID
  3437. daySchedule.ScheduleType = schedual_type
  3438. daySchedule.UpdatedTime = time.Now().Unix()
  3439. xtSchedule := models.Schedule{
  3440. PartitionId: deviceNumber.ZoneID,
  3441. BedId: bedID,
  3442. ScheduleType: schedual_type,
  3443. UpdatedTime: time.Now().Unix(),
  3444. }
  3445. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3446. if err != nil {
  3447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3448. return
  3449. }
  3450. }
  3451. } else if err == nil {
  3452. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3453. if order.ID > 0 { //该机位被其他人占用了
  3454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3455. return
  3456. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3457. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3458. if daySchedule.ID > 0 {
  3459. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3460. if err != nil {
  3461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3462. return
  3463. }
  3464. }
  3465. }
  3466. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3468. return
  3469. }
  3470. //else if order.ID == 0 { //该床位没被占用
  3471. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3472. // if daySchedule.ID > 0 {
  3473. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3474. // //daySchedule.BedId = bedID
  3475. // //daySchedule.ScheduleType = schedual_type
  3476. // //daySchedule.UpdatedTime = time.Now().Unix()
  3477. // //err := service.UpdateSchedule(&daySchedule)
  3478. // xtSchedule := models.Schedule{
  3479. // PartitionId: deviceNumber.ZoneID,
  3480. // BedId: bedID,
  3481. // ScheduleType: schedual_type,
  3482. // UpdatedTime: time.Now().Unix(),
  3483. // }
  3484. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3485. // if err != nil {
  3486. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3487. // return
  3488. // }
  3489. // }
  3490. //}
  3491. //}
  3492. } else if err != nil {
  3493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3494. return
  3495. }
  3496. // 查询信息规挡的设置天数
  3497. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3498. if infor.ID > 0 && infor.WeekDay > 0 {
  3499. var cha_time int64
  3500. timeNowStr := time.Now().Format("2006-01-02")
  3501. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3502. //今日的日期减去设置的日期
  3503. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3504. if cha_time >= recordDate.Unix() {
  3505. //查询审核是否允许
  3506. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3507. //申请状态不允许的情况 拒绝修改
  3508. if infor.ApplicationStatus != 1 {
  3509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3510. return
  3511. }
  3512. }
  3513. }
  3514. dialysisRecord = &models.DialysisOrder{
  3515. DialysisDate: recordDate.Unix(),
  3516. UserOrgId: adminUserInfo.Org.Id,
  3517. PatientId: patientID,
  3518. Stage: 1,
  3519. BedID: bedID,
  3520. StartNurse: nurseID,
  3521. Status: 1,
  3522. StartTime: startDate.Unix(),
  3523. CreatedTime: time.Now().Unix(),
  3524. UpdatedTime: time.Now().Unix(),
  3525. PunctureNurse: puncture_nurse,
  3526. Creator: adminUserInfo.AdminUser.Id,
  3527. Modifier: adminUserInfo.AdminUser.Id,
  3528. SchedualType: schedual_type,
  3529. WashpipeNurse: washpipe_nurse,
  3530. ChangeNurse: change_nurse,
  3531. DifficultPunctureNurse: difficult_puncture_nurse,
  3532. NewFistulaNurse: new_fistula_nurse,
  3533. ZoneId: zone_id,
  3534. QualityNurseId: quality_nurse_id,
  3535. PunctureNeedle: puncture_needle,
  3536. PunctureWay: puncture_way,
  3537. DialysisIrrigation: dialysis_irrigation,
  3538. DialysisDialyszers: dialysis_dialyszers,
  3539. BloodAccessId: blood_access_id,
  3540. Url: elecsign,
  3541. NucleinDate: theNucleinDate,
  3542. ScheduleRemark: schedule_remark,
  3543. OrderRemark: order_remark,
  3544. CatheterOperation: catheter_operation,
  3545. BloodFlowVolume: blood_flow_volume,
  3546. BloodDrawing: blood_drawing,
  3547. DialysisStrainer: dialysis_strainer,
  3548. }
  3549. //查询该床位是否有人用了
  3550. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3551. if errorscode == gorm.ErrRecordNotFound {
  3552. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3553. finish := models.XtDialysisFinish{
  3554. IsFinish: 1,
  3555. UserOrgId: adminUserInfo.Org.Id,
  3556. Status: 1,
  3557. Ctime: time.Now().Unix(),
  3558. Mtime: 0,
  3559. Module: 6,
  3560. RecordDate: schedulestartTime,
  3561. Sourse: 1,
  3562. PatientId: patientID,
  3563. }
  3564. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3565. if dialysisFinish.ID == 0 {
  3566. service.CreateDialysisFinish(finish)
  3567. }
  3568. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3569. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3570. //统计该患者总次数
  3571. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3572. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3573. }
  3574. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3575. //统计该患者总次数
  3576. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3577. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3578. }
  3579. redis := service.RedisClient()
  3580. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3581. redis.Set(key, "", time.Second)
  3582. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3583. //清空key 值
  3584. redis.Set(keyOne, "", time.Second)
  3585. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3586. //清空key 值
  3587. redis.Set(keyTwo, "", time.Second)
  3588. if createErr != nil {
  3589. this.ErrorLog("上机失败:%v", createErr)
  3590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3591. return
  3592. }
  3593. }
  3594. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3595. var tempdispose string
  3596. // 只针对中能建
  3597. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3598. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3599. }
  3600. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3601. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3602. }
  3603. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3604. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3605. //}
  3606. var ultrafiltration_rate float64
  3607. var ultrafiltration_rate_one string
  3608. var replacement_rate float64
  3609. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3610. //后期预增脱水量
  3611. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3612. if prescription.ID > 0 {
  3613. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3614. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3615. 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
  3616. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3617. }
  3618. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3619. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3620. }
  3621. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3622. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3623. }
  3624. //针对医师汇
  3625. if adminUserInfo.Org.Id == 10121 {
  3626. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3627. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3628. }
  3629. //针对通道
  3630. if adminUserInfo.Org.Id == 10234 {
  3631. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3632. }
  3633. //针对监利大垸医院
  3634. if template.TemplateId == 41 {
  3635. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3636. }
  3637. //针对肇庆三鹤血液透析中心
  3638. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3639. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3640. }
  3641. if adminUserInfo.Org.Id == 10469 {
  3642. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3643. }
  3644. if adminUserInfo.Org.Id == 10667 {
  3645. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3646. }
  3647. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3648. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3649. }
  3650. // 只针对方济医院
  3651. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3652. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3653. ultrafiltration_rate = value
  3654. }
  3655. //针对
  3656. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3657. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3658. ultrafiltration_rate = ultrafiltration_rate / 1000
  3659. }
  3660. if adminUserInfo.Org.Id == 10551 {
  3661. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3662. ultrafiltration_rate = ultrafiltration_rate / 1000
  3663. }
  3664. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3665. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3666. ultrafiltration_rate = ultrafiltration_rate / 1000
  3667. }
  3668. if adminUserInfo.Org.Id == 10580 {
  3669. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3670. ultrafiltration_rate = ultrafiltration_rate / 1000
  3671. }
  3672. if adminUserInfo.Org.Id == 10629 {
  3673. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3674. ultrafiltration_rate = ultrafiltration_rate / 1000
  3675. }
  3676. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3677. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3678. ultrafiltration_rate = ultrafiltration_rate / 1000
  3679. }
  3680. if adminUserInfo.Org.Id == 10751 {
  3681. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3682. ultrafiltration_rate = ultrafiltration_rate / 1000
  3683. }
  3684. if adminUserInfo.Org.Id == 10768 {
  3685. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3686. ultrafiltration_rate = ultrafiltration_rate / 1000
  3687. }
  3688. if adminUserInfo.Org.Id == 10667 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3690. ultrafiltration_rate = ultrafiltration_rate / 1000
  3691. }
  3692. if adminUserInfo.Org.Id == 10693 {
  3693. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3694. ultrafiltration_rate = ultrafiltration_rate
  3695. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3696. }
  3697. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3698. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3699. ultrafiltration_rate = ultrafiltration_rate
  3700. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3701. }
  3702. if adminUserInfo.Org.Id == 10206 {
  3703. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3704. ultrafiltration_rate = ultrafiltration_rate
  3705. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3706. }
  3707. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3708. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3709. ultrafiltration_rate = ultrafiltration_rate
  3710. }
  3711. if adminUserInfo.Org.Id == 10702 {
  3712. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3713. ultrafiltration_rate = ultrafiltration_rate / 1000
  3714. }
  3715. if adminUserInfo.Org.Id == 10752 {
  3716. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3717. ultrafiltration_rate = ultrafiltration_rate / 1000
  3718. }
  3719. if adminUserInfo.Org.Id == 10723 {
  3720. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3721. ultrafiltration_rate = ultrafiltration_rate / 1000
  3722. }
  3723. if adminUserInfo.Org.Id == 10721 {
  3724. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3725. ultrafiltration_rate = ultrafiltration_rate / 1000
  3726. }
  3727. if adminUserInfo.Org.Id == 10766 {
  3728. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3729. ultrafiltration_rate = ultrafiltration_rate / 1000
  3730. }
  3731. if adminUserInfo.Org.Id == 10757 {
  3732. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3733. ultrafiltration_rate = ultrafiltration_rate / 1000
  3734. }
  3735. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3736. if prescription.ModeId == 2 {
  3737. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3738. if totalMin == 0 {
  3739. totalMin = 240
  3740. }
  3741. if prescription.ReplacementTotal == 0 {
  3742. prescription.ReplacementTotal = 15
  3743. }
  3744. //乘10 除10是为了保留一位小数
  3745. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3746. }
  3747. }
  3748. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10768 {
  3749. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3750. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3751. if totalMin == 0 {
  3752. totalMin = 240
  3753. }
  3754. if prescription.DisplaceLiquiValue == 0 {
  3755. prescription.DisplaceLiquiValue = 15
  3756. }
  3757. //乘10 除10是为了保留一位小数
  3758. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3759. }
  3760. }
  3761. if adminUserInfo.Org.Id == 10752 {
  3762. if prescription.ModeId == 2 {
  3763. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3764. if totalMin == 0 {
  3765. totalMin = 240
  3766. }
  3767. if prescription.ReplacementTotal == 0 {
  3768. prescription.ReplacementTotal = 15
  3769. }
  3770. //乘10 除10是为了保留一位小数
  3771. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3772. }
  3773. }
  3774. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3775. if prescription.ModeId == 2 {
  3776. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3777. if totalMin == 0 {
  3778. totalMin = 240
  3779. }
  3780. if prescription.DisplaceLiquiValue == 0 {
  3781. prescription.ReplacementTotal = 32
  3782. }
  3783. //乘10 除10是为了保留一位小数
  3784. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3785. }
  3786. }
  3787. }
  3788. }
  3789. if adminUserInfo.Org.Id == 10172 {
  3790. if prescription.ID == 0 {
  3791. if prescription.ModeId == 2 {
  3792. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3793. if totalMin == 0 {
  3794. totalMin = 240
  3795. }
  3796. if prescription.ReplacementTotal == 0 {
  3797. prescription.ReplacementTotal = 15
  3798. }
  3799. //乘10 除10是为了保留一位小数
  3800. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3801. }
  3802. }
  3803. }
  3804. record := models.MonitoringRecord{
  3805. UserOrgId: adminUserInfo.Org.Id,
  3806. PatientId: patientID,
  3807. DialysisOrderId: dialysisRecord.ID,
  3808. MonitoringDate: schedulestartTime,
  3809. OperateTime: startDate.Unix(),
  3810. // MonitoringTime: recordTime,
  3811. MonitoringNurse: nurseID,
  3812. Dispose: tempdispose,
  3813. UltrafiltrationRate: ultrafiltration_rate,
  3814. UltrafiltrationVolume: 0,
  3815. Status: 1,
  3816. CreatedTime: time.Now().Unix(),
  3817. UpdatedTime: time.Now().Unix(),
  3818. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3819. ReplacementRate: replacement_rate,
  3820. }
  3821. //只针对广慈医院
  3822. 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 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10757 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  3823. // 查询病人是否有透前评估数据
  3824. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3825. //如果有数据就插入
  3826. if errcode == nil {
  3827. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3828. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3829. record.BreathingRate = befor.BreathingRate
  3830. record.PulseFrequency = befor.PulseFrequency
  3831. record.Temperature = befor.Temperature
  3832. }
  3833. }
  3834. //孝昌
  3835. if adminUserInfo.Org.Id == 10693 {
  3836. // 查询病人是否有透前评估数据
  3837. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3838. //如果有数据就插入
  3839. if errcode == nil {
  3840. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3841. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3842. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3843. record.BreathingRate = befor.BreathingRate
  3844. }
  3845. }
  3846. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3847. if newdialysisRecord.ID > 0 {
  3848. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3849. record.Temperature = 36.5
  3850. record.ArterialPressure = -100
  3851. record.DialysateTemperature = 36.5
  3852. record.Conductivity = 14
  3853. record.BreathingRate = "20"
  3854. record.VenousPressure = 80
  3855. record.TransmembranePressure = 60
  3856. record.Dispose = catheter_operation
  3857. }
  3858. //针对新化博翔
  3859. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3860. record.BloodOxygenSaturation = "99"
  3861. record.Conductivity = 14
  3862. record.DialysateTemperature = 36.5
  3863. record.BreathingRate = "20"
  3864. }
  3865. //针对兰溪人民医院的需求
  3866. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3867. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3868. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3869. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3870. record.Temperature = befor.Temperature
  3871. record.PulseFrequency = befor.PulseFrequency
  3872. record.BreathingRate = befor.BreathingRate
  3873. }
  3874. //针对乐山友谊医院的需求
  3875. if adminUserInfo.Org.Id == 10677 {
  3876. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3877. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3878. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3879. record.Temperature = befor.Temperature
  3880. record.PulseFrequency = befor.PulseFrequency
  3881. record.BreathingRate = befor.BreathingRate
  3882. }
  3883. //新化博翔
  3884. if adminUserInfo.Org.Id == 10447 {
  3885. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3886. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3887. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3888. record.BreathingRate = befor.BreathingRate
  3889. }
  3890. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3891. record.PulseFrequency = 80
  3892. record.Temperature = 36.5
  3893. }
  3894. //诊断灵山圣康
  3895. if adminUserInfo.Org.Id == 10375 {
  3896. record.Conductivity = 13.8
  3897. record.DialysateTemperature = 37
  3898. record.DialysateFlow = 500
  3899. record.BloodFlowVolume = 200
  3900. record.BreathingRate = "18"
  3901. record.SodiumConcentration = 140
  3902. }
  3903. //江成肾病医院
  3904. if adminUserInfo.Org.Id == 10517 {
  3905. record.SodiumConcentration = 138
  3906. record.DialysateTemperature = 36.5
  3907. }
  3908. //濉溪杏康血液透析中心
  3909. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3910. record.BloodFlowVolume = prescription.BloodFlowVolume
  3911. }
  3912. //胶州少海医院
  3913. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3914. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3915. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3916. record.BreathingRate = befor.BreathingRate
  3917. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3918. record.Temperature = befor.Temperature
  3919. record.PulseFrequency = befor.PulseFrequency
  3920. }
  3921. if adminUserInfo.Org.Id != 10683 {
  3922. err = service.CreateMonitor(&record)
  3923. }
  3924. //记录日志
  3925. byterequest, _ := json.Marshal(record)
  3926. monitorRecordLog := models.XtMonitorRecordLog{
  3927. RecordDate: record.MonitoringDate,
  3928. PatientId: record.PatientId,
  3929. Module: 1,
  3930. AdminUserId: adminUserInfo.AdminUser.Id,
  3931. Ctime: time.Now().Unix(),
  3932. Mtime: 0,
  3933. Status: 1,
  3934. UserOrgId: record.UserOrgId,
  3935. ErrLog: string(byterequest),
  3936. Source: "执行上机时新增监测",
  3937. }
  3938. service.CreateMonitorRecordLog(monitorRecordLog)
  3939. finish := models.XtDialysisFinish{
  3940. IsFinish: 1,
  3941. UserOrgId: adminUserInfo.Org.Id,
  3942. Status: 1,
  3943. Ctime: time.Now().Unix(),
  3944. Mtime: 0,
  3945. Module: 7,
  3946. RecordDate: schedulestartTime,
  3947. Sourse: 1,
  3948. PatientId: patientID,
  3949. }
  3950. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3951. if dialysisFinish.ID == 0 {
  3952. service.CreateDialysisFinish(finish)
  3953. }
  3954. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3955. redis := service.RedisClient()
  3956. //清空key 值
  3957. redis.Set(key, "", time.Second)
  3958. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3959. redis.Set(keyOne, "", time.Second)
  3960. defer redis.Close()
  3961. if err != nil {
  3962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3963. return
  3964. }
  3965. }
  3966. go func() {
  3967. ssoDomain := beego.AppConfig.String("call_domain")
  3968. api := ssoDomain + "/index/uppatient"
  3969. values := make(url.Values)
  3970. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3971. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3972. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3973. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3974. http.PostForm(api, values)
  3975. }()
  3976. this.ServeSuccessJSON(map[string]interface{}{
  3977. "dialysis_order": newdialysisRecord,
  3978. "monitor": record,
  3979. })
  3980. return
  3981. }
  3982. func (c *DialysisAPIController) PostSolution() {
  3983. id, _ := c.GetInt64("patient", 0)
  3984. recordDateStr := c.GetString("record_date")
  3985. if id <= 0 {
  3986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3987. return
  3988. }
  3989. adminUserInfo := c.GetMobileAdminUserInfo()
  3990. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3991. if patient.ID == 0 {
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3993. return
  3994. }
  3995. if len(recordDateStr) == 0 {
  3996. recordDateStr = time.Now().Format("2006-01-02")
  3997. }
  3998. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3999. if parseDateErr != nil {
  4000. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4002. return
  4003. }
  4004. mode_id, _ := c.GetInt64("mode_id", 0)
  4005. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  4006. dialyzer, _ := c.GetInt64("dialyzer", 0)
  4007. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  4008. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  4009. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  4010. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  4011. replacement_way, _ := c.GetInt64("replacement_way", 0)
  4012. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  4013. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  4014. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  4015. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  4016. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  4017. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  4018. kalium, _ := c.GetFloat("kalium", 0)
  4019. sodium, _ := c.GetFloat("sodium", 0)
  4020. calcium, _ := c.GetFloat("calcium", 0)
  4021. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  4022. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  4023. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  4024. glucose, _ := c.GetFloat("glucose", 0)
  4025. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  4026. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  4027. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  4028. conductivity, _ := c.GetFloat("conductivity", 0)
  4029. remark := c.GetString("remark")
  4030. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  4031. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  4032. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  4033. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  4034. body_fluid, _ := c.GetInt64("body_fluid", 0)
  4035. special_medicine, _ := c.GetInt64("special_medicine", 0)
  4036. special_medicine_other := c.GetString("special_medicine_other")
  4037. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4038. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4039. blood_access, _ := c.GetInt64("blood_access", 0)
  4040. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4041. body_fluid_other := c.GetString("body_fluid_other")
  4042. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4043. niprocart, _ := c.GetInt64("niprocart", 0)
  4044. jms, _ := c.GetInt64("jms", 0)
  4045. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4046. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4047. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4048. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4049. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4050. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4051. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4052. injector, _ := c.GetInt64("injector", 0)
  4053. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4054. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4055. safe_package, _ := c.GetInt64("package", 0)
  4056. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4057. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4058. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4059. blood := c.GetString("blood")
  4060. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4061. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4062. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4063. displace_speed := c.GetString("displace_speed")
  4064. illness, _ := c.GetInt64("illness")
  4065. amylaceum := c.GetString("amylaceum")
  4066. single_time := c.GetString("single_time")
  4067. single_water := c.GetString("single_water")
  4068. replacement_flow := c.GetString("replacement_flow")
  4069. plasma_separator := c.GetString("plasma_separator")
  4070. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4071. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4072. oxygen_flow := c.GetString("oxygen_flow")
  4073. oxygen_time := c.GetString("oxygen_time")
  4074. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4075. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4076. puncture_needle := c.GetString("puncture_needle")
  4077. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4078. epo := c.GetString("epo")
  4079. epo_count, _ := c.GetFloat("epo_count", 0)
  4080. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4081. pre_impulse := c.GetString("pre_impulse")
  4082. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4083. admin_user_id, _ := c.GetInt64("admin_user_id")
  4084. is_water := c.GetString("is_water")
  4085. add_amount, _ := c.GetFloat("add_amount")
  4086. reduce_amount, _ := c.GetFloat("reduce_amount")
  4087. prescribing_number, _ := c.GetFloat("prescribing_number")
  4088. treatment_remark := c.GetString("treatment_remark")
  4089. prescription_sodium := c.GetString("prescription_sodium")
  4090. start_sodium := c.GetString("start_sodium")
  4091. sodium_curve := c.GetString("sodium_curve")
  4092. var is_war int64
  4093. if is_water == "是" {
  4094. is_war = 1
  4095. }
  4096. if is_water == "否" {
  4097. is_war = 2
  4098. }
  4099. if is_water == "请选择" {
  4100. is_war = 0
  4101. }
  4102. drhy_water := c.GetString("drhy_water")
  4103. dry_water_hour := c.GetString("dry_water_hour")
  4104. water_machine := c.GetString("water_machine")
  4105. dialysis_remark := c.GetString("dialysis_remark")
  4106. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4107. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4108. prescription_water, _ := c.GetFloat("prescription_water")
  4109. dialysis_strainer := c.GetString("dialysis_strainer")
  4110. chaptalization := c.GetString("chaptalization")
  4111. washing_time := c.GetString("washing_time")
  4112. warsh_count := c.GetString("warsh_count")
  4113. blood_access_part_id := c.GetString("blood_access_part_id")
  4114. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4115. dialyzate := c.GetString("dialyzate")
  4116. first_super := c.GetString("first_super")
  4117. is_sequential := c.GetString("is_sequential")
  4118. sterilization_water := c.GetString("sterilization_water")
  4119. five_glucose := c.GetString("five_glucose")
  4120. fifty_glucose := c.GetString("fifty_glucose")
  4121. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  4122. calcium_gluconate := c.GetString("calcium_gluconate")
  4123. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  4124. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  4125. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  4126. new_sty := c.GetString("new_sty")
  4127. var fisrt_sup int64
  4128. if first_super == "是" {
  4129. fisrt_sup = 1
  4130. }
  4131. if first_super == "否" {
  4132. fisrt_sup = 2
  4133. }
  4134. if first_super == "请选择" {
  4135. fisrt_sup = 0
  4136. }
  4137. var is_sequen int64
  4138. if is_sequential == "是" {
  4139. is_sequen = 1
  4140. }
  4141. if is_sequential == "否" {
  4142. is_sequen = 2
  4143. }
  4144. if is_sequential == "请选择" {
  4145. is_sequen = 0
  4146. }
  4147. conduct := c.GetString("conduct")
  4148. if mode_id > 0 {
  4149. var str string
  4150. //查找该机构用的是什么透析器
  4151. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4152. if filedConfig.ID > 0 {
  4153. str = dialyzerPerfusionApparatus
  4154. } else {
  4155. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4156. }
  4157. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4158. }
  4159. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4160. //
  4161. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4162. // if appRole.UserType == 3 {
  4163. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4164. // if getPermissionErr != nil {
  4165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4166. // return
  4167. // } else if headNursePermission == nil {
  4168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4169. // return
  4170. // }
  4171. // }
  4172. //}
  4173. // 查询信息规挡的设置天数
  4174. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4175. if infor.ID > 0 && infor.WeekDay > 0 {
  4176. var cha_time int64
  4177. timeNowStr := time.Now().Format("2006-01-02")
  4178. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4179. //今日的日期减去设置的日期
  4180. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4181. if cha_time >= recordDate.Unix() {
  4182. //查询审核是否允许
  4183. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4184. //申请状态不允许的情况 拒绝修改
  4185. if infor.ApplicationStatus != 1 {
  4186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4187. return
  4188. }
  4189. }
  4190. }
  4191. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4192. var dialysis_dialyszers_id int64
  4193. var dialysis_strainer_id int64
  4194. var dialysis_irrigation_id int64
  4195. if len(goodList) > 0 {
  4196. for _, item := range goodList {
  4197. if item.SpecificationName == dialysis_dialyszers {
  4198. dialysis_dialyszers_id = item.ID
  4199. }
  4200. if item.SpecificationName == dialysis_irrigation {
  4201. dialysis_irrigation_id = item.ID
  4202. }
  4203. if item.SpecificationName == dialysis_strainer {
  4204. dialysis_strainer_id = item.ID
  4205. }
  4206. }
  4207. }
  4208. prescription := models.DialysisPrescription{
  4209. UserOrgId: adminUserInfo.Org.Id,
  4210. PatientId: id,
  4211. RecordDate: recordDate.Unix(),
  4212. ModeId: mode_id,
  4213. DialysisDuration: dialysis_duration,
  4214. Dialyzer: dialyzer,
  4215. PerfusionApparatus: perfusion_apparatus,
  4216. BloodFlowVolume: blood_flow_volume,
  4217. DewaterAmount: dewater_amount,
  4218. DisplaceLiqui: displace_liqui,
  4219. ReplacementWay: replacement_way,
  4220. Anticoagulant: anticoagulant,
  4221. AnticoagulantShouji: anticoagulant_shouji,
  4222. AnticoagulantWeichi: anticoagulant_weichi,
  4223. AnticoagulantZongliang: anticoagulant_zongliang,
  4224. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4225. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4226. Kalium: kalium,
  4227. Sodium: sodium,
  4228. Calcium: calcium,
  4229. Bicarbonate: bicarbonate,
  4230. Glucose: glucose,
  4231. // DryWeight: dry_weight,
  4232. DialysateFlow: dialysate_flow,
  4233. DialysateTemperature: dialysate_temperature,
  4234. Conductivity: conductivity,
  4235. Remark: remark,
  4236. Status: 1,
  4237. CreatedTime: time.Now().Unix(),
  4238. UpdatedTime: time.Now().Unix(),
  4239. DialysisDurationMinute: dialysisDurationMinute,
  4240. DialysisDurationHour: dialysisDurationHour,
  4241. TargetUltrafiltration: targetUltrafiltration,
  4242. DialysateFormulation: dialysateFormulation,
  4243. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4244. BodyFluid: body_fluid,
  4245. SpecialMedicine: special_medicine,
  4246. SpecialMedicineOther: special_medicine_other,
  4247. DisplaceLiquiPart: displace_liqui_part,
  4248. DisplaceLiquiValue: displace_liqui_value,
  4249. BloodAccess: blood_access,
  4250. Ultrafiltration: ultrafiltration,
  4251. BodyFluidOther: body_fluid_other,
  4252. ReplacementTotal: replacement_total,
  4253. Niprocart: niprocart,
  4254. Jms: jms,
  4255. FistulaNeedleSet: fistula_needle_set,
  4256. FistulaNeedleSet16: fistula_needle_set_16,
  4257. Hemoperfusion: hemoperfusion,
  4258. DialyserSterilised: dialyser_sterilised,
  4259. Filtryzer: filtryzer,
  4260. TargetKtv: target_ktv,
  4261. Dialyzers: dialyzers,
  4262. Injector: injector,
  4263. Bloodlines: bloodlines,
  4264. TubingHemodialysis: tubing_hemodialysis,
  4265. Package: safe_package,
  4266. ALiquid: a_liquid,
  4267. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4268. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4269. Blood: blood,
  4270. DialysisDialyszers: dialysis_dialyszers,
  4271. DialysisIrrigation: dialysis_irrigation,
  4272. AntioxidantCommodityName: antioxidant_commodity_name,
  4273. DisplaceSpeed: displace_speed,
  4274. Illness: illness,
  4275. Amylaceum: amylaceum,
  4276. SingleWater: single_water,
  4277. SingleTime: single_time,
  4278. ReplacementFlow: replacement_flow,
  4279. PlasmaSeparator: plasma_separator,
  4280. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4281. OxygenUptake: oxygen_uptake,
  4282. OxygenTime: oxygen_time,
  4283. OxygenFlow: oxygen_flow,
  4284. HemodialysisPipelines: hemodialysis_pipelines,
  4285. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4286. PunctureNeedle: puncture_needle,
  4287. PunctureNeedleCount: puncture_needle_count,
  4288. Epo: epo,
  4289. EpoCount: epo_count,
  4290. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4291. PreImpulse: impulse,
  4292. AdminUserId: admin_user_id,
  4293. IsWater: is_war,
  4294. DrhyWater: drhy_water,
  4295. DryWaterHour: dry_water_hour,
  4296. WaterMachine: water_machine,
  4297. AddAmount: add_amount,
  4298. ReduceAmount: reduce_amount,
  4299. DialysisRemark: dialysis_remark,
  4300. PrescribingNumber: prescribing_number,
  4301. PrescriptionSodium: prescription_sodium,
  4302. StartSodium: start_sodium,
  4303. SodiumCurve: sodium_curve,
  4304. TreatmentRemark: treatment_remark,
  4305. DialysisFluidFlow: dialysis_fluid_flow,
  4306. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4307. PrescriptionWater: prescription_water,
  4308. DialysisStrainer: dialysis_strainer,
  4309. Chaptalization: chaptalization,
  4310. WashingTime: washing_time,
  4311. WarshCount: warsh_count,
  4312. BloodAccessPartId: blood_access_part_id,
  4313. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4314. Dialyzate: dialyzate,
  4315. DialysisDialyszersId: dialysis_dialyszers_id,
  4316. DialysisIrrigationId: dialysis_irrigation_id,
  4317. DialysisStrainerId: dialysis_strainer_id,
  4318. FirstSuper: fisrt_sup,
  4319. IsSequential: is_sequen,
  4320. Conduct: conduct,
  4321. SterilizationWater: sterilization_water,
  4322. FiveGlucose: five_glucose,
  4323. FiftyGlucose: fifty_glucose,
  4324. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4325. CalciumGluconate: calcium_gluconate,
  4326. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4327. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4328. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4329. NewSty: new_sty,
  4330. }
  4331. if prescription.ModeId != 13 {
  4332. prescription.SterilizationWater = ""
  4333. prescription.FiveGlucose = ""
  4334. prescription.FiftyGlucose = ""
  4335. prescription.MagnesiumSulfateInjection = ""
  4336. prescription.CalciumGluconate = ""
  4337. prescription.FivePotassiumChlorideInjection = ""
  4338. prescription.TenPotassiumChlorideInjection = ""
  4339. prescription.FiveSodiumBicarbonateInjection = ""
  4340. prescription.NewSty = ""
  4341. }
  4342. if adminUserInfo.Org.Id == 10721 {
  4343. if prescription.ModeId == 2 {
  4344. if prescription.ReplacementTotal == 0 {
  4345. prescription.ReplacementTotal = 15
  4346. }
  4347. }
  4348. }
  4349. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4350. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4351. if prescription.ReplacementTotal == 0 {
  4352. prescription.ReplacementTotal = 15
  4353. }
  4354. }
  4355. }
  4356. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4357. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4358. //
  4359. if appRole.UserType == 2 || appRole.UserType == 1 {
  4360. prescription_doctor = adminUserInfo.AdminUser.Id
  4361. prescription.PrescriptionDoctor = prescription_doctor
  4362. }
  4363. if dialysisPrescription.ID == 0 { //新增
  4364. prescription.Creater = adminUserInfo.AdminUser.Id
  4365. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4366. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4367. }
  4368. } else { //修改
  4369. if dialysisPrescription.Creater == 0 {
  4370. prescription.Creater = adminUserInfo.AdminUser.Id
  4371. } else {
  4372. prescription.Creater = dialysisPrescription.Creater
  4373. if adminUserInfo.Org.Id == 9882 {
  4374. if appRole.UserType == 2 || appRole.UserType == 1 {
  4375. prescription.Creater = adminUserInfo.AdminUser.Id
  4376. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4377. }
  4378. }
  4379. }
  4380. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4381. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4382. }
  4383. //if/**/
  4384. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4385. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4386. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4387. // if getPermissionErr != nil {
  4388. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4389. // return
  4390. // } else if headNursePermission == nil {
  4391. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4392. // return
  4393. // }
  4394. //}
  4395. //prescription.Creater = dialysisPrescription.Creater
  4396. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4397. prescription.Modifier = adminUserInfo.AdminUser.Id
  4398. prescription.ID = dialysisPrescription.ID
  4399. }
  4400. solution := models.DialysisSolution{
  4401. RegistrarsId: adminUserInfo.AdminUser.Id,
  4402. UserOrgId: adminUserInfo.Org.Id,
  4403. Doctor: prescription_doctor,
  4404. PatientId: id,
  4405. ModeId: mode_id,
  4406. DialysisDuration: dialysis_duration,
  4407. PerfusionApparatus: perfusion_apparatus,
  4408. BloodFlowVolume: blood_flow_volume,
  4409. Dewater: dewater_amount,
  4410. DisplaceLiqui: displace_liqui,
  4411. ReplacementWay: replacement_way,
  4412. Anticoagulant: anticoagulant,
  4413. AnticoagulantShouji: anticoagulant_shouji,
  4414. AnticoagulantWeichi: anticoagulant_weichi,
  4415. AnticoagulantZongliang: anticoagulant_zongliang,
  4416. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4417. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4418. Kalium: kalium,
  4419. Sodium: sodium,
  4420. Calcium: calcium,
  4421. Bicarbonate: bicarbonate,
  4422. Glucose: glucose,
  4423. // DryWeight: dry_weight,
  4424. DialysateFlow: dialysate_flow,
  4425. DialysateTemperature: dialysate_temperature,
  4426. Conductivity: conductivity,
  4427. Remark: remark,
  4428. Status: 1,
  4429. CreatedTime: time.Now().Unix(),
  4430. UpdatedTime: time.Now().Unix(),
  4431. DialysisDurationMinute: dialysisDurationMinute,
  4432. DialysisDurationHour: dialysisDurationHour,
  4433. TargetUltrafiltration: targetUltrafiltration,
  4434. DialysateFormulation: dialysateFormulation,
  4435. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4436. BodyFluid: body_fluid,
  4437. SpecialMedicine: special_medicine,
  4438. SpecialMedicineOther: special_medicine_other,
  4439. DisplaceLiquiPart: displace_liqui_part,
  4440. DisplaceLiquiValue: displace_liqui_value,
  4441. BloodAccess: blood_access,
  4442. Ultrafiltration: ultrafiltration,
  4443. BodyFluidOther: body_fluid_other,
  4444. ReplacementTotal: replacement_total,
  4445. TargetKtv: target_ktv,
  4446. DialysisDialyszers: dialysis_dialyszers,
  4447. DialysisIrrigation: dialysis_irrigation,
  4448. HemodialysisPipelines: hemodialysis_pipelines,
  4449. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4450. PunctureNeedle: puncture_needle,
  4451. PunctureNeedleCount: puncture_needle_count,
  4452. Epo: epo,
  4453. EpoCount: epo_count,
  4454. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4455. PreImpulse: impulse,
  4456. SolutionStatus: 1,
  4457. DialysisRemark: dialysis_remark,
  4458. PrescribingNumber: prescribing_number,
  4459. PrescriptionSodium: prescription_sodium,
  4460. StartSodium: start_sodium,
  4461. SodiumCurve: sodium_curve,
  4462. TreatmentRemark: treatment_remark,
  4463. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4464. DialysisFluidFlow: dialysis_fluid_flow,
  4465. PrescriptionWater: prescription_water,
  4466. DialysisStrainer: dialysis_strainer,
  4467. Chaptalization: chaptalization,
  4468. WashingTime: washing_time,
  4469. WarshCount: warsh_count,
  4470. BloodAccessPartId: blood_access_part_id,
  4471. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4472. Dialyzate: dialyzate,
  4473. DialysisDialyszersId: dialysis_dialyszers_id,
  4474. DialysisIrrigationId: dialysis_irrigation_id,
  4475. DialysisStrainerId: dialysis_strainer_id,
  4476. FirstSuper: fisrt_sup,
  4477. IsSequential: is_sequen,
  4478. Conduct: conduct,
  4479. SterilizationWater: sterilization_water,
  4480. FiveGlucose: five_glucose,
  4481. FiftyGlucose: fifty_glucose,
  4482. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4483. CalciumGluconate: calcium_gluconate,
  4484. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4485. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4486. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4487. NewSty: new_sty,
  4488. }
  4489. if prescription.ModeId != 13 {
  4490. prescription.SterilizationWater = ""
  4491. prescription.FiveGlucose = ""
  4492. prescription.FiftyGlucose = ""
  4493. prescription.MagnesiumSulfateInjection = ""
  4494. prescription.CalciumGluconate = ""
  4495. prescription.FivePotassiumChlorideInjection = ""
  4496. prescription.TenPotassiumChlorideInjection = ""
  4497. prescription.FiveSodiumBicarbonateInjection = ""
  4498. prescription.NewSty = ""
  4499. }
  4500. //针对河间咸的
  4501. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4502. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4503. solution.DisplaceLiquiPart = 0
  4504. solution.DisplaceLiquiValue = 0
  4505. }
  4506. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4507. prescription.DisplaceLiquiPart = 0
  4508. prescription.DisplaceLiquiValue = 0
  4509. }
  4510. }
  4511. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4512. if solution.PrescribingNumber == 0 {
  4513. solution.PrescribingNumber = 1
  4514. }
  4515. if prescription.PrescribingNumber == 0 {
  4516. prescription.PrescribingNumber = 1
  4517. }
  4518. if solution.PrescribingNumber == 0 && id == 14682 {
  4519. solution.PrescribingNumber = 2
  4520. }
  4521. if solution.PrescribingNumber == 0 && id == 18560 {
  4522. solution.PrescribingNumber = 2
  4523. }
  4524. if prescription.PrescribingNumber == 0 && id == 14682 {
  4525. prescription.PrescribingNumber = 2
  4526. }
  4527. if prescription.PrescribingNumber == 0 && id == 18560 {
  4528. prescription.PrescribingNumber = 2
  4529. }
  4530. }
  4531. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4532. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4533. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4534. if len(monitorList) > 0 {
  4535. var ultrafiltration_rate float64
  4536. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4537. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4538. var replacement_rate float64
  4539. if adminUserInfo.Org.Id == 10721 {
  4540. //乘10 除10是为了保留一位小数
  4541. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4542. }
  4543. if adminUserInfo.Org.Id == 9478 {
  4544. //乘10 除10是为了保留一位小数
  4545. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4546. }
  4547. if adminUserInfo.Org.Id == 10766 {
  4548. //乘10 除10是为了保留一位小数
  4549. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4550. }
  4551. var firstOpeateTime = monitorList[0].OperateTime
  4552. for _, item := range monitorList {
  4553. //超滤率
  4554. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4555. //置换率
  4556. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4557. //超滤量
  4558. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4559. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4560. //置换量
  4561. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4562. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4563. }
  4564. }
  4565. }
  4566. //记录日志
  4567. byterequest, _ := json.Marshal(prescription)
  4568. prescriptionLog := models.XtDialysisPrescriptionLog{
  4569. UserOrgId: prescription.UserOrgId,
  4570. Ctime: time.Now().Unix(),
  4571. Mtime: 0,
  4572. ErrLog: string(byterequest),
  4573. AdminUserId: adminUserInfo.AdminUser.Id,
  4574. RecordDate: prescription.RecordDate,
  4575. PatientId: prescription.PatientId,
  4576. Source: "手机端新增长期处方",
  4577. Status: 1,
  4578. }
  4579. service.CreatePrescriptionLog(prescriptionLog)
  4580. finish := models.XtDialysisFinish{
  4581. IsFinish: 1,
  4582. UserOrgId: adminUserInfo.Org.Id,
  4583. Status: 1,
  4584. Ctime: time.Now().Unix(),
  4585. Mtime: 0,
  4586. Module: 1,
  4587. RecordDate: recordDate.Unix(),
  4588. Sourse: 1,
  4589. PatientId: id,
  4590. }
  4591. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4592. if dialysisFinish.ID == 0 {
  4593. service.CreateDialysisFinish(finish)
  4594. }
  4595. //获取最新1条
  4596. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4597. //更新状态
  4598. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4599. //长沙南雅医院,自动生成抗凝剂的临时处方
  4600. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4601. if prescribing_number == 0 {
  4602. prescribing_number = 1
  4603. }
  4604. advice := models.DoctorAdvice{
  4605. UserOrgId: adminUserInfo.Org.Id,
  4606. PatientId: id,
  4607. GroupNo: 0,
  4608. AdviceType: 2,
  4609. RecordDate: recordDate.Unix(),
  4610. AdviceDate: recordDate.Unix(),
  4611. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4612. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4613. AdviceDesc: "",
  4614. ReminderDate: 0,
  4615. SingleDose: prescription.AnticoagulantZongliang,
  4616. SingleDoseUnit: "iu",
  4617. DrugSpec: 0,
  4618. DrugSpecUnit: "",
  4619. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4620. PrescribingNumberUnit: "支",
  4621. DeliveryWay: "静脉注射",
  4622. ExecutionFrequency: "上机前",
  4623. AdviceDoctor: 0,
  4624. Status: 1,
  4625. CreatedTime: time.Now().Unix(),
  4626. UpdatedTime: time.Now().Unix(),
  4627. IsPrescription: 1,
  4628. ExecutionState: 2,
  4629. StopState: 2,
  4630. IsSettle: 2,
  4631. }
  4632. // 查询排班信息
  4633. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4634. if schedulePatient.ID > 0 {
  4635. if schedulePatient.ScheduleType == 1 {
  4636. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4637. }
  4638. if schedulePatient.ScheduleType == 2 {
  4639. advice.StartTime = recordDate.Unix() + 9*60*60
  4640. }
  4641. }
  4642. // 抗凝剂名称
  4643. switch anticoagulant {
  4644. case 1:
  4645. advice.AdviceName = "无肝素"
  4646. break
  4647. case 2:
  4648. advice.AdviceName = "普通肝素"
  4649. break
  4650. case 3:
  4651. advice.AdviceName = "低分子肝素"
  4652. break
  4653. case 4:
  4654. advice.AdviceName = "阿加曲班"
  4655. break
  4656. case 5:
  4657. advice.AdviceName = "枸橼酸钠"
  4658. break
  4659. case 6:
  4660. advice.AdviceName = "低分子肝素钙"
  4661. break
  4662. case 7:
  4663. advice.AdviceName = "低分子肝素钠"
  4664. break
  4665. case 8:
  4666. advice.AdviceName = "依诺肝素"
  4667. break
  4668. case 9:
  4669. advice.AdviceName = "达肝素"
  4670. break
  4671. case 10:
  4672. advice.AdviceName = "体外抗凝"
  4673. break
  4674. case 11:
  4675. advice.AdviceName = "那曲肝素"
  4676. break
  4677. case 12:
  4678. advice.AdviceName = "无抗凝剂"
  4679. break
  4680. }
  4681. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4682. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4683. advice.AdviceDoctor = appRole.AdminUserId
  4684. }
  4685. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4686. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4687. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4688. advice.AdviceName = "低分子肝素钠注射液"
  4689. // 修改患者临时医嘱里的抗凝剂医嘱
  4690. advice.ID = advicePrescription.ID
  4691. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4692. } else {
  4693. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4694. advice.AdviceName = "低分子肝素钠注射液"
  4695. service.CreateDoctorAdvice(&advice)
  4696. }
  4697. }
  4698. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4699. redis := service.RedisClient()
  4700. defer redis.Close()
  4701. //清空key 值
  4702. redis.Set(key, "", time.Second)
  4703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4704. redis.Set(keyOne, "", time.Second)
  4705. }
  4706. //获取key,清空redis
  4707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4708. redis := service.RedisClient()
  4709. defer redis.Close()
  4710. //清空key 值
  4711. redis.Set(key, "", time.Second)
  4712. //清空长期医嘱的key
  4713. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4714. redis.Set(soulution_key, "", time.Second)
  4715. //查询最近透析准备表里是否存在 透析器 灌流器
  4716. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4717. redis.Set(keyOne, "", time.Second)
  4718. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4719. redis.Set(keyTwo, "", time.Second)
  4720. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4721. redis.Set(keyThree, "", time.Second)
  4722. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4723. redis.Set(keyFour, "", time.Second)
  4724. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4725. //
  4726. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4727. //
  4728. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4729. //if len(mation)>0{
  4730. // for _, item := range splitStr {
  4731. // for _,it := range mation{
  4732. // if(item == it.SpecificationName){
  4733. //
  4734. // //查询最近一次的透析器
  4735. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4736. //
  4737. // if errcode == gorm.ErrRecordNotFound{
  4738. // //插入数据
  4739. // prepare := models.DialysisBeforePrepare{
  4740. // UserOrgId: adminUserInfo.Org.Id,
  4741. // PatientId: id,
  4742. // RecordDate: recordDate.Unix(),
  4743. // GoodTypeId: it.GoodTypeId,
  4744. // GoodId: it.ID,
  4745. // Count: 1,
  4746. // Ctime: time.Now().Unix(),
  4747. // Creater: adminUserInfo.AdminUser.Id,
  4748. // Status:1,
  4749. //
  4750. // }
  4751. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4752. // fmt.Println("",errcode)
  4753. // }
  4754. // }
  4755. // }
  4756. //
  4757. // }
  4758. //
  4759. // for _, item := range splitIrrigation {
  4760. // for _,it := range mation{
  4761. // if(item == it.SpecificationName){
  4762. // //查询最近一次的透析器
  4763. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4764. // if errcode == gorm.ErrRecordNotFound{
  4765. // //插入数据
  4766. // prepare := models.DialysisBeforePrepare{
  4767. // UserOrgId: adminUserInfo.Org.Id,
  4768. // PatientId: id,
  4769. // RecordDate: recordDate.Unix(),
  4770. // GoodTypeId: it.GoodTypeId,
  4771. // GoodId: it.ID,
  4772. // Count: 1,
  4773. // Ctime: time.Now().Unix(),
  4774. // Creater: adminUserInfo.AdminUser.Id,
  4775. // Status:1,
  4776. //
  4777. // }
  4778. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4779. // fmt.Println(errcode)
  4780. // }
  4781. // }
  4782. // }
  4783. // }
  4784. //}
  4785. c.ServeSuccessJSON(map[string]interface{}{
  4786. "solution": &solution,
  4787. "prescription": &prescription,
  4788. })
  4789. }
  4790. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4791. patient, _ := c.GetInt64("patient", 0)
  4792. adminUserInfo := c.GetMobileAdminUserInfo()
  4793. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4794. c.ServeSuccessJSON(map[string]interface{}{
  4795. "receiveTreatmentAsses": receiveTreatmentAsses,
  4796. })
  4797. }
  4798. func (this *DialysisAPIController) PostSignInfo() {
  4799. patientID, _ := this.GetInt64("patient_id")
  4800. recordDateStr := this.GetString("date")
  4801. if patientID <= 0 {
  4802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4803. return
  4804. }
  4805. if len(recordDateStr) == 0 {
  4806. recordDateStr = time.Now().Format("2006-01-02")
  4807. }
  4808. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4809. if parseDateErr != nil {
  4810. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4812. return
  4813. }
  4814. adminInfo := this.GetMobileAdminUserInfo()
  4815. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4816. if err != nil {
  4817. this.ErrorLog("签名失败:%v", err)
  4818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4819. return
  4820. }
  4821. this.ServeSuccessJSON(map[string]interface{}{
  4822. "doctor_id": adminInfo.AdminUser.Id,
  4823. })
  4824. }
  4825. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4826. patientID, _ := this.GetInt64("patient_id")
  4827. adminInfo := this.GetMobileAdminUserInfo()
  4828. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4829. this.ServeSuccessJSON(map[string]interface{}{
  4830. "monitor": record,
  4831. })
  4832. }
  4833. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4834. thisTime := time.Now()
  4835. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4836. timeLayout := "2006-01-02 15:04:05"
  4837. loc, _ := time.LoadLocation("Local")
  4838. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4839. theAssessmentDateTime := theStartTime.Unix()
  4840. patientID, _ := this.GetInt64("patient_id")
  4841. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4842. adminInfo := this.GetMobileAdminUserInfo()
  4843. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4844. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4845. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4846. var ultrafiltration_rate float64
  4847. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4848. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4849. fmt.Println(evaluation)
  4850. fmt.Println("prescription.ID", prescription.ID)
  4851. if prescription.ID > 0 {
  4852. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4853. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4854. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4855. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4856. record.UltrafiltrationRate = ultrafiltration_rate
  4857. }
  4858. //重庆塘坝卫生院
  4859. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4860. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4861. record.UltrafiltrationRate = ultrafiltration_rate
  4862. }
  4863. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4864. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4865. record.UltrafiltrationRate = ultrafiltration_rate
  4866. }
  4867. if adminInfo.Org.Id == 10768 {
  4868. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60)
  4869. record.UltrafiltrationRate = ultrafiltration_rate
  4870. }
  4871. if adminInfo.Org.Id == 10510 {
  4872. record.UltrafiltrationRate = 0
  4873. }
  4874. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4875. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4876. record.UltrafiltrationRate = ultrafiltration_rate
  4877. }
  4878. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4879. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4880. record.UltrafiltrationRate = ultrafiltration_rate
  4881. }
  4882. // 只针对方济医院
  4883. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4884. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4885. ultrafiltration_rate = value
  4886. record.UltrafiltrationRate = ultrafiltration_rate
  4887. }
  4888. if template.TemplateId == 41 || template.TemplateId == 47 {
  4889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4890. record.UltrafiltrationRate = ultrafiltration_rate
  4891. }
  4892. if template.TemplateId == 43 {
  4893. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4894. record.UltrafiltrationRate = ultrafiltration_rate
  4895. }
  4896. if template.TemplateId == 46 || template.TemplateId == 54 {
  4897. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4898. record.UltrafiltrationRate = ultrafiltration_rate
  4899. }
  4900. 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 {
  4901. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4902. record.UltrafiltrationRate = ultrafiltration_rate
  4903. }
  4904. if adminInfo.Org.Id == 10469 {
  4905. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4906. record.UltrafiltrationRate = ultrafiltration_rate
  4907. }
  4908. if adminInfo.Org.Id == 10667 {
  4909. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4910. record.UltrafiltrationRate = ultrafiltration_rate
  4911. }
  4912. if adminInfo.Org.Id == 10471 {
  4913. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4914. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4915. }
  4916. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4917. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4918. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4919. }
  4920. if adminInfo.Org.Id == 10751 {
  4921. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4922. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4923. }
  4924. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4925. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4926. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4927. }
  4928. if adminInfo.Org.Id == 10721 {
  4929. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4930. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4931. }
  4932. if adminInfo.Org.Id == 10766 {
  4933. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4934. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4935. }
  4936. if adminInfo.Org.Id == 10757 {
  4937. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4938. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4939. }
  4940. if adminInfo.Org.Id == 10752 {
  4941. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4942. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4943. }
  4944. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4945. record.UltrafiltrationRate = 0
  4946. }
  4947. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4948. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4949. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4950. }
  4951. if adminInfo.Org.Id == 10206 {
  4952. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4953. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4954. }
  4955. //湘潭爱心美白石
  4956. if adminInfo.Org.Id == 9850 {
  4957. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4958. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4959. }
  4960. if adminInfo.Org.Id == 9919 {
  4961. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4962. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4963. }
  4964. //if template.TemplateId == 47 {
  4965. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4966. // record.UltrafiltrationRate = ultrafiltration_rate
  4967. //}
  4968. }
  4969. }
  4970. // record.UltrafiltrationRate = ultrafiltration_rate
  4971. record.UltrafiltrationVolume = 0
  4972. 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
  4973. if ultrafiltration_rate > 0 {
  4974. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4975. record.UltrafiltrationVolume = value
  4976. }
  4977. }
  4978. 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
  4979. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4980. if adminInfo.Org.Id != 10735 {
  4981. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4982. record.UltrafiltrationVolume = ultrafiltration_volume
  4983. }
  4984. //胶州少海医院
  4985. if adminInfo.Org.Id == 10735 {
  4986. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4987. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4988. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4989. if lastMonitorRecordList.ID > 0 {
  4990. record.UltrafiltrationRate = ultrafiltration_rate_one
  4991. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4992. record.UltrafiltrationVolume = ultrafiltration_volume
  4993. } else {
  4994. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4995. record.UltrafiltrationVolume = ultrafiltration_volume
  4996. }
  4997. }
  4998. }
  4999. }
  5000. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  5001. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5002. record.UltrafiltrationVolume = ultrafiltration_volume
  5003. }
  5004. //长沙南雅
  5005. 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 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5006. if ultrafiltration_rate > 0 {
  5007. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5008. record.UltrafiltrationVolume = ultrafiltration_volume
  5009. }
  5010. }
  5011. if adminInfo.Org.Id == 10471 {
  5012. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5013. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5014. }
  5015. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  5016. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5017. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5018. }
  5019. if adminInfo.Org.Id == 10751 {
  5020. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5021. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5022. }
  5023. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  5024. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5025. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5026. }
  5027. //长沙南雅累计血容量自动计算
  5028. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  5029. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  5030. //}
  5031. if template.TemplateId == 47 || template.TemplateId == 54 {
  5032. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5033. }
  5034. if adminInfo.Org.Id == 10510 {
  5035. record.UltrafiltrationVolume = 0
  5036. }
  5037. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10766 {
  5038. if ultrafiltration_rate > 0 {
  5039. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5040. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5041. }
  5042. }
  5043. //古镇乐生
  5044. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  5045. if ultrafiltration_rate > 0 {
  5046. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5047. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5048. }
  5049. }
  5050. if adminInfo.Org.Id == 9919 {
  5051. if ultrafiltration_rate > 0 {
  5052. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5053. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  5054. }
  5055. }
  5056. if adminInfo.Org.Id == 10206 {
  5057. if ultrafiltration_rate > 0 {
  5058. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5059. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5060. }
  5061. }
  5062. if adminInfo.Org.Id == 10768 {
  5063. if ultrafiltration_rate > 0 {
  5064. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5065. record.UltrafiltrationVolume = ultrafiltration_volume
  5066. }
  5067. }
  5068. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  5069. var replacement_rate float64
  5070. var displacement_quantity float64
  5071. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5072. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  5073. record.ReplacementRate = replacement_rate
  5074. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5075. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5076. record.DisplacementQuantity = displacement_quantity
  5077. }
  5078. if adminInfo.Org.Id == 10766 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10768 {
  5079. var replacement_rate float64
  5080. var displacement_quantity float64
  5081. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5082. //replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5083. ////乘10 除10是为了保留一位小数
  5084. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5085. fmt.Println("replacement_rate", replacement_rate)
  5086. record.ReplacementRate = replacement_rate
  5087. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5088. record.DisplacementQuantity = displacement_quantity
  5089. //fmt.Println("totalMin", totalMin)
  5090. //fmt.Println("math.Floor(prescription", math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60))
  5091. //fmt.Println("replacement_rate", replacement_rate)
  5092. //fmt.Println("math.Floor", math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600))
  5093. //fmt.Println("displacement_quantity===================", displacement_quantity)
  5094. }
  5095. if adminInfo.Org.Id == 9478 {
  5096. var replacement_rate float64
  5097. var displacement_quantity float64
  5098. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5099. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5100. record.ReplacementRate = replacement_rate
  5101. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5102. record.DisplacementQuantity = displacement_quantity
  5103. }
  5104. if adminInfo.Org.Id == 10752 {
  5105. var replacement_rate float64
  5106. var displacement_quantity float64
  5107. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5108. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5109. record.ReplacementRate = replacement_rate
  5110. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5111. record.DisplacementQuantity = displacement_quantity
  5112. }
  5113. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5114. var replacement_rate float64
  5115. var displacement_quantity float64
  5116. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5117. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5118. record.ReplacementRate = replacement_rate
  5119. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5120. record.DisplacementQuantity = displacement_quantity
  5121. }
  5122. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5123. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5124. record.UltrafiltrationVolume = ultrafiltration_volume
  5125. }
  5126. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5127. var replacement_rate float64
  5128. var displacement_quantity float64
  5129. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5130. if totalMin == 0 {
  5131. totalMin = 240
  5132. }
  5133. if prescription.DisplaceLiquiValue == 0 {
  5134. prescription.ReplacementTotal = 32
  5135. }
  5136. //乘10 除10是为了保留一位小数
  5137. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5138. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5139. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5140. record.DisplacementQuantity = displacement_quantity
  5141. }
  5142. if adminInfo.Org.Id == 9850 {
  5143. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5144. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5145. }
  5146. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5147. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5148. this.ServeSuccessJSON(map[string]interface{}{
  5149. "monitor": record,
  5150. "lastMonitorRecordList": lastMonitorRecordList,
  5151. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5152. })
  5153. }
  5154. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5155. record_id, _ := this.GetInt64("id")
  5156. nurseID, _ := this.GetInt64("start_nurse")
  5157. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5158. bedID, _ := this.GetInt64("bed")
  5159. start_time := this.GetString("start_time")
  5160. schedual_type, _ := this.GetInt64("schedual_type")
  5161. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5162. change_nurse, _ := this.GetInt64("change_nurse")
  5163. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5164. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5165. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5166. patient_id, _ := this.GetInt64("patient_id")
  5167. record_date, _ := this.GetInt64("record_date")
  5168. puncture_needle := this.GetString("puncture_needle")
  5169. puncture_way := this.GetString("puncture_way")
  5170. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5171. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5172. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5173. nuclein_date_str := this.GetString("nuclein_date_str")
  5174. order_remark := this.GetString("order_remark")
  5175. schedule_remark := this.GetString("schedule_remark")
  5176. catheter_operation := this.GetString("catheter_operation")
  5177. blood_flow_volume := this.GetString("blood_flow_volume")
  5178. blood_drawing, _ := this.GetInt64("blood_drawing")
  5179. dialysis_strainer := this.GetString("dialysis_strainer")
  5180. if record_id == 0 {
  5181. this.ErrorLog("id:%v", record_id)
  5182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5183. return
  5184. }
  5185. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5186. if parseStartDateErr != nil {
  5187. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5189. return
  5190. }
  5191. adminUserInfo := this.GetMobileAdminUserInfo()
  5192. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5193. if getNurseErr != nil {
  5194. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5196. return
  5197. } else if nurse == nil {
  5198. this.ErrorLog("护士不存在")
  5199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5200. return
  5201. }
  5202. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5203. //if getNurseErr != nil {
  5204. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5205. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5206. // return
  5207. //} else if nurse == nil {
  5208. // this.ErrorLog("护士不存在")
  5209. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5210. // return
  5211. //}
  5212. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5213. if getDeviceNumberErr != nil {
  5214. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5216. return
  5217. } else if deviceNumber == nil {
  5218. this.ErrorLog("床位号不存在")
  5219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5220. return
  5221. }
  5222. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5223. //
  5224. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5225. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5226. // if getPermissionErr != nil {
  5227. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5228. // return
  5229. // } else if headNursePermission == nil {
  5230. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5231. // return
  5232. // }
  5233. //}
  5234. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5235. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5236. timeLayout := "2006-01-02 15:04:05"
  5237. loc, _ := time.LoadLocation("Local")
  5238. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5239. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5240. schedulestartTime := theStartTime.Unix()
  5241. scheduleendTime := theEndTime.Unix()
  5242. var theNucleinDate int64
  5243. timeLayoutOne := "2006-01-02"
  5244. if len(nuclein_date_str) > 0 {
  5245. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5246. if err != nil {
  5247. utils.ErrorLog(err.Error())
  5248. }
  5249. theNucleinDate = theTime.Unix()
  5250. }
  5251. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5252. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5253. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5254. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5255. if err == gorm.ErrRecordNotFound { //空床位
  5256. // 修改了床位逻辑
  5257. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5258. if daySchedule.ID > 0 {
  5259. //daySchedule.BedId = bedID
  5260. //daySchedule.PartitionId = deviceNumber.ZoneID
  5261. //daySchedule.ScheduleType = schedual_type
  5262. //daySchedule.UpdatedTime = time.Now().Unix()
  5263. //err := service.UpdateSchedule(&daySchedule)
  5264. xtSchedule := models.Schedule{
  5265. PartitionId: deviceNumber.ZoneID,
  5266. BedId: bedID,
  5267. ScheduleType: schedual_type,
  5268. UpdatedTime: time.Now().Unix(),
  5269. }
  5270. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5271. if err != nil {
  5272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5273. return
  5274. }
  5275. }
  5276. } else if err == nil {
  5277. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5278. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5279. if daySchedule.ID > 0 {
  5280. //daySchedule.BedId = bedID
  5281. //daySchedule.PartitionId = deviceNumber.ZoneID
  5282. //
  5283. //daySchedule.ScheduleType = schedual_type
  5284. //daySchedule.UpdatedTime = time.Now().Unix()
  5285. //err := service.UpdateSchedule(&daySchedule)
  5286. xtSchedule := models.Schedule{
  5287. PartitionId: deviceNumber.ZoneID,
  5288. BedId: bedID,
  5289. ScheduleType: schedual_type,
  5290. UpdatedTime: time.Now().Unix(),
  5291. }
  5292. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5293. if err != nil {
  5294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5295. return
  5296. }
  5297. }
  5298. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5300. return
  5301. }
  5302. } else if err != nil {
  5303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5304. return
  5305. }
  5306. }
  5307. dialysisRecord := &models.DialysisOrder{
  5308. ID: record_id,
  5309. UserOrgId: adminUserInfo.Org.Id,
  5310. BedID: bedID,
  5311. StartNurse: nurseID,
  5312. StartTime: startDate.Unix(),
  5313. PunctureNurse: puncture_nurse,
  5314. Creator: adminUserInfo.AdminUser.Id,
  5315. Modifier: adminUserInfo.AdminUser.Id,
  5316. WashpipeNurse: washpipe_nurse,
  5317. SchedualType: schedual_type,
  5318. ChangeNurse: change_nurse,
  5319. DifficultPunctureNurse: difficult_puncture_nurse,
  5320. NewFistulaNurse: new_fistula_nurse,
  5321. QualityNurseId: quality_nurse_id,
  5322. PunctureNeedle: puncture_needle,
  5323. PunctureWay: puncture_way,
  5324. DialysisDialyszers: dialysis_dialyszers,
  5325. DialysisIrrigation: dialysis_irrigation,
  5326. BloodAccessId: blood_access_id,
  5327. NucleinDate: theNucleinDate,
  5328. OrderRemark: order_remark,
  5329. ScheduleRemark: schedule_remark,
  5330. CatheterOperation: catheter_operation,
  5331. BloodFlowVolume: blood_flow_volume,
  5332. BloodDrawing: blood_drawing,
  5333. DialysisStrainer: dialysis_strainer,
  5334. }
  5335. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5336. if prescription.ID > 0 {
  5337. var endTime int64
  5338. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5339. dialysisRecord.EndTime = endTime
  5340. }
  5341. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10164 {
  5342. //查询第一条监测
  5343. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5344. service.UpdateFirstMoitorById(firstMonitor.ID, dialysisRecord.StartTime)
  5345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5346. redis := service.RedisClient()
  5347. //清空key 值
  5348. redis.Set(key, "", time.Second)
  5349. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5350. redis.Set(keyOne, "", time.Second)
  5351. defer redis.Close()
  5352. }
  5353. //修改床位号需要重新消毒
  5354. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5355. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5356. //查询第一条监测
  5357. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5358. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5359. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5360. redis := service.RedisClient()
  5361. //清空key 值
  5362. redis.Set(key, "", time.Second)
  5363. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5364. redis.Set(keyOne, "", time.Second)
  5365. defer redis.Close()
  5366. }
  5367. // 查询信息规挡的设置天数
  5368. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5369. if infor.ID > 0 && infor.WeekDay > 0 {
  5370. var cha_time int64
  5371. timeNowStr := time.Now().Format("2006-01-02")
  5372. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5373. //今日的日期减去设置的日期
  5374. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5375. if cha_time >= record_date {
  5376. //查询审核是否允许
  5377. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5378. //申请状态不允许的情况 拒绝修改
  5379. if infor.ApplicationStatus != 1 {
  5380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5381. return
  5382. }
  5383. }
  5384. }
  5385. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5386. //修改床位后重新生成消毒计划
  5387. if adminUserInfo.Org.Id == 10340 {
  5388. //根据床位号获取设备型号
  5389. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5390. //查询使用消毒最后一条消毒记录
  5391. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5392. fmt.Println("err", err)
  5393. if err == gorm.ErrRecordNotFound {
  5394. //查找排班
  5395. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5396. //查询改设备是否有消毒计划
  5397. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5398. //根据床位号获取设备id
  5399. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5400. //查询病人信息
  5401. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5402. var con = ""
  5403. if patients.IsInfectious == 0 {
  5404. con = ""
  5405. }
  5406. if patients.IsInfectious == 1 {
  5407. con = "无"
  5408. }
  5409. if patients.IsInfectious == 2 {
  5410. con = "有"
  5411. }
  5412. if errcode == nil {
  5413. var end_time int64
  5414. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5415. //新增消毒
  5416. information := models.DeviceInformation{
  5417. Date: dialysisRecord.DialysisDate,
  5418. Zone: dialysisRecord.ZoneId,
  5419. Class: dialysisRecord.SchedualType,
  5420. BedNumber: dialysisRecord.BedID,
  5421. PatientId: dialysisRecord.PatientId,
  5422. DialysisMode: scheduleByPatient.ModeId,
  5423. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5424. Disinfection: 1,
  5425. DialysisConcentration: 1,
  5426. DisinfectionStatus: 1,
  5427. Move: 1,
  5428. UserOrgId: dialysisRecord.UserOrgId,
  5429. DisinfectType: plan.Way,
  5430. DisinfectantType: plan.MachineDisinfectant,
  5431. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5432. Disinfectant: plan.Disinfectant,
  5433. Ctime: time.Now().Unix(),
  5434. Status: 1,
  5435. SignName: nurseID,
  5436. EquimentId: addmacher.ID,
  5437. DisinfectionResidue: 2,
  5438. Bed: addmacher.BedNumber,
  5439. StartTime: dialysisRecord.StartTime,
  5440. EndTime: dialysisRecord.EndTime,
  5441. Contagion: con,
  5442. WeightLoss: 0,
  5443. Hyperfiltratio: 0,
  5444. DialysisHour: "",
  5445. MachineRun: 1,
  5446. DisinfecStartime: dialysisRecord.EndTime,
  5447. DisinfecEndtime: end_time,
  5448. }
  5449. err := service.CreateInformationTwo(&information)
  5450. fmt.Println("报错", err)
  5451. }
  5452. }
  5453. }
  5454. order, _ := service.GetLastPatientOrder(record_id)
  5455. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5456. redis := service.RedisClient()
  5457. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5458. redis.Set(key, "", time.Second)
  5459. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5460. //清空key 值
  5461. redis.Set(keyOne, "", time.Second)
  5462. scheduleDateStartOne := startDate.Format("2006-01-02")
  5463. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5464. redis.Set(keyTwo, "", time.Second)
  5465. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5466. redis.Set(keyThree, "", time.Second)
  5467. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5468. redis.Set(keyFour, "", time.Second)
  5469. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5470. redis.Set(keyFive, "", time.Second)
  5471. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5472. redis.Set(keySix, "", time.Second)
  5473. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5474. redis.Set(keySeven, "", time.Second)
  5475. if updateErr != nil {
  5476. this.ErrorLog("修改上机失败:%v", updateErr)
  5477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5478. return
  5479. }
  5480. if updateErr == nil {
  5481. if tempDialysisRecord.Stage == 2 {
  5482. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5483. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5484. fmt.Println(value)
  5485. a, b := math.Modf(value)
  5486. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5487. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5488. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5489. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5490. redis := service.RedisClient()
  5491. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5492. redis.Set(key, "", time.Second)
  5493. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5494. redis.Set(keyOne, "", time.Second)
  5495. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5496. //清空key 值
  5497. redis.Set(keySix, "", time.Second)
  5498. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5499. redis.Set(keySeven, "", time.Second)
  5500. redis.Close()
  5501. if updateAssessmentErr != nil {
  5502. utils.ErrorLog("%v", updateAssessmentErr)
  5503. }
  5504. }
  5505. }
  5506. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5507. this.ServeSuccessJSON(map[string]interface{}{
  5508. "dialysis_order": dialysisRecords,
  5509. })
  5510. }
  5511. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5512. record_id, _ := c.GetInt64("id")
  5513. nurseID, _ := c.GetInt64("nurse")
  5514. end_time := c.GetString("end_time")
  5515. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5516. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5517. catheter := c.GetString("catheter")
  5518. cruor := c.GetString("cruor")
  5519. mission := c.GetString("mission")
  5520. condenser := c.GetString("condenser")
  5521. if record_id <= 0 || nurseID <= 0 {
  5522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5523. return
  5524. }
  5525. adminUserInfo := c.GetMobileAdminUserInfo()
  5526. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5527. if getNurseErr != nil {
  5528. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5530. return
  5531. } else if nurse == nil {
  5532. c.ErrorLog("护士不存在")
  5533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5534. return
  5535. }
  5536. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5537. if parseEndDateErr != nil {
  5538. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5540. return
  5541. }
  5542. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5543. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5544. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5545. // if getPermissionErr != nil {
  5546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5547. // return
  5548. // } else if headNursePermission == nil {
  5549. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5550. // return
  5551. // }
  5552. //}
  5553. // 查询信息规挡的设置天数
  5554. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5555. if infor.ID > 0 {
  5556. var cha_time int64
  5557. timeNowStr := time.Now().Format("2006-01-02")
  5558. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5559. //今日的日期减去设置的日期
  5560. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5561. if cha_time >= tempDialysisRecords.DialysisDate {
  5562. //查询审核是否允许
  5563. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5564. //申请状态不允许的情况 拒绝修改
  5565. if infor.ApplicationStatus != 1 {
  5566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5567. return
  5568. }
  5569. }
  5570. }
  5571. dialysisRecord := &models.DialysisOrder{
  5572. ID: record_id,
  5573. UserOrgId: adminUserInfo.Org.Id,
  5574. EndTime: endDate.Unix(),
  5575. FinishNurse: nurseID,
  5576. FinishModifier: adminUserInfo.AdminUser.Id,
  5577. PuncturePointHaematoma: puncture_point_haematoma,
  5578. BloodAccessInternalFistula: blood_access_internal_fistula,
  5579. Catheter: catheter,
  5580. Cruor: cruor,
  5581. Mission: mission,
  5582. Condenser: condenser,
  5583. }
  5584. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5585. redis := service.RedisClient()
  5586. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5587. //清空key 值
  5588. redis.Set(key, "", time.Second)
  5589. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5590. //清空key 值
  5591. redis.Set(keyOne, "", time.Second)
  5592. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5593. redis.Set(keySeven, "", time.Second)
  5594. redis.Close()
  5595. if updateErr != nil {
  5596. c.ErrorLog("修改下机失败:%v", updateErr)
  5597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5598. return
  5599. }
  5600. if updateErr == nil {
  5601. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5602. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5603. a, b := math.Modf(value)
  5604. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5605. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5606. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5607. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5608. redis := service.RedisClient()
  5609. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5610. redis.Set(keyTen, "", time.Second)
  5611. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5612. redis.Set(keyTwo, "", time.Second)
  5613. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5614. redis.Set(key, "", time.Second)
  5615. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5616. redis.Set(keyThree, "", time.Second)
  5617. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5618. redis.Set(keySeven, "", time.Second)
  5619. defer redis.Close()
  5620. if updateAssessmentErr != nil {
  5621. utils.ErrorLog("%v", updateAssessmentErr)
  5622. }
  5623. }
  5624. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5625. c.ServeSuccessJSON(map[string]interface{}{
  5626. "dialysis_order": dialysisRecords,
  5627. })
  5628. }
  5629. func (c *DialysisAPIController) GetLongAdvice() {
  5630. patient_id, _ := c.GetInt64("id")
  5631. adminUserInfo := c.GetMobileAdminUserInfo()
  5632. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5633. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5634. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5635. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5636. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5637. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5638. c.ServeSuccessJSON(map[string]interface{}{
  5639. "status": "1",
  5640. })
  5641. return
  5642. } else { //开启推送提醒
  5643. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5644. var advice_three []*models.DoctorAdvice
  5645. recordDateStr := time.Now().Format("2006-01-02")
  5646. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5647. nowtime := recordDate.Unix()
  5648. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5649. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5650. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5651. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5652. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5653. for _, advice := range advices {
  5654. if advice.FrequencyType == 3 {
  5655. t := time.Now()
  5656. week := int(t.Weekday())
  5657. fmt.Println(t.Weekday())
  5658. fmt.Println(week)
  5659. switch week {
  5660. case 1:
  5661. if strings.Index(advice.WeekDay, "周一") == -1 {
  5662. advice_three = append(advice_three, advice)
  5663. }
  5664. break
  5665. case 2:
  5666. if strings.Index(advice.WeekDay, "周二") == -1 {
  5667. advice_three = append(advice_three, advice)
  5668. }
  5669. break
  5670. case 3:
  5671. if strings.Index(advice.WeekDay, "周三") == -1 {
  5672. advice_three = append(advice_three, advice)
  5673. }
  5674. break
  5675. case 4:
  5676. if strings.Index(advice.WeekDay, "周四") == -1 {
  5677. advice_three = append(advice_three, advice)
  5678. }
  5679. break
  5680. case 5:
  5681. if strings.Index(advice.WeekDay, "周五") == -1 {
  5682. advice_three = append(advice_three, advice)
  5683. }
  5684. break
  5685. case 6:
  5686. if strings.Index(advice.WeekDay, "周六") == -1 {
  5687. advice_three = append(advice_three, advice)
  5688. }
  5689. break
  5690. case 0:
  5691. if strings.Index(advice.WeekDay, "周日") == -1 {
  5692. advice_three = append(advice_three, advice)
  5693. }
  5694. break
  5695. }
  5696. }
  5697. }
  5698. for _, advice := range advices_two {
  5699. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5700. now := p.Unix()
  5701. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5702. dayStr2 := "-" + dayStr
  5703. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5704. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5705. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5706. for _, ad := range advices {
  5707. advice_three = append(advice_three, ad)
  5708. }
  5709. }
  5710. if err == nil {
  5711. c.ServeSuccessJSON(map[string]interface{}{
  5712. "status": "2",
  5713. "advices": advices,
  5714. "advices_two": RemoveRepeatedElement(advice_three),
  5715. "is_open_remind": config.IsOpenRemind,
  5716. "his_config_open": hisConfig.IsOpen,
  5717. "is_advice_open": is_advice_open.IsAdviceOpen,
  5718. "prescription_open": prescription_open.IsOpen,
  5719. })
  5720. }
  5721. }
  5722. }
  5723. func (c *DialysisAPIController) GetLongAdviceOne() {
  5724. patient_id, _ := c.GetInt64("id")
  5725. startTime := c.GetString("schedule_date")
  5726. timeLayout := "2006-01-02"
  5727. loc, _ := time.LoadLocation("Local")
  5728. var theStartTime int64
  5729. if len(startTime) > 0 {
  5730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5731. if err != nil {
  5732. utils.ErrorLog(err.Error())
  5733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5734. return
  5735. }
  5736. theStartTime = theTime.Unix()
  5737. }
  5738. adminUserInfo := c.GetMobileAdminUserInfo()
  5739. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5740. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5741. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5742. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5743. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5744. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5745. c.ServeSuccessJSON(map[string]interface{}{
  5746. "status": "1",
  5747. })
  5748. return
  5749. } else { //开启推送提醒
  5750. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5751. var advice_three []*models.DoctorAdvice
  5752. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5753. fmt.Println("theStartTime-----------------------", theStartTime)
  5754. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5755. for _, advice := range advices {
  5756. if advice.FrequencyType == 3 {
  5757. t := time.Now()
  5758. week := int(t.Weekday())
  5759. fmt.Println(t.Weekday())
  5760. fmt.Println(week)
  5761. switch week {
  5762. case 1:
  5763. if strings.Index(advice.WeekDay, "周一") == -1 {
  5764. advice_three = append(advice_three, advice)
  5765. }
  5766. break
  5767. case 2:
  5768. if strings.Index(advice.WeekDay, "周二") == -1 {
  5769. advice_three = append(advice_three, advice)
  5770. }
  5771. break
  5772. case 3:
  5773. if strings.Index(advice.WeekDay, "周三") == -1 {
  5774. advice_three = append(advice_three, advice)
  5775. }
  5776. break
  5777. case 4:
  5778. if strings.Index(advice.WeekDay, "周四") == -1 {
  5779. advice_three = append(advice_three, advice)
  5780. }
  5781. break
  5782. case 5:
  5783. if strings.Index(advice.WeekDay, "周五") == -1 {
  5784. advice_three = append(advice_three, advice)
  5785. }
  5786. break
  5787. case 6:
  5788. if strings.Index(advice.WeekDay, "周六") == -1 {
  5789. advice_three = append(advice_three, advice)
  5790. }
  5791. break
  5792. case 0:
  5793. if strings.Index(advice.WeekDay, "周日") == -1 {
  5794. advice_three = append(advice_three, advice)
  5795. }
  5796. break
  5797. }
  5798. }
  5799. }
  5800. for _, advice := range advices_two {
  5801. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5802. now := p.Unix()
  5803. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5804. dayStr2 := "-" + dayStr
  5805. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5806. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5807. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5808. fmt.Println("advices-==---------------", advices)
  5809. for _, ad := range advices {
  5810. advice_three = append(advice_three, ad)
  5811. }
  5812. }
  5813. if err == nil {
  5814. c.ServeSuccessJSON(map[string]interface{}{
  5815. "status": "2",
  5816. "advices": advices,
  5817. "advices_two": RemoveRepeatedElement(advice_three),
  5818. "is_open_remind": config.IsOpenRemind,
  5819. "his_config_open": hisConfig.IsOpen,
  5820. "is_advice_open": is_advice_open.IsAdviceOpen,
  5821. "prescription_open": prescription_open.IsOpen,
  5822. })
  5823. }
  5824. }
  5825. }
  5826. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5827. newArr = make([]*models.DoctorAdvice, 0)
  5828. for i := 0; i < len(arr); i++ {
  5829. repeat := false
  5830. for j := i + 1; j < len(arr); j++ {
  5831. if arr[i].ID == arr[j].ID {
  5832. repeat = true
  5833. break
  5834. }
  5835. }
  5836. if !repeat {
  5837. newArr = append(newArr, arr[i])
  5838. }
  5839. }
  5840. return
  5841. }
  5842. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5843. patient, _ := c.GetInt64("id", 0)
  5844. groupNo, _ := c.GetInt64("groupno", 0)
  5845. if patient <= 0 {
  5846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5847. return
  5848. }
  5849. adminUserInfo := c.GetMobileAdminUserInfo()
  5850. dataBody := make(map[string]interface{}, 0)
  5851. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5852. if err != nil {
  5853. utils.ErrorLog(err.Error())
  5854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5855. return
  5856. }
  5857. utils.ErrorLog("%v", dataBody)
  5858. timeLayout := "2006-01-02 15:04"
  5859. loc, _ := time.LoadLocation("Local")
  5860. timeLayout2 := "2006-01-02"
  5861. loc2, _ := time.LoadLocation("Local")
  5862. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5863. utils.ErrorLog("advice_type")
  5864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5865. return
  5866. }
  5867. adviceType := int64(2)
  5868. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5869. utils.ErrorLog("advice_date")
  5870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5871. return
  5872. }
  5873. adviceDate, _ := dataBody["advice_date"].(string)
  5874. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5875. AdviceDate := theTime.Unix()
  5876. RecordDate := theTime.Unix()
  5877. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5878. utils.ErrorLog("start_time")
  5879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5880. return
  5881. }
  5882. startTime, _ := dataBody["start_time"].(string)
  5883. if len(startTime) == 0 {
  5884. utils.ErrorLog("len(start_time) == 0")
  5885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5886. return
  5887. }
  5888. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5889. if err != nil {
  5890. utils.ErrorLog(err.Error())
  5891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5892. return
  5893. }
  5894. StartTime := theTime.Unix()
  5895. Remark := ""
  5896. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5897. remark, _ := dataBody["remark"].(string)
  5898. Remark = remark
  5899. }
  5900. var advices []*models.GroupAdvice
  5901. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5902. utils.ErrorLog("advices")
  5903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5904. return
  5905. }
  5906. adviceNames := dataBody["advices"].([]interface{})
  5907. for _, adviceNameMap := range adviceNames {
  5908. adviceNameM := adviceNameMap.(map[string]interface{})
  5909. var advice models.GroupAdvice
  5910. advice.Remark = Remark
  5911. advice.AdviceType = adviceType
  5912. advice.StartTime = StartTime
  5913. advice.AdviceDate = AdviceDate
  5914. advice.RecordDate = RecordDate
  5915. advice.Status = 1
  5916. advice.CreatedTime = time.Now().Unix()
  5917. advice.UpdatedTime = time.Now().Unix()
  5918. advice.StopState = 2
  5919. advice.ExecutionState = 2
  5920. advice.UserOrgId = adminUserInfo.Org.Id
  5921. advice.PatientId = patient
  5922. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5923. advice.IsSettle = 2
  5924. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5925. utils.ErrorLog("advice_name")
  5926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5927. return
  5928. }
  5929. adviceName, _ := adviceNameM["advice_name"].(string)
  5930. if len(adviceName) == 0 {
  5931. utils.ErrorLog("len(advice_name) == 0")
  5932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5933. return
  5934. }
  5935. advice.AdviceName = adviceName
  5936. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5937. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5938. advice.DrugSpec = drugSpec
  5939. }
  5940. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5941. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5942. advice.AdviceDesc = adviceDesc
  5943. }
  5944. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5945. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5946. advice.DrugSpecUnit = drugSpecUnit
  5947. }
  5948. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5949. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5950. // advice.SingleDose = singleDose
  5951. //}
  5952. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5953. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5954. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5955. }
  5956. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5957. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5958. advice.SingleDoseUnit = singleDoseUnit
  5959. }
  5960. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5961. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5962. // advice.PrescribingNumber = prescribingNumber
  5963. //}
  5964. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5965. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5966. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5967. }
  5968. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5969. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5970. advice.PrescribingNumberUnit = prescribingNumberUnit
  5971. }
  5972. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5973. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5974. advice.DeliveryWay = deliveryWay
  5975. }
  5976. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5977. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5978. advice.ExecutionFrequency = executionFrequency
  5979. }
  5980. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5981. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5982. advice.FrequencyType = frequency_type
  5983. }
  5984. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5985. day_count := int64(adviceNameM["day_count"].(float64))
  5986. advice.DayCount = day_count
  5987. }
  5988. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5989. week_day, _ := adviceNameM["week_day"].(string)
  5990. advice.WeekDay = week_day
  5991. }
  5992. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5993. way := int64(adviceNameM["way"].(float64))
  5994. advice.Way = way
  5995. }
  5996. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5997. drug_id := int64(adviceNameM["drug_id"].(float64))
  5998. advice.DrugId = drug_id
  5999. }
  6000. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  6001. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  6002. advice.DrugNameId = drug_name_id
  6003. }
  6004. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  6005. remark, _ := adviceNameM["remark"].(string)
  6006. advice.Remark = remark
  6007. }
  6008. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  6009. groupno := int64(adviceNameM["groupno"].(float64))
  6010. advice.GroupNo = groupno
  6011. }
  6012. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  6013. template_id, _ := adviceNameM["template_id"].(string)
  6014. advice.TemplateId = template_id
  6015. }
  6016. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  6017. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  6018. advice.ExecutionFrequency = executionFrequency
  6019. }
  6020. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  6021. children := adviceNameM["child"].([]interface{})
  6022. if len(children) > 0 {
  6023. for _, childrenMap := range children {
  6024. childMap := childrenMap.(map[string]interface{})
  6025. var child models.GroupAdvice
  6026. child.Remark = Remark
  6027. child.AdviceType = adviceType
  6028. child.StartTime = StartTime
  6029. child.AdviceDate = AdviceDate
  6030. child.RecordDate = RecordDate
  6031. child.Status = 1
  6032. child.CreatedTime = time.Now().Unix()
  6033. child.UpdatedTime = time.Now().Unix()
  6034. child.StopState = 2
  6035. child.ExecutionState = 2
  6036. child.UserOrgId = adminUserInfo.Org.Id
  6037. child.PatientId = patient
  6038. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  6039. child.IsSettle = 1
  6040. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  6041. utils.ErrorLog("child advice_name")
  6042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6043. return
  6044. }
  6045. childAdviceName, _ := childMap["advice_name"].(string)
  6046. if len(childAdviceName) == 0 {
  6047. utils.ErrorLog("len(child advice_name) == 0")
  6048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6049. return
  6050. }
  6051. child.AdviceName = childAdviceName
  6052. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  6053. childAdviceDesc, _ := childMap["advice_desc"].(string)
  6054. child.AdviceDesc = childAdviceDesc
  6055. }
  6056. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  6057. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  6058. child.DrugSpec = childDrugSpec
  6059. }
  6060. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  6061. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  6062. child.DrugSpecUnit = childDrugSpecUnit
  6063. }
  6064. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  6065. child.SingleDose = childMap["single_dose"].(float64)
  6066. }
  6067. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  6068. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  6069. child.SingleDoseUnit = childSingleDoseUnit
  6070. }
  6071. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  6072. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  6073. }
  6074. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  6075. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  6076. child.PrescribingNumberUnit = childPrescribingNumberUnit
  6077. }
  6078. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  6079. groupno := int64(childMap["groupno"].(float64))
  6080. advice.GroupNo = groupno
  6081. }
  6082. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  6083. remark, _ := childMap["remark"].(string)
  6084. child.Remark = remark
  6085. }
  6086. child.DeliveryWay = advice.DeliveryWay
  6087. child.ExecutionFrequency = advice.ExecutionFrequency
  6088. advice.Children = append(advice.Children, &child)
  6089. }
  6090. }
  6091. }
  6092. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  6093. if temp_advice.ID == 0 {
  6094. advices = append(advices, &advice)
  6095. }
  6096. }
  6097. if len(advices) > 0 {
  6098. finish := models.XtDialysisFinish{
  6099. IsFinish: 1,
  6100. UserOrgId: adminUserInfo.Org.Id,
  6101. Status: 1,
  6102. Ctime: time.Now().Unix(),
  6103. Mtime: 0,
  6104. Module: 4,
  6105. RecordDate: AdviceDate,
  6106. Sourse: 1,
  6107. PatientId: patient,
  6108. }
  6109. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  6110. if dialysisFinish.ID == 0 {
  6111. service.CreateDialysisFinish(finish)
  6112. }
  6113. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  6114. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  6115. for _, item := range advices {
  6116. byterequest, _ := json.Marshal(item)
  6117. adviceLog := models.XtDoctorAdviceLog{
  6118. UserOrgId: adminUserInfo.Org.Id,
  6119. PatientId: patient,
  6120. AdminUserId: adminUserInfo.AdminUser.Id,
  6121. Module: 1,
  6122. ErrLog: string(byterequest),
  6123. Status: 1,
  6124. Ctime: time.Now().Unix(),
  6125. Mtime: 0,
  6126. Source: "手机端医嘱推送",
  6127. RecordDate: item.AdviceDate,
  6128. }
  6129. service.CreateDoctorAdviceLog(adviceLog)
  6130. }
  6131. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6132. redis := service.RedisClient()
  6133. //清空key 值
  6134. redis.Set(key, "", time.Second)
  6135. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6136. redis.Set(keyOne, "", time.Second)
  6137. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6138. defer redis.Close()
  6139. redis.Set(keyThree, "", time.Second)
  6140. if err != nil {
  6141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6142. return
  6143. }
  6144. c.ServeSuccessJSON(map[string]interface{}{
  6145. "msg": "ok",
  6146. "advices": list,
  6147. })
  6148. } else {
  6149. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6150. for _, item := range advices {
  6151. byterequest, _ := json.Marshal(item)
  6152. adviceLog := models.XtDoctorAdviceLog{
  6153. UserOrgId: adminUserInfo.Org.Id,
  6154. PatientId: patient,
  6155. AdminUserId: adminUserInfo.AdminUser.Id,
  6156. Module: 1,
  6157. ErrLog: string(byterequest),
  6158. Status: 1,
  6159. Ctime: time.Now().Unix(),
  6160. Mtime: 0,
  6161. Source: "手机端医嘱推送",
  6162. RecordDate: item.AdviceDate,
  6163. }
  6164. service.CreateDoctorAdviceLog(adviceLog)
  6165. }
  6166. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6167. redis := service.RedisClient()
  6168. //清空key 值
  6169. redis.Set(key, "", time.Second)
  6170. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6171. redis.Set(keyOne, "", time.Second)
  6172. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6173. defer redis.Close()
  6174. redis.Set(keyThree, "", time.Second)
  6175. if err != nil {
  6176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6177. return
  6178. }
  6179. c.ServeSuccessJSON(map[string]interface{}{
  6180. "msg": "ok",
  6181. "advices": list,
  6182. })
  6183. }
  6184. } else {
  6185. c.ServeSuccessJSON(map[string]interface{}{
  6186. "msg": "ok",
  6187. })
  6188. }
  6189. return
  6190. }
  6191. func (c *DialysisAPIController) UploadDryWeight() {
  6192. patient_id, _ := c.GetInt64("id")
  6193. dry_weight, _ := c.GetFloat("dry_weight")
  6194. doctor_id, _ := c.GetInt64("doctor_id")
  6195. remark := c.GetString("remark")
  6196. adminUserInfo := c.GetMobileAdminUserInfo()
  6197. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6198. if err == gorm.ErrRecordNotFound {
  6199. dryWeight := &models.SgjPatientDryweight{
  6200. PatientId: patient_id,
  6201. DryWeight: dry_weight,
  6202. Remakes: remark,
  6203. Ctime: time.Now().Unix(),
  6204. Mtime: time.Now().Unix(),
  6205. Creator: doctor_id,
  6206. Status: 1,
  6207. UserOrgId: adminUserInfo.Org.Id,
  6208. AdjustedValue: "/",
  6209. UserId: adminUserInfo.AdminUser.Id,
  6210. }
  6211. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6212. redis := service.RedisClient()
  6213. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6214. redis.Set(keyOne, "", time.Second)
  6215. loc, _ := time.LoadLocation("Local")
  6216. nowTime := time.Now()
  6217. nowDay := nowTime.Format("2006-01-02")
  6218. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6219. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6220. redis.Set(key, "", time.Second)
  6221. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6222. redis.Set(keyTwo, "", time.Second)
  6223. redis.Close()
  6224. if createErr == nil {
  6225. c.ServeSuccessJSON(map[string]interface{}{
  6226. "msg": "提交成功",
  6227. "weight": dryWeight,
  6228. })
  6229. }
  6230. } else {
  6231. dryWeight := &models.SgjPatientDryweight{
  6232. PatientId: patient_id,
  6233. DryWeight: dry_weight,
  6234. Remakes: remark,
  6235. Ctime: time.Now().Unix(),
  6236. Mtime: time.Now().Unix(),
  6237. Creator: doctor_id,
  6238. Status: 1,
  6239. UserOrgId: adminUserInfo.Org.Id,
  6240. AdjustedValue: "/",
  6241. UserId: adminUserInfo.AdminUser.Id,
  6242. }
  6243. var value float64
  6244. value = dry_weight - weightAdjust.DryWeight
  6245. if value < 0 {
  6246. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6247. } else if value == 0 {
  6248. dryWeight.AdjustedValue = "/"
  6249. } else if value > 0 {
  6250. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6251. }
  6252. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6253. //康桥
  6254. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6255. timeNowStr := time.Now().Format("2006-01-02")
  6256. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6257. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6258. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6259. if beforAssesment.ID > 0 {
  6260. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6261. var dewater_amount float64
  6262. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6263. if adminUserInfo.Org.Id != 10702 {
  6264. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6265. }
  6266. if adminUserInfo.Org.Id == 10702 {
  6267. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6268. }
  6269. //获取key,清空redis
  6270. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6271. redis := service.RedisClient()
  6272. //清空key 值
  6273. redis.Set(key, "", time.Second)
  6274. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6275. //清空key 值
  6276. redis.Set(keyOne, "", time.Second)
  6277. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6278. //清空key 值
  6279. redis.Set(keyTwo, "", time.Second)
  6280. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6281. redis.Set(keySix, "", time.Second)
  6282. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6283. redis.Set(keySeven, "", time.Second)
  6284. }
  6285. }
  6286. redis := service.RedisClient()
  6287. loc, _ := time.LoadLocation("Local")
  6288. nowTime := time.Now()
  6289. nowDay := nowTime.Format("2006-01-02")
  6290. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6291. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6292. redis.Set(keyOne, "", time.Second)
  6293. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6294. redis.Set(key, "", time.Second)
  6295. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6296. redis.Set(keyTwo, "", time.Second)
  6297. redis.Close()
  6298. if createErr == nil {
  6299. c.ServeSuccessJSON(map[string]interface{}{
  6300. "msg": "提交成功",
  6301. "weight": dryWeight,
  6302. })
  6303. }
  6304. }
  6305. }
  6306. func (c *DialysisAPIController) GetSolution() {
  6307. patient_id, _ := c.GetInt64("patient_id")
  6308. mode_id, _ := c.GetInt64("mode_id")
  6309. adminUserInfo := c.GetMobileAdminUserInfo()
  6310. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6311. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6312. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6313. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6314. if err != nil {
  6315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6316. return
  6317. }
  6318. c.ServeSuccessJSON(map[string]interface{}{
  6319. "solution": solution,
  6320. "prescription": prescription,
  6321. "system_prescription": system_prescription,
  6322. "dialysisPrescription": dialysisPrescription,
  6323. })
  6324. }
  6325. func (c *DialysisAPIController) GetSchedule() {
  6326. schedual_type, _ := c.GetInt64("schedual_type")
  6327. adminUserInfo := c.GetMobileAdminUserInfo()
  6328. scheduleTime, _ := c.GetInt64("record_date")
  6329. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6330. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6331. c.ServeSuccessJSON(map[string]interface{}{
  6332. "number": deviceNumber,
  6333. "list": list,
  6334. })
  6335. }
  6336. func (c *DialysisAPIController) GetPatientId() {
  6337. id, _ := c.GetInt64("id")
  6338. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6339. patientId, _ := service.GetPatientId(id)
  6340. //获取该患者的所有传染病
  6341. list, _ := service.GetPatientInfectious(id)
  6342. c.ServeSuccessJSON(map[string]interface{}{
  6343. "patient": patientId,
  6344. "infectioulist": list,
  6345. })
  6346. }
  6347. func (this *DialysisAPIController) GetDialysisSchedule() {
  6348. schedualDate := this.GetString("date")
  6349. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6350. if parseDateErr != nil {
  6351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6352. return
  6353. }
  6354. adminInfo := this.GetMobileAdminUserInfo()
  6355. orgID := adminInfo.Org.Id
  6356. redis := service.RedisClient()
  6357. defer redis.Close()
  6358. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6359. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6360. if len(scheduals) > 0 {
  6361. //缓存数据
  6362. scheduals_json, err := json.Marshal(scheduals)
  6363. if err == nil {
  6364. redis.Set(key, scheduals_json, time.Second*30)
  6365. }
  6366. }
  6367. this.ServeSuccessJSON(map[string]interface{}{
  6368. "scheduals": scheduals,
  6369. })
  6370. }
  6371. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6372. change_type, _ := this.GetInt64("type", 0)
  6373. record_date := this.GetString("record_time")
  6374. patient_id, _ := this.GetInt64("patient_id", 0)
  6375. timeLayout := "2006-01-02"
  6376. loc, _ := time.LoadLocation("Local")
  6377. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6378. record_time := theAdviceRecordTime.Unix()
  6379. adminUserInfo := this.GetMobileAdminUserInfo()
  6380. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6381. if err == nil {
  6382. if len(advices) == 0 {
  6383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6384. return
  6385. } else {
  6386. this.ServeSuccessJSON(map[string]interface{}{
  6387. "advices": advices,
  6388. "schedule": sch,
  6389. })
  6390. return
  6391. }
  6392. } else {
  6393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6394. return
  6395. }
  6396. }
  6397. func (c *DialysisAPIController) CreateConsumables() {
  6398. record_date := c.GetString("record_time")
  6399. patient_id, _ := c.GetInt64("patient_id", 0)
  6400. active, _ := c.GetInt64("active")
  6401. adminUser := c.GetMobileAdminUserInfo()
  6402. timeLayout := "2006-01-02"
  6403. loc, _ := time.LoadLocation("Local")
  6404. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6405. record_time := theRecordTime.Unix()
  6406. // 查询信息规挡的设置天数
  6407. orgid := c.GetMobileAdminUserInfo().Org.Id
  6408. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6409. if infor.ID > 0 {
  6410. var cha_time int64
  6411. timeNowStr := time.Now().Format("2006-01-02")
  6412. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6413. //今日的日期减去设置的日期
  6414. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6415. if cha_time >= record_time {
  6416. //查询审核是否允许
  6417. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6418. //申请状态不允许的情况 拒绝修改
  6419. if infor.ApplicationStatus != 1 {
  6420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6421. return
  6422. }
  6423. }
  6424. }
  6425. dataBody := make(map[string]interface{}, 0)
  6426. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6427. if err != nil {
  6428. utils.ErrorLog(err.Error())
  6429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6430. return
  6431. }
  6432. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6433. var beforePrepares []*models.DialysisBeforePrepareGoods
  6434. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6435. var dialysisBefor []*models.DialysisBeforePrepare
  6436. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6437. goods, _ := dataBody["goods"].([]interface{})
  6438. if len(goods) > 0 {
  6439. for _, item := range goods {
  6440. items := item.(map[string]interface{})
  6441. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6442. utils.ErrorLog("good_id")
  6443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6444. return
  6445. }
  6446. good_id := int64(items["good_id"].(float64))
  6447. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6448. utils.ErrorLog("good_type_id")
  6449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6450. return
  6451. }
  6452. good_type_id := int64(items["good_type_id"].(float64))
  6453. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6454. utils.ErrorLog("count")
  6455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6456. return
  6457. }
  6458. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6459. commdity_code := items["commdity_code"].(string)
  6460. fmt.Println("commdity", commdity_code)
  6461. prepareGoods := &models.DialysisBeforePrepareGoods{
  6462. GoodTypeId: good_type_id,
  6463. GoodId: good_id,
  6464. Count: count,
  6465. StorehouseId: houseConfig.StorehouseOutInfo,
  6466. }
  6467. beforePrepares = append(beforePrepares, prepareGoods)
  6468. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6469. GoodTypeId: good_type_id,
  6470. GoodId: good_id,
  6471. Count: count,
  6472. StorehouseId: houseConfig.StorehouseOutInfo,
  6473. }
  6474. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6475. prepare := &models.DialysisBeforePrepare{
  6476. GoodTypeId: good_type_id,
  6477. GoodId: good_id,
  6478. Count: count,
  6479. PatientId: patient_id,
  6480. RecordDate: record_time,
  6481. UserOrgId: adminUser.Org.Id,
  6482. Status: 1,
  6483. Ctime: time.Now().Unix(),
  6484. Creater: adminUser.AdminUser.Id,
  6485. CommdityCode: commdity_code,
  6486. StorehouseId: houseConfig.StorehouseOutInfo,
  6487. }
  6488. dialysisBefor = append(dialysisBefor, prepare)
  6489. }
  6490. }
  6491. //查询是否有库存
  6492. for _, item := range dialysisBefor {
  6493. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6494. if err == gorm.ErrRecordNotFound {
  6495. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6496. c.ServeSuccessJSON(map[string]interface{}{
  6497. "message": "1",
  6498. "good_name": goodObj.GoodName,
  6499. "specification_name": goodObj.SpecificationName,
  6500. })
  6501. return
  6502. }
  6503. if err != nil {
  6504. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6505. c.ServeSuccessJSON(map[string]interface{}{
  6506. "message": "1",
  6507. "good_name": goodObj.GoodName,
  6508. "specification_name": goodObj.SpecificationName,
  6509. })
  6510. return
  6511. }
  6512. }
  6513. fmt.Println("active-----------------------", active)
  6514. fmt.Println("len(goods)-----------------------", len(goods))
  6515. //新增
  6516. if active == 1 && len(goods) > 0 {
  6517. for _, item := range dialysisBefor {
  6518. dialyPrepareOne := models.DialysisBeforePrepare{
  6519. GoodTypeId: item.GoodTypeId,
  6520. GoodId: item.GoodId,
  6521. PatientId: item.PatientId,
  6522. RecordDate: item.RecordDate,
  6523. UserOrgId: item.UserOrgId,
  6524. Count: item.Count,
  6525. Ctime: time.Now().Unix(),
  6526. Creater: item.Creater,
  6527. CommdityCode: item.CommdityCode,
  6528. Status: 1,
  6529. StorehouseId: houseConfig.StorehouseOutInfo,
  6530. }
  6531. //先清除再插入
  6532. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6533. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6534. //查询默认仓库
  6535. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6536. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6537. var total_count int64
  6538. for _, it := range stockList {
  6539. total_count += it.StockCount
  6540. }
  6541. //基础库插入数据
  6542. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6543. //更新库存
  6544. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6545. var flush_count int64
  6546. for _, it := range goodList {
  6547. flush_count += it.StockCount
  6548. }
  6549. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6550. }
  6551. if err == nil {
  6552. c.ServeSuccessJSON(map[string]interface{}{
  6553. "msg": "保存成功",
  6554. "message": "2",
  6555. })
  6556. return
  6557. } else {
  6558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6559. return
  6560. }
  6561. }
  6562. if len(beforePrepares) > 0 && active == 2 {
  6563. for _, item := range beforePrepares {
  6564. //1.查看该患者该耗材型号最后一次出库数量
  6565. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6566. //判断当前出库数量和最后一次出库数量的大小
  6567. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6568. if item.Count <= goodInfo.Count {
  6569. //退库
  6570. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6571. //查询今日出库数据
  6572. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6573. for _, it := range list {
  6574. prepare := models.DialysisBeforePrepare{
  6575. UserOrgId: it.OrgId,
  6576. PatientId: patient_id,
  6577. RecordDate: it.RecordTime,
  6578. GoodId: it.GoodId,
  6579. GoodTypeId: it.GoodTypeId,
  6580. Count: it.Count,
  6581. Ctime: time.Now().Unix(),
  6582. Creater: adminUser.AdminUser.Id,
  6583. Status: 1,
  6584. StorehouseId: houseConfig.StorehouseOutInfo,
  6585. }
  6586. //删除准备表数据
  6587. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6588. service.CreateDialysisBeforePrepareOne(&prepare)
  6589. }
  6590. }
  6591. var last_total int64
  6592. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6593. if item.Count >= goodInfo.Count {
  6594. //查询当前批次当前耗材最后一条出库数据
  6595. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6596. //计算当前出库和最后一次出库数据相差数据
  6597. last_total = item.Count - lastOutInfo.Count
  6598. //查询该批次剩余库存
  6599. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6600. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6601. if lastInfo.StockCount >= last_total {
  6602. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6603. //查询今日出库数据
  6604. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6605. for _, it := range list {
  6606. prepare := models.DialysisBeforePrepare{
  6607. UserOrgId: it.OrgId,
  6608. PatientId: patient_id,
  6609. RecordDate: it.RecordTime,
  6610. GoodId: it.GoodId,
  6611. GoodTypeId: it.GoodTypeId,
  6612. Count: it.Count,
  6613. Ctime: time.Now().Unix(),
  6614. Creater: adminUser.AdminUser.Id,
  6615. Status: 1,
  6616. StorehouseId: houseConfig.StorehouseOutInfo,
  6617. }
  6618. //删除准备表数据
  6619. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6620. service.CreateDialysisBeforePrepareOne(&prepare)
  6621. //查询默认仓库
  6622. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6623. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6624. var total_count int64
  6625. for _, it := range stockList {
  6626. total_count += it.StockCount
  6627. }
  6628. //基础库插入数据
  6629. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6630. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6631. var flush_count int64
  6632. for _, it := range goodList {
  6633. flush_count += it.StockCount
  6634. }
  6635. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6636. }
  6637. }
  6638. //如果库存不够,则出库到下一个批次
  6639. if lastInfo.StockCount < last_total {
  6640. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6641. //查询今日出库数据
  6642. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6643. for _, it := range list {
  6644. prepare := models.DialysisBeforePrepare{
  6645. UserOrgId: it.OrgId,
  6646. PatientId: patient_id,
  6647. RecordDate: it.RecordTime,
  6648. GoodId: it.GoodId,
  6649. GoodTypeId: it.GoodTypeId,
  6650. Count: it.Count,
  6651. Ctime: time.Now().Unix(),
  6652. Creater: adminUser.AdminUser.Id,
  6653. Status: 1,
  6654. StorehouseId: houseConfig.StorehouseOutInfo,
  6655. }
  6656. //删除准备表数据
  6657. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6658. service.CreateDialysisBeforePrepareOne(&prepare)
  6659. //查询默认仓库
  6660. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6661. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6662. var total_count int64
  6663. for _, it := range stockList {
  6664. total_count += it.StockCount
  6665. }
  6666. //基础库插入数据
  6667. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6668. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6669. var flush_count int64
  6670. for _, it := range goodList {
  6671. flush_count += it.StockCount
  6672. }
  6673. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6674. }
  6675. if err != nil {
  6676. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6677. c.ServeSuccessJSON(map[string]interface{}{
  6678. "message": "1",
  6679. "good_name": goodObj.GoodName,
  6680. "specification_name": goodObj.SpecificationName,
  6681. })
  6682. return
  6683. }
  6684. }
  6685. }
  6686. if err != nil {
  6687. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6688. c.ServeSuccessJSON(map[string]interface{}{
  6689. "message": "1",
  6690. "good_name": goodObj.GoodName,
  6691. "specification_name": goodObj.SpecificationName,
  6692. })
  6693. return
  6694. }
  6695. }
  6696. }
  6697. }
  6698. var errs error
  6699. if errs == nil {
  6700. c.ServeSuccessJSON(map[string]interface{}{
  6701. "msg": "提交成功",
  6702. "message": "2",
  6703. "good_name": "",
  6704. "specification_name": "",
  6705. })
  6706. return
  6707. } else {
  6708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6709. return
  6710. }
  6711. }
  6712. func (c *DialysisAPIController) CreateStockOutInfo() {
  6713. patient_id, _ := c.GetInt64("patient_id", 0)
  6714. record_date := c.GetString("record_time")
  6715. if patient_id <= 0 {
  6716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6717. return
  6718. }
  6719. adminInfo := c.GetMobileAdminUserInfo()
  6720. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6721. timeLayout := "2006-01-02"
  6722. loc, _ := time.LoadLocation("Local")
  6723. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6724. record_time := theRecordTime.Unix()
  6725. // 查询信息规挡的设置天数
  6726. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6727. if infor.ID > 0 && infor.WeekDay > 0 {
  6728. var cha_time int64
  6729. timeNowStr := time.Now().Format("2006-01-02")
  6730. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6731. //今日的日期减去设置的日期
  6732. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6733. if cha_time >= record_time {
  6734. //查询审核是否允许
  6735. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6736. //申请状态不允许的情况 拒绝修改
  6737. if infor.ApplicationStatus != 1 {
  6738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6739. return
  6740. }
  6741. }
  6742. }
  6743. //创建步骤表
  6744. finish := models.XtDialysisFinish{
  6745. IsFinish: 1,
  6746. UserOrgId: adminInfo.Org.Id,
  6747. Status: 1,
  6748. Ctime: time.Now().Unix(),
  6749. Mtime: 0,
  6750. Module: 11,
  6751. RecordDate: record_time,
  6752. Sourse: 1,
  6753. PatientId: patient_id,
  6754. }
  6755. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6756. if dialysisFinish.ID == 0 {
  6757. service.CreateDialysisFinish(finish)
  6758. }
  6759. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6760. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6761. //去重
  6762. consumables = RemoveRepeatedGood(consumables)
  6763. if adminInfo.Org.Id == 9919 {
  6764. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6765. //查询是否有库存
  6766. for _, item := range consumables {
  6767. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6768. if item.Count > warehouse.Count {
  6769. goodErrcode := models.XtGoodErrcode{
  6770. UserOrgId: item.UserOrgId,
  6771. Errcode: "自动出库库存不足",
  6772. GoodId: item.GoodId,
  6773. Status: 1,
  6774. Ctime: time.Now().Unix(),
  6775. Mtime: 0,
  6776. Count: 0,
  6777. StockCount: 0,
  6778. Creater: creator,
  6779. BatchNumberId: warehouse.ID,
  6780. WarehouseOutId: 0,
  6781. }
  6782. service.CreateGoodErrcode(goodErrcode)
  6783. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6784. c.ServeSuccessJSON(map[string]interface{}{
  6785. "message": "1",
  6786. "good_name": goodObj.GoodName,
  6787. "specification_name": goodObj.SpecificationName,
  6788. })
  6789. return
  6790. }
  6791. }
  6792. //查询是否有出库单
  6793. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6794. if err == gorm.ErrRecordNotFound {
  6795. //没有记录,则创建出库单
  6796. timeStr := time.Now().Format("2006-01-02")
  6797. timeArr := strings.Split(timeStr, "-")
  6798. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6799. total = total + 1
  6800. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6801. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6802. number = number + total
  6803. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6804. creater := adminInfo.AdminUser.Id
  6805. warehouseOut := models.WarehouseOut{
  6806. WarehouseOutOrderNumber: warehousing_out_order,
  6807. OperationTime: time.Now().Unix(),
  6808. OrgId: adminInfo.Org.Id,
  6809. Creater: creater,
  6810. Ctime: time.Now().Unix(),
  6811. Status: 1,
  6812. WarehouseOutTime: record_time,
  6813. Dealer: 0,
  6814. Manufacturer: 0,
  6815. Type: 1,
  6816. IsSys: 1,
  6817. StorehouseId: houseConfig.StorehouseOutInfo,
  6818. IsCheck: 1,
  6819. }
  6820. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6821. if err != nil {
  6822. goodErrcode := models.XtGoodErrcode{
  6823. UserOrgId: adminInfo.Org.Id,
  6824. Errcode: "创建出库单失败",
  6825. GoodId: 0,
  6826. Status: 1,
  6827. Ctime: time.Now().Unix(),
  6828. Mtime: 0,
  6829. Count: 0,
  6830. StockCount: 0,
  6831. Creater: creator,
  6832. BatchNumberId: 0,
  6833. WarehouseOutId: 0,
  6834. }
  6835. service.CreateGoodErrcode(goodErrcode)
  6836. utils.TraceLog("创建出库单失败 err = %v", err)
  6837. } else {
  6838. for _, item := range consumables {
  6839. //出库
  6840. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6841. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6842. if err == nil {
  6843. goodErrcode := models.XtGoodErrcode{
  6844. UserOrgId: adminInfo.Org.Id,
  6845. Errcode: "自动出库接口报错",
  6846. GoodId: 0,
  6847. Status: 1,
  6848. Ctime: time.Now().Unix(),
  6849. Mtime: 0,
  6850. Count: 0,
  6851. StockCount: 0,
  6852. Creater: creator,
  6853. BatchNumberId: 0,
  6854. WarehouseOutId: 0,
  6855. }
  6856. service.CreateGoodErrcode(goodErrcode)
  6857. utils.TraceLog("创建出库单失败 err = %v", err)
  6858. }
  6859. //查询
  6860. //出库数量相加
  6861. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6862. if errs != nil {
  6863. goodErrcode := models.XtGoodErrcode{
  6864. UserOrgId: item.UserOrgId,
  6865. Errcode: "创建剩余库存字段报错",
  6866. GoodId: item.GoodId,
  6867. Status: 1,
  6868. Ctime: time.Now().Unix(),
  6869. Mtime: 0,
  6870. Count: 0,
  6871. StockCount: 0,
  6872. Creater: creater,
  6873. BatchNumberId: 0,
  6874. WarehouseOutId: 0,
  6875. }
  6876. service.CreateGoodErrcode(goodErrcode)
  6877. }
  6878. }
  6879. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6880. if len(list) == 0 {
  6881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6882. return
  6883. }
  6884. for _, item := range list {
  6885. prepare := models.DialysisBeforePrepare{
  6886. UserOrgId: adminInfo.Org.Id,
  6887. PatientId: patient_id,
  6888. RecordDate: record_time,
  6889. GoodId: item.GoodId,
  6890. GoodTypeId: item.GoodTypeId,
  6891. Count: item.Count,
  6892. Creater: adminInfo.AdminUser.Id,
  6893. Status: 1,
  6894. Ctime: time.Now().Unix(),
  6895. StorehouseId: houseConfig.StorehouseOutInfo,
  6896. }
  6897. //清空准备表数据
  6898. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6899. if err != nil {
  6900. goodErrcode := models.XtGoodErrcode{
  6901. UserOrgId: item.OrgId,
  6902. Errcode: "自动出库清空准备表数据报错",
  6903. GoodId: item.GoodId,
  6904. Status: 1,
  6905. Ctime: time.Now().Unix(),
  6906. Mtime: 0,
  6907. Count: 0,
  6908. StockCount: 0,
  6909. Creater: creater,
  6910. BatchNumberId: 0,
  6911. WarehouseOutId: 0,
  6912. }
  6913. service.CreateGoodErrcode(goodErrcode)
  6914. }
  6915. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6916. if errs != nil {
  6917. goodErrcode := models.XtGoodErrcode{
  6918. UserOrgId: item.OrgId,
  6919. Errcode: "自动出库创建准备表数据报错",
  6920. GoodId: item.GoodId,
  6921. Status: 1,
  6922. Ctime: time.Now().Unix(),
  6923. Mtime: 0,
  6924. Count: 0,
  6925. StockCount: 0,
  6926. Creater: creater,
  6927. BatchNumberId: 0,
  6928. WarehouseOutId: 0,
  6929. }
  6930. service.CreateGoodErrcode(goodErrcode)
  6931. }
  6932. //查询默认仓库
  6933. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6934. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6935. var total_count int64
  6936. for _, it := range stockList {
  6937. total_count += it.StockCount
  6938. }
  6939. //基础库插入数据
  6940. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6941. if errcodes != nil {
  6942. goodErrcode := models.XtGoodErrcode{
  6943. UserOrgId: item.OrgId,
  6944. Errcode: "自动出库基础库插入数据",
  6945. GoodId: item.GoodId,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Count: 0,
  6950. StockCount: 0,
  6951. Creater: creater,
  6952. BatchNumberId: 0,
  6953. WarehouseOutId: 0,
  6954. }
  6955. service.CreateGoodErrcode(goodErrcode)
  6956. }
  6957. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6958. var flush_count int64
  6959. for _, it := range goodList {
  6960. flush_count += it.StockCount
  6961. }
  6962. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6963. if errsss != nil {
  6964. goodErrcode := models.XtGoodErrcode{
  6965. UserOrgId: item.OrgId,
  6966. Errcode: "自动出库剩余库存更新数据",
  6967. GoodId: item.GoodId,
  6968. Status: 1,
  6969. Ctime: time.Now().Unix(),
  6970. Mtime: 0,
  6971. Count: 0,
  6972. StockCount: 0,
  6973. Creater: creater,
  6974. BatchNumberId: 0,
  6975. WarehouseOutId: 0,
  6976. }
  6977. service.CreateGoodErrcode(goodErrcode)
  6978. }
  6979. }
  6980. }
  6981. //
  6982. } else if err == nil {
  6983. for _, item := range consumables {
  6984. //出库
  6985. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6986. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6987. if err != nil {
  6988. goodErrcode := models.XtGoodErrcode{
  6989. UserOrgId: adminInfo.Org.Id,
  6990. Errcode: "自动出库接口报错",
  6991. GoodId: 0,
  6992. Status: 1,
  6993. Ctime: time.Now().Unix(),
  6994. Mtime: 0,
  6995. Count: 0,
  6996. StockCount: 0,
  6997. Creater: creator,
  6998. BatchNumberId: 0,
  6999. WarehouseOutId: 0,
  7000. }
  7001. service.CreateGoodErrcode(goodErrcode)
  7002. }
  7003. //出库数量相加
  7004. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7005. if errss != nil {
  7006. goodErrcode := models.XtGoodErrcode{
  7007. UserOrgId: item.UserOrgId,
  7008. Errcode: "创建剩余库存字段报错",
  7009. GoodId: item.GoodId,
  7010. Status: 1,
  7011. Ctime: time.Now().Unix(),
  7012. Mtime: time.Now().Unix(),
  7013. Count: 0,
  7014. StockCount: 0,
  7015. Creater: item.Creater,
  7016. BatchNumberId: 0,
  7017. WarehouseOutId: 0,
  7018. }
  7019. service.CreateGoodErrcode(goodErrcode)
  7020. }
  7021. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7022. if len(list) == 0 {
  7023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7024. return
  7025. }
  7026. for _, item := range list {
  7027. prepare := models.DialysisBeforePrepare{
  7028. UserOrgId: adminInfo.Org.Id,
  7029. PatientId: patient_id,
  7030. RecordDate: record_time,
  7031. GoodId: item.GoodId,
  7032. GoodTypeId: item.GoodTypeId,
  7033. Count: item.Count,
  7034. Creater: adminInfo.AdminUser.Id,
  7035. Status: 1,
  7036. Ctime: time.Now().Unix(),
  7037. StorehouseId: houseConfig.StorehouseOutInfo,
  7038. }
  7039. //清空准备表数据
  7040. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7041. if errs != nil {
  7042. goodErrcode := models.XtGoodErrcode{
  7043. UserOrgId: adminInfo.Org.Id,
  7044. Errcode: "自动出库清空准备表数据报错",
  7045. GoodId: 0,
  7046. Status: 1,
  7047. Ctime: time.Now().Unix(),
  7048. Mtime: 0,
  7049. Count: 0,
  7050. StockCount: 0,
  7051. Creater: creator,
  7052. BatchNumberId: 0,
  7053. WarehouseOutId: 0,
  7054. }
  7055. service.CreateGoodErrcode(goodErrcode)
  7056. }
  7057. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7058. if errcodes != nil {
  7059. goodErrcode := models.XtGoodErrcode{
  7060. UserOrgId: adminInfo.Org.Id,
  7061. Errcode: "自动出库创建准备表数据报错",
  7062. GoodId: 0,
  7063. Status: 1,
  7064. Ctime: time.Now().Unix(),
  7065. Mtime: 0,
  7066. Count: 0,
  7067. StockCount: 0,
  7068. Creater: creator,
  7069. BatchNumberId: 0,
  7070. WarehouseOutId: 0,
  7071. }
  7072. service.CreateGoodErrcode(goodErrcode)
  7073. }
  7074. //查询默认仓库
  7075. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7076. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7077. var total_count int64
  7078. for _, it := range stockList {
  7079. total_count += it.StockCount
  7080. }
  7081. //基础库插入数据
  7082. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7083. if errcodes != nil {
  7084. goodErrcode := models.XtGoodErrcode{
  7085. UserOrgId: adminInfo.Org.Id,
  7086. Errcode: "自动出库基础库插入数据报错",
  7087. GoodId: 0,
  7088. Status: 1,
  7089. Ctime: time.Now().Unix(),
  7090. Mtime: 0,
  7091. Count: 0,
  7092. StockCount: 0,
  7093. Creater: creator,
  7094. BatchNumberId: 0,
  7095. WarehouseOutId: 0,
  7096. }
  7097. service.CreateGoodErrcode(goodErrcode)
  7098. }
  7099. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7100. var flush_count int64
  7101. for _, it := range goodList {
  7102. flush_count += it.StockCount
  7103. }
  7104. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7105. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7106. if errss != nil {
  7107. goodErrcode := models.XtGoodErrcode{
  7108. UserOrgId: item.OrgId,
  7109. Errcode: "自动出库剩余库存更新数据",
  7110. GoodId: item.GoodId,
  7111. Status: 1,
  7112. Ctime: time.Now().Unix(),
  7113. Mtime: 0,
  7114. Count: 0,
  7115. StockCount: 0,
  7116. Creater: creater,
  7117. BatchNumberId: 0,
  7118. WarehouseOutId: 0,
  7119. }
  7120. service.CreateGoodErrcode(goodErrcode)
  7121. }
  7122. }
  7123. }
  7124. }
  7125. c.ServeSuccessJSON(map[string]interface{}{
  7126. "msg": "提交成功",
  7127. "message": "2",
  7128. "good_name": "",
  7129. "specification_name": "",
  7130. })
  7131. return
  7132. }
  7133. if record.IsOpen == 1 {
  7134. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7135. //查询是否有库存
  7136. for _, item := range consumables {
  7137. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7138. if item.Count > warehouse.Count {
  7139. goodErrcode := models.XtGoodErrcode{
  7140. UserOrgId: item.UserOrgId,
  7141. Errcode: "自动出库库存不足",
  7142. GoodId: item.GoodId,
  7143. Status: 1,
  7144. Ctime: time.Now().Unix(),
  7145. Mtime: 0,
  7146. Count: 0,
  7147. StockCount: 0,
  7148. Creater: creator,
  7149. BatchNumberId: warehouse.ID,
  7150. WarehouseOutId: 0,
  7151. }
  7152. service.CreateGoodErrcode(goodErrcode)
  7153. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "message": "1",
  7156. "good_name": goodObj.GoodName,
  7157. "specification_name": goodObj.SpecificationName,
  7158. })
  7159. return
  7160. }
  7161. }
  7162. //查询是否有出库单
  7163. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7164. if err == gorm.ErrRecordNotFound {
  7165. //没有记录,则创建出库单
  7166. timeStr := time.Now().Format("2006-01-02")
  7167. timeArr := strings.Split(timeStr, "-")
  7168. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7169. total = total + 1
  7170. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7171. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7172. number = number + total
  7173. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7174. creater := adminInfo.AdminUser.Id
  7175. warehouseOut := models.WarehouseOut{
  7176. WarehouseOutOrderNumber: warehousing_out_order,
  7177. OperationTime: time.Now().Unix(),
  7178. OrgId: adminInfo.Org.Id,
  7179. Creater: creater,
  7180. Ctime: time.Now().Unix(),
  7181. Status: 1,
  7182. WarehouseOutTime: record_time,
  7183. Dealer: 0,
  7184. Manufacturer: 0,
  7185. Type: 1,
  7186. IsSys: 1,
  7187. StorehouseId: houseConfig.StorehouseOutInfo,
  7188. IsCheck: 1,
  7189. }
  7190. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7191. if err != nil {
  7192. goodErrcode := models.XtGoodErrcode{
  7193. UserOrgId: adminInfo.Org.Id,
  7194. Errcode: "创建出库单失败",
  7195. GoodId: 0,
  7196. Status: 1,
  7197. Ctime: time.Now().Unix(),
  7198. Mtime: 0,
  7199. Count: 0,
  7200. StockCount: 0,
  7201. Creater: creator,
  7202. BatchNumberId: 0,
  7203. WarehouseOutId: 0,
  7204. }
  7205. service.CreateGoodErrcode(goodErrcode)
  7206. utils.TraceLog("创建出库单失败 err = %v", err)
  7207. } else {
  7208. for _, item := range consumables {
  7209. //出库
  7210. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7211. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7212. if err == nil {
  7213. goodErrcode := models.XtGoodErrcode{
  7214. UserOrgId: adminInfo.Org.Id,
  7215. Errcode: "自动出库接口报错",
  7216. GoodId: 0,
  7217. Status: 1,
  7218. Ctime: time.Now().Unix(),
  7219. Mtime: 0,
  7220. Count: 0,
  7221. StockCount: 0,
  7222. Creater: creator,
  7223. BatchNumberId: 0,
  7224. WarehouseOutId: 0,
  7225. }
  7226. service.CreateGoodErrcode(goodErrcode)
  7227. utils.TraceLog("创建出库单失败 err = %v", err)
  7228. }
  7229. //查询
  7230. //出库数量相加
  7231. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7232. if errs != nil {
  7233. goodErrcode := models.XtGoodErrcode{
  7234. UserOrgId: item.UserOrgId,
  7235. Errcode: "创建剩余库存字段报错",
  7236. GoodId: item.GoodId,
  7237. Status: 1,
  7238. Ctime: time.Now().Unix(),
  7239. Mtime: 0,
  7240. Count: 0,
  7241. StockCount: 0,
  7242. Creater: creater,
  7243. BatchNumberId: 0,
  7244. WarehouseOutId: 0,
  7245. }
  7246. service.CreateGoodErrcode(goodErrcode)
  7247. }
  7248. }
  7249. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7250. if len(list) == 0 {
  7251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7252. return
  7253. }
  7254. for _, item := range list {
  7255. prepare := models.DialysisBeforePrepare{
  7256. UserOrgId: adminInfo.Org.Id,
  7257. PatientId: patient_id,
  7258. RecordDate: record_time,
  7259. GoodId: item.GoodId,
  7260. GoodTypeId: item.GoodTypeId,
  7261. Count: item.Count,
  7262. Creater: adminInfo.AdminUser.Id,
  7263. Status: 1,
  7264. Ctime: time.Now().Unix(),
  7265. StorehouseId: houseConfig.StorehouseOutInfo,
  7266. }
  7267. //清空准备表数据
  7268. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7269. if err != nil {
  7270. goodErrcode := models.XtGoodErrcode{
  7271. UserOrgId: item.OrgId,
  7272. Errcode: "自动出库清空准备表数据报错",
  7273. GoodId: item.GoodId,
  7274. Status: 1,
  7275. Ctime: time.Now().Unix(),
  7276. Mtime: 0,
  7277. Count: 0,
  7278. StockCount: 0,
  7279. Creater: creater,
  7280. BatchNumberId: 0,
  7281. WarehouseOutId: 0,
  7282. }
  7283. service.CreateGoodErrcode(goodErrcode)
  7284. }
  7285. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7286. if errs != nil {
  7287. goodErrcode := models.XtGoodErrcode{
  7288. UserOrgId: item.OrgId,
  7289. Errcode: "自动出库创建准备表数据报错",
  7290. GoodId: item.GoodId,
  7291. Status: 1,
  7292. Ctime: time.Now().Unix(),
  7293. Mtime: 0,
  7294. Count: 0,
  7295. StockCount: 0,
  7296. Creater: creater,
  7297. BatchNumberId: 0,
  7298. WarehouseOutId: 0,
  7299. }
  7300. service.CreateGoodErrcode(goodErrcode)
  7301. }
  7302. //查询默认仓库
  7303. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7304. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7305. var total_count int64
  7306. for _, it := range stockList {
  7307. total_count += it.StockCount
  7308. }
  7309. //基础库插入数据
  7310. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7311. if errcodes != nil {
  7312. goodErrcode := models.XtGoodErrcode{
  7313. UserOrgId: item.OrgId,
  7314. Errcode: "自动出库基础库插入数据",
  7315. GoodId: item.GoodId,
  7316. Status: 1,
  7317. Ctime: time.Now().Unix(),
  7318. Mtime: 0,
  7319. Count: 0,
  7320. StockCount: 0,
  7321. Creater: creater,
  7322. BatchNumberId: 0,
  7323. WarehouseOutId: 0,
  7324. }
  7325. service.CreateGoodErrcode(goodErrcode)
  7326. }
  7327. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7328. var flush_count int64
  7329. for _, it := range goodList {
  7330. flush_count += it.StockCount
  7331. }
  7332. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7333. if errsss != nil {
  7334. goodErrcode := models.XtGoodErrcode{
  7335. UserOrgId: item.OrgId,
  7336. Errcode: "自动出库剩余库存更新数据",
  7337. GoodId: item.GoodId,
  7338. Status: 1,
  7339. Ctime: time.Now().Unix(),
  7340. Mtime: 0,
  7341. Count: 0,
  7342. StockCount: 0,
  7343. Creater: creater,
  7344. BatchNumberId: 0,
  7345. WarehouseOutId: 0,
  7346. }
  7347. service.CreateGoodErrcode(goodErrcode)
  7348. }
  7349. }
  7350. }
  7351. //
  7352. } else if err == nil {
  7353. for _, item := range consumables {
  7354. //出库
  7355. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7356. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7357. if err != nil {
  7358. goodErrcode := models.XtGoodErrcode{
  7359. UserOrgId: adminInfo.Org.Id,
  7360. Errcode: "自动出库接口报错",
  7361. GoodId: 0,
  7362. Status: 1,
  7363. Ctime: time.Now().Unix(),
  7364. Mtime: 0,
  7365. Count: 0,
  7366. StockCount: 0,
  7367. Creater: creator,
  7368. BatchNumberId: 0,
  7369. WarehouseOutId: 0,
  7370. }
  7371. service.CreateGoodErrcode(goodErrcode)
  7372. }
  7373. //出库数量相加
  7374. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7375. if errss != nil {
  7376. goodErrcode := models.XtGoodErrcode{
  7377. UserOrgId: item.UserOrgId,
  7378. Errcode: "创建剩余库存字段报错",
  7379. GoodId: item.GoodId,
  7380. Status: 1,
  7381. Ctime: time.Now().Unix(),
  7382. Mtime: time.Now().Unix(),
  7383. Count: 0,
  7384. StockCount: 0,
  7385. Creater: item.Creater,
  7386. BatchNumberId: 0,
  7387. WarehouseOutId: 0,
  7388. }
  7389. service.CreateGoodErrcode(goodErrcode)
  7390. }
  7391. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7392. if len(list) == 0 {
  7393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7394. return
  7395. }
  7396. for _, item := range list {
  7397. prepare := models.DialysisBeforePrepare{
  7398. UserOrgId: adminInfo.Org.Id,
  7399. PatientId: patient_id,
  7400. RecordDate: record_time,
  7401. GoodId: item.GoodId,
  7402. GoodTypeId: item.GoodTypeId,
  7403. Count: item.Count,
  7404. Creater: adminInfo.AdminUser.Id,
  7405. Status: 1,
  7406. Ctime: time.Now().Unix(),
  7407. StorehouseId: houseConfig.StorehouseOutInfo,
  7408. }
  7409. //清空准备表数据
  7410. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7411. if errs != nil {
  7412. goodErrcode := models.XtGoodErrcode{
  7413. UserOrgId: adminInfo.Org.Id,
  7414. Errcode: "自动出库清空准备表数据报错",
  7415. GoodId: 0,
  7416. Status: 1,
  7417. Ctime: time.Now().Unix(),
  7418. Mtime: 0,
  7419. Count: 0,
  7420. StockCount: 0,
  7421. Creater: creator,
  7422. BatchNumberId: 0,
  7423. WarehouseOutId: 0,
  7424. }
  7425. service.CreateGoodErrcode(goodErrcode)
  7426. }
  7427. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7428. if errcodes != nil {
  7429. goodErrcode := models.XtGoodErrcode{
  7430. UserOrgId: adminInfo.Org.Id,
  7431. Errcode: "自动出库创建准备表数据报错",
  7432. GoodId: 0,
  7433. Status: 1,
  7434. Ctime: time.Now().Unix(),
  7435. Mtime: 0,
  7436. Count: 0,
  7437. StockCount: 0,
  7438. Creater: creator,
  7439. BatchNumberId: 0,
  7440. WarehouseOutId: 0,
  7441. }
  7442. service.CreateGoodErrcode(goodErrcode)
  7443. }
  7444. //查询默认仓库
  7445. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7446. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7447. var total_count int64
  7448. for _, it := range stockList {
  7449. total_count += it.StockCount
  7450. }
  7451. //基础库插入数据
  7452. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7453. if errcodes != nil {
  7454. goodErrcode := models.XtGoodErrcode{
  7455. UserOrgId: adminInfo.Org.Id,
  7456. Errcode: "自动出库基础库插入数据报错",
  7457. GoodId: 0,
  7458. Status: 1,
  7459. Ctime: time.Now().Unix(),
  7460. Mtime: 0,
  7461. Count: 0,
  7462. StockCount: 0,
  7463. Creater: creator,
  7464. BatchNumberId: 0,
  7465. WarehouseOutId: 0,
  7466. }
  7467. service.CreateGoodErrcode(goodErrcode)
  7468. }
  7469. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7470. var flush_count int64
  7471. for _, it := range goodList {
  7472. flush_count += it.StockCount
  7473. }
  7474. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7475. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7476. if errss != nil {
  7477. goodErrcode := models.XtGoodErrcode{
  7478. UserOrgId: item.OrgId,
  7479. Errcode: "自动出库剩余库存更新数据",
  7480. GoodId: item.GoodId,
  7481. Status: 1,
  7482. Ctime: time.Now().Unix(),
  7483. Mtime: 0,
  7484. Count: 0,
  7485. StockCount: 0,
  7486. Creater: creater,
  7487. BatchNumberId: 0,
  7488. WarehouseOutId: 0,
  7489. }
  7490. service.CreateGoodErrcode(goodErrcode)
  7491. }
  7492. }
  7493. }
  7494. }
  7495. c.ServeSuccessJSON(map[string]interface{}{
  7496. "msg": "提交成功",
  7497. "message": "2",
  7498. "good_name": "",
  7499. "specification_name": "",
  7500. })
  7501. return
  7502. } else {
  7503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7504. return
  7505. }
  7506. }
  7507. func (c *DialysisAPIController) EditConsumables() {
  7508. patient_id, _ := c.GetInt64("patient_id", 0)
  7509. record_date := c.GetString("record_time")
  7510. if patient_id <= 0 {
  7511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7512. return
  7513. }
  7514. adminInfo := c.GetMobileAdminUserInfo()
  7515. timeLayout := "2006-01-02"
  7516. loc, _ := time.LoadLocation("Local")
  7517. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7518. record_time := theRecordTime.Unix()
  7519. // 查询信息规挡的设置天数
  7520. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7521. if infor.ID > 0 && infor.WeekDay > 0 {
  7522. var cha_time int64
  7523. timeNowStr := time.Now().Format("2006-01-02")
  7524. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7525. //今日的日期减去设置的日期
  7526. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7527. if cha_time >= record_time {
  7528. //查询审核是否允许
  7529. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7530. //申请状态不允许的情况 拒绝修改
  7531. if infor.ApplicationStatus != 1 {
  7532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7533. return
  7534. }
  7535. }
  7536. }
  7537. dataBody := make(map[string]interface{}, 0)
  7538. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7539. if err != nil {
  7540. utils.ErrorLog(err.Error())
  7541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7542. return
  7543. }
  7544. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7545. var beforePrepares []*models.DialysisBeforePrepareGoods
  7546. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7547. var cancelbefor []*models.DialysisBeforePrepareGoods
  7548. var outbefor []*models.DialysisBeforePrepareGoods
  7549. //判断是否开启自动出库
  7550. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7551. if record.IsOpen == 1 {
  7552. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7553. goods, _ := dataBody["goods"].([]interface{})
  7554. if len(goods) > 0 {
  7555. for _, item := range goods {
  7556. items := item.(map[string]interface{})
  7557. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7558. utils.ErrorLog("good_id")
  7559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7560. return
  7561. }
  7562. good_id := int64(items["good_id"].(float64))
  7563. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7564. utils.ErrorLog("good_type_id")
  7565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7566. return
  7567. }
  7568. good_type_id := int64(items["good_type_id"].(float64))
  7569. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7570. utils.ErrorLog("count")
  7571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7572. return
  7573. }
  7574. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7575. commdity_code := items["commdity_code"].(string)
  7576. fmt.Println(commdity_code)
  7577. prepareGoods := &models.DialysisBeforePrepareGoods{
  7578. GoodTypeId: good_type_id,
  7579. GoodId: good_id,
  7580. Count: count,
  7581. StorehouseId: houseConfig.StorehouseOutInfo,
  7582. }
  7583. beforePrepares = append(beforePrepares, prepareGoods)
  7584. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7585. GoodTypeId: good_type_id,
  7586. GoodId: good_id,
  7587. Count: count,
  7588. StorehouseId: houseConfig.StorehouseOutInfo,
  7589. }
  7590. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7591. }
  7592. for _, item := range beforePrepares {
  7593. //1.查看该患者该耗材型号最后一次出库数量
  7594. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7595. //判断当前出库数量和最后一次出库数量的大小
  7596. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7597. if item.Count < goodInfo.Count {
  7598. cancelbefor = append(cancelbefor, item)
  7599. }
  7600. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7601. if item.Count > goodInfo.Count {
  7602. outbefor = append(outbefor, item)
  7603. }
  7604. //处理编辑耗材新增不了的问题
  7605. if goodInfo.Count == item.Count {
  7606. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7607. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7608. }
  7609. }
  7610. if len(cancelbefor) > 0 {
  7611. //退库
  7612. for _, item := range cancelbefor {
  7613. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7614. creater := adminInfo.AdminUser.Id
  7615. //查询该患者当天已经出库的耗材信息
  7616. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7617. var delete_count int64 = 0
  7618. delete_count = warehouseOutInfos.Count - item.Count
  7619. //增加库存数量
  7620. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7621. //减少实际出库库存数量
  7622. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7623. // 删除出库完成后,要增加对应批次的库存数量
  7624. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7625. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7626. //更新剩余库存
  7627. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7628. var flush_count int64
  7629. for _, it := range goodListOne {
  7630. flush_count += it.StockCount
  7631. }
  7632. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7633. //查询剩余库存
  7634. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7635. var sum_count int64
  7636. for _, item := range goodList {
  7637. sum_count += item.StockCount
  7638. }
  7639. // 在出库记录表里记录退库详情
  7640. warehouseOutInfo := &models.WarehouseOutInfo{
  7641. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7642. WarehouseOutId: warehouseOut.ID,
  7643. Status: 1,
  7644. Ctime: time.Now().Unix(),
  7645. OrgId: adminInfo.Org.Id,
  7646. Type: 1,
  7647. IsSys: 1,
  7648. SysRecordTime: record_time,
  7649. GoodTypeId: item.GoodTypeId,
  7650. GoodId: item.GoodId,
  7651. PatientId: patient_id,
  7652. ConsumableType: 2,
  7653. StorehouseId: houseConfig.StorehouseOutInfo,
  7654. IsCheck: 1,
  7655. OverCount: sum_count,
  7656. }
  7657. warehouseOutInfo.Count = item.Count
  7658. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7659. warehouseOutInfo.Price = stockInInfo.Price
  7660. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7661. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7662. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7663. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7664. warehouseOutInfo.Number = warehouseOutInfos.Number
  7665. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7666. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7667. //查找当天是否存在出库记录
  7668. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7669. if errcod == gorm.ErrRecordNotFound {
  7670. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7671. //插入详情明细表
  7672. stockFlow := models.VmStockFlow{
  7673. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7674. WarehouseOutId: warehouseOut.ID,
  7675. GoodId: item.GoodId,
  7676. Number: warehouseOutInfos.Number,
  7677. ProductDate: stockInInfo.ProductDate,
  7678. ExpireDate: stockInInfo.ExpiryDate,
  7679. Count: item.Count,
  7680. Price: stockInInfo.Price,
  7681. Status: 1,
  7682. Ctime: record_time,
  7683. UserOrgId: adminInfo.Org.Id,
  7684. Manufacturer: stockInInfo.Manufacturer,
  7685. Dealer: stockInInfo.Dealer,
  7686. LicenseNumber: stockInInfo.LicenseNumber,
  7687. IsEdit: 2,
  7688. Creator: creater,
  7689. SystemTime: record_time,
  7690. ConsumableType: 3,
  7691. WarehousingDetailId: 0,
  7692. IsSys: 1,
  7693. UpdateCreator: creater,
  7694. PatientId: patient_id,
  7695. StorehouseId: houseConfig.StorehouseOutInfo,
  7696. }
  7697. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7698. if errflow == gorm.ErrRecordNotFound {
  7699. //创建流水表
  7700. err := service.CreateStockFlowOne(stockFlow)
  7701. fmt.Println("err", err)
  7702. } else if errflow == nil {
  7703. //插入详情明细表
  7704. stockFlow := models.VmStockFlow{
  7705. ID: exsit.ID,
  7706. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7707. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7708. WarehouseOutId: warehouseOut.ID,
  7709. GoodId: item.GoodId,
  7710. Number: warehouseOutInfos.Number,
  7711. ProductDate: stockInInfo.ProductDate,
  7712. ExpireDate: stockInInfo.ExpiryDate,
  7713. Count: exsit.Count - delete_count,
  7714. Price: stockInInfo.Price,
  7715. Status: 1,
  7716. Ctime: record_time,
  7717. UserOrgId: adminInfo.Org.Id,
  7718. Manufacturer: stockInInfo.Manufacturer,
  7719. Dealer: stockInInfo.Dealer,
  7720. LicenseNumber: stockInInfo.LicenseNumber,
  7721. IsEdit: 2,
  7722. Creator: creater,
  7723. SystemTime: record_time,
  7724. ConsumableType: 3,
  7725. WarehousingDetailId: 0,
  7726. IsSys: 1,
  7727. UpdateCreator: creater,
  7728. PatientId: patient_id,
  7729. StorehouseId: houseConfig.StorehouseOutInfo,
  7730. }
  7731. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7732. }
  7733. } else if errcod == nil {
  7734. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7735. //查询剩余库存
  7736. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7737. var sum_count int64
  7738. for _, item := range goodList {
  7739. sum_count += item.StockCount
  7740. }
  7741. //创建退库单,生成退库数据
  7742. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7743. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7744. operation_time := time.Now().Unix()
  7745. creater := adminInfo.AdminUser.Id
  7746. //创建退库单
  7747. timeStr := time.Now().Format("2006-01-02")
  7748. timeArr := strings.Split(timeStr, "-")
  7749. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7750. total = total + 1
  7751. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7752. cancelStock := models.CancelStock{
  7753. OrderNumber: orderNumber,
  7754. OperaTime: operation_time,
  7755. OrgId: adminInfo.Org.Id,
  7756. Creater: creater,
  7757. Ctime: time.Now().Unix(),
  7758. Status: 1,
  7759. ReturnTime: record_time,
  7760. Type: 1,
  7761. StorehouseId: houseConfig.StorehouseOutInfo,
  7762. IsCheck: 1,
  7763. }
  7764. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7765. if msgerrkonde == gorm.ErrRecordNotFound {
  7766. service.AddSigleCancelStock(&cancelStock)
  7767. }
  7768. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7769. //查询是否有出库
  7770. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7771. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7772. deaerler, _ := service.GetDealerById(info.Dealer)
  7773. if info.ID > 0 {
  7774. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7775. cancelStockInfo := models.CancelStockInfo{
  7776. GoodId: item.GoodId,
  7777. CancelStockId: cancel.ID,
  7778. GoodTypeId: good.GoodTypeId,
  7779. Count: delete_count,
  7780. Price: info.Price,
  7781. Total: 0,
  7782. ProductDate: info.ProductDate,
  7783. ExpiryDate: info.ExpiryDate,
  7784. Ctime: time.Now().Unix(),
  7785. Status: 1,
  7786. OrgId: adminInfo.Org.Id,
  7787. OrderNumber: cancel.OrderNumber,
  7788. Type: 0,
  7789. Dealer: deaerler.DealerName,
  7790. Manufacturer: manufacturer.ManufacturerName,
  7791. Number: info.Number,
  7792. RegisterAccount: "",
  7793. Remark: "",
  7794. WarehouseInfoId: info.WarehouseInfotId,
  7795. PatientId: info.PatientId,
  7796. RecordDate: info.SysRecordTime,
  7797. StorehouseId: houseConfig.StorehouseOutInfo,
  7798. IsCheck: 1,
  7799. }
  7800. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7801. //退库数量增加
  7802. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7803. //查询剩余库存
  7804. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7805. var over_count int64
  7806. for _, it := range goodList {
  7807. over_count += it.StockCount
  7808. }
  7809. flow := models.VmStockFlow{
  7810. WarehousingId: info.WarehouseInfotId,
  7811. GoodId: item.GoodId,
  7812. Number: info.Number,
  7813. LicenseNumber: info.LicenseNumber,
  7814. Count: delete_count,
  7815. UserOrgId: adminInfo.Org.Id,
  7816. PatientId: patient_id,
  7817. SystemTime: info.SysRecordTime,
  7818. ConsumableType: 7,
  7819. IsSys: 0,
  7820. WarehousingOrder: "",
  7821. WarehouseOutId: info.WarehouseOutId,
  7822. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7823. IsEdit: 0,
  7824. CancelStockId: cancel.ID,
  7825. CancelOrderNumber: cancel.OrderNumber,
  7826. Manufacturer: manufacturer.ID,
  7827. Dealer: 0,
  7828. Creator: adminInfo.AdminUser.Id,
  7829. UpdateCreator: 0,
  7830. Status: 1,
  7831. Ctime: record_time,
  7832. Mtime: 0,
  7833. Price: info.Price,
  7834. WarehousingDetailId: info.WarehouseInfotId,
  7835. WarehouseOutDetailId: info.ID,
  7836. CancelOutDetailId: cancelInfo.ID,
  7837. ProductDate: info.ProductDate,
  7838. ExpireDate: info.ExpiryDate,
  7839. StorehouseId: houseConfig.StorehouseOutInfo,
  7840. OverCount: over_count,
  7841. }
  7842. service.CreateStockFlowOne(flow)
  7843. }
  7844. }
  7845. //更改自动出库的表格
  7846. details := models.BloodAutomaticReduceDetail{
  7847. WarehouseOutId: warehouseOutInfo.ID,
  7848. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7849. PatientId: patient_id,
  7850. Ctime: time.Now().Unix(),
  7851. Mtime: time.Now().Unix(),
  7852. Status: 1,
  7853. RecordTime: record_time,
  7854. OrgId: adminInfo.Org.Id,
  7855. GoodId: item.GoodId,
  7856. GoodTypeId: item.GoodTypeId,
  7857. Count: item.Count,
  7858. StorehouseId: houseConfig.StorehouseOutInfo,
  7859. }
  7860. //查询当天耗材是否已经存在数据
  7861. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7862. if errcode == gorm.ErrRecordNotFound {
  7863. service.CreateAutoReduceRecord(&details)
  7864. } else if errcode == nil {
  7865. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7866. service.CreateAutoReduceRecord(&details)
  7867. }
  7868. //查询默认仓库
  7869. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7870. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7871. var total_count int64
  7872. for _, it := range stockList {
  7873. total_count += it.StockCount
  7874. }
  7875. //基础库插入数据
  7876. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7877. }
  7878. }
  7879. if len(outbefor) > 0 {
  7880. //出库
  7881. for _, item := range outbefor {
  7882. var last_total int64
  7883. //1.查看该患者该耗材型号最后一次出库数量
  7884. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7885. //计算当前出库和最后一次出库数据相差数据
  7886. last_total = item.Count - goodInfoOne.Count
  7887. //查询该耗材的总库存
  7888. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7889. // 如果库存差大于剩余库存则提示库存不足
  7890. if last_total > wareinfo.StockCount {
  7891. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7892. c.ServeSuccessJSON(map[string]interface{}{
  7893. "message": "1",
  7894. "good_name": goodObj.GoodName,
  7895. "specification_name": goodObj.SpecificationName,
  7896. })
  7897. return
  7898. } else {
  7899. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7900. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7901. if err == gorm.ErrRecordNotFound {
  7902. //没有记录,则创建出库单
  7903. timeStr := time.Now().Format("2006-01-02")
  7904. timeArr := strings.Split(timeStr, "-")
  7905. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7906. total = total + 1
  7907. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7908. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7909. number = number + total
  7910. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7911. warehouseOut := models.WarehouseOut{
  7912. WarehouseOutOrderNumber: warehousing_out_order,
  7913. OperationTime: time.Now().Unix(),
  7914. OrgId: adminInfo.Org.Id,
  7915. Creater: adminInfo.AdminUser.Id,
  7916. Ctime: time.Now().Unix(),
  7917. Status: 1,
  7918. WarehouseOutTime: record_time,
  7919. Dealer: 0,
  7920. Manufacturer: 0,
  7921. Type: 1,
  7922. IsSys: 1,
  7923. StorehouseId: houseConfig.StorehouseOutInfo,
  7924. IsCheck: 1,
  7925. }
  7926. service.AddSigleWarehouseOutOne(&warehouseOut)
  7927. }
  7928. //出库
  7929. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7930. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7931. //1.查看该患者该耗材型号最后一次出库数量
  7932. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7933. prepare := models.DialysisBeforePrepare{
  7934. UserOrgId: adminInfo.Org.Id,
  7935. PatientId: patient_id,
  7936. RecordDate: record_time,
  7937. GoodId: item.GoodId,
  7938. GoodTypeId: item.GoodTypeId,
  7939. Count: item.Count - goodInfoTwo.Count,
  7940. Ctime: time.Now().Unix(),
  7941. Mtime: 0,
  7942. Creater: adminInfo.AdminUser.Id,
  7943. Modifier: adminInfo.AdminUser.Id,
  7944. Status: 1,
  7945. CommdityCode: "",
  7946. NewCount: 0,
  7947. ProjectId: 0,
  7948. StorehouseId: houseConfig.StorehouseOutInfo,
  7949. }
  7950. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7951. //增加出库数量
  7952. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7953. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7954. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7955. var total_count int64
  7956. for _, it := range stockList {
  7957. total_count += it.StockCount
  7958. }
  7959. //基础库插入数据
  7960. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7961. //剩余库存
  7962. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7963. var flush_count int64
  7964. for _, it := range goodList {
  7965. flush_count += it.StockCount
  7966. }
  7967. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7968. }
  7969. }
  7970. }
  7971. //查询今日出库数据
  7972. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7973. for _, it := range list {
  7974. prepare := models.DialysisBeforePrepare{
  7975. UserOrgId: it.OrgId,
  7976. PatientId: patient_id,
  7977. RecordDate: it.RecordTime,
  7978. GoodId: it.GoodId,
  7979. GoodTypeId: it.GoodTypeId,
  7980. Count: it.Count,
  7981. Ctime: time.Now().Unix(),
  7982. Creater: adminInfo.AdminUser.Id,
  7983. Status: 1,
  7984. StorehouseId: houseConfig.StorehouseOutInfo,
  7985. ProjectId: it.ProjectId,
  7986. }
  7987. //删除准备表数据
  7988. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7989. service.CreateDialysisBeforePrepareOne(&prepare)
  7990. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7991. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7992. var total_count int64
  7993. for _, it := range stockList {
  7994. total_count += it.StockCount
  7995. }
  7996. //基础库插入数据
  7997. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7998. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7999. var flush_count int64
  8000. for _, it := range goodList {
  8001. flush_count += it.StockCount
  8002. }
  8003. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  8004. }
  8005. }
  8006. }
  8007. //更新自动出库的地方
  8008. var errs error
  8009. if errs == nil {
  8010. c.ServeSuccessJSON(map[string]interface{}{
  8011. "msg": "修改成功",
  8012. "message": "2",
  8013. "good_name": "",
  8014. "specification_name": "",
  8015. })
  8016. return
  8017. } else {
  8018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8019. return
  8020. }
  8021. }
  8022. }
  8023. func (c *DialysisAPIController) GetDialysisGoods() {
  8024. schedualDate := c.GetString("schedule_date")
  8025. schedule_type, _ := c.GetInt64("schedule_type")
  8026. partition_id, _ := c.GetInt64("partition_id")
  8027. page, _ := c.GetInt("page")
  8028. patient_id, _ := c.GetInt64("patient_id")
  8029. schedualEndDate := int64(0)
  8030. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  8031. if parseDateErr != nil && len(schedualDate) != 0 {
  8032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8033. return
  8034. }
  8035. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  8036. if parseDateErr != nil && len(schedualDate) != 0 {
  8037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8038. return
  8039. }
  8040. schedualEndDate = endDate.Unix()
  8041. adminUser := c.GetMobileAdminUserInfo()
  8042. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  8043. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  8044. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8045. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8046. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  8047. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  8048. //获取当天该病人的透析处方
  8049. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8050. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8051. if err == gorm.ErrRecordNotFound {
  8052. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8053. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8054. if patient_id != 0 {
  8055. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8056. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8057. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8058. //获取患者总的出库数据
  8059. item.LastAutomaticReduceDetail = goodUser
  8060. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8061. item.Project = project
  8062. for _, it := range item.AutomaticReduceDetail {
  8063. var total int64
  8064. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8065. for _, its := range auto {
  8066. total += its.Count
  8067. }
  8068. it.Count = total
  8069. }
  8070. }
  8071. }
  8072. c.ServeSuccessJSON(map[string]interface{}{
  8073. "dialysis_goods": dialysisGoods,
  8074. "good_type": goodTypes,
  8075. "total": total,
  8076. "prescribe": prescribe,
  8077. "good_info": good_info,
  8078. "warehouseOutList": warehouseOutList,
  8079. "config": config,
  8080. "outConfig": outConfig,
  8081. "settleConfig": settleConfig,
  8082. })
  8083. return
  8084. } else if err == nil {
  8085. //获取当天排班的每个患者的库存使用情况
  8086. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8087. //获取患者总的出库数据
  8088. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8089. if patient_id != 0 {
  8090. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8091. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8092. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8093. item.Project = project
  8094. item.LastAutomaticReduceDetail = goodUser
  8095. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8096. for _, it := range item.AutomaticReduceDetail {
  8097. var total int64
  8098. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8099. for _, its := range auto {
  8100. total += its.Count
  8101. }
  8102. it.Count = total
  8103. }
  8104. }
  8105. }
  8106. if err == nil {
  8107. c.ServeSuccessJSON(map[string]interface{}{
  8108. "dialysis_goods": dialysisGoods,
  8109. "good_type": goodTypes,
  8110. "total": total,
  8111. "prescribe": prescribe,
  8112. "good_info": good_info,
  8113. "project": project,
  8114. "warehouseOutList": warehouseOutList,
  8115. "config": config,
  8116. "outConfig": outConfig,
  8117. "settleConfig": settleConfig,
  8118. })
  8119. return
  8120. } else {
  8121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8122. return
  8123. }
  8124. } else if err != nil {
  8125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8126. return
  8127. }
  8128. }
  8129. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8130. start_time := c.GetString("start_time")
  8131. end_time := c.GetString("end_time")
  8132. timeLayout := "2006-01-02"
  8133. loc, _ := time.LoadLocation("Local")
  8134. var theStartTime int64
  8135. if len(start_time) > 0 {
  8136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8137. if err != nil {
  8138. utils.ErrorLog(err.Error())
  8139. }
  8140. theStartTime = theTime.Unix()
  8141. }
  8142. var theEndtTime int64
  8143. if len(end_time) > 0 {
  8144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8145. if err != nil {
  8146. utils.ErrorLog(err.Error())
  8147. }
  8148. theEndtTime = theTime.Unix()
  8149. }
  8150. adminUser := c.GetMobileAdminUserInfo()
  8151. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8152. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8153. if err == nil {
  8154. c.ServeSuccessJSON(map[string]interface{}{
  8155. "stock_out": outInfo,
  8156. "stockCount": stockCount,
  8157. })
  8158. return
  8159. } else {
  8160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8161. return
  8162. }
  8163. }
  8164. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8165. patient_id, _ := c.GetInt64("patient_id", 0)
  8166. record_time := c.GetString("record_time")
  8167. adminUser := c.GetMobileAdminUserInfo()
  8168. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8169. if parseDateErr != nil && len(record_time) != 0 {
  8170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8171. return
  8172. }
  8173. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8174. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8175. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8176. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8177. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8178. //获取今日患者的透析处方参数
  8179. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8180. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8181. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8182. c.ServeSuccessJSON(map[string]interface{}{
  8183. "good_type": goodTypes,
  8184. "good_user": goodUser,
  8185. "good_info": good_info,
  8186. "last_good_user": lastGoodUserDetial,
  8187. "project": project,
  8188. "prescription": prescribe,
  8189. "outInfo": outInfo,
  8190. "configs": configs,
  8191. })
  8192. return
  8193. }
  8194. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8195. patient_id, _ := c.GetInt64("patient_id", 0)
  8196. record_date := c.GetString("record_time")
  8197. timeLayout := "2006-01-02"
  8198. loc, _ := time.LoadLocation("Local")
  8199. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8200. record_time := theRecordTime.Unix()
  8201. adminInfo := c.GetMobileAdminUserInfo()
  8202. dataBody := make(map[string]interface{}, 0)
  8203. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8204. if err != nil {
  8205. utils.ErrorLog(err.Error())
  8206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8207. return
  8208. }
  8209. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8210. var beforePrepares []*models.DialysisBeforePrepareGoods
  8211. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8212. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8213. goods, _ := dataBody["goods"].([]interface{})
  8214. if len(goods) > 0 {
  8215. for _, item := range goods {
  8216. items := item.(map[string]interface{})
  8217. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8218. utils.ErrorLog("good_id")
  8219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8220. return
  8221. }
  8222. good_id := int64(items["good_id"].(float64))
  8223. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8224. utils.ErrorLog("good_type_id")
  8225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8226. return
  8227. }
  8228. good_type_id := int64(items["good_type_id"].(float64))
  8229. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8230. utils.ErrorLog("count")
  8231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8232. return
  8233. }
  8234. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8235. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8236. utils.ErrorLog("project_id")
  8237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8238. return
  8239. }
  8240. project_id := int64(items["project_id"].(float64))
  8241. new_count := int64(items["new_count"].(float64))
  8242. old_count := int64(items["old_count"].(float64))
  8243. prepare := &models.DialysisBeforePrepareGoods{
  8244. GoodId: good_id,
  8245. GoodTypeId: good_type_id,
  8246. Count: count,
  8247. ProjectId: project_id,
  8248. StorehouseId: houseConfig.StorehouseOutInfo,
  8249. NewCount: new_count,
  8250. OldCount: old_count,
  8251. }
  8252. beforePrepares = append(beforePrepares, prepare)
  8253. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8254. GoodId: good_id,
  8255. GoodTypeId: good_type_id,
  8256. Count: count,
  8257. ProjectId: project_id,
  8258. StorehouseId: houseConfig.StorehouseOutInfo,
  8259. NewCount: new_count,
  8260. OldCount: old_count,
  8261. }
  8262. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8263. }
  8264. }
  8265. }
  8266. //查询是否有库存
  8267. for _, item := range beforePrepares {
  8268. if item.NewCount > 0 {
  8269. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8270. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8271. if item.Count > warehouse.Count {
  8272. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8273. c.ServeSuccessJSON(map[string]interface{}{
  8274. "message": "1",
  8275. "good_name": goodObj.GoodName,
  8276. "specification_name": goodObj.SpecificationName,
  8277. })
  8278. return
  8279. }
  8280. }
  8281. }
  8282. // 查询信息规挡的设置天数
  8283. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8284. if infor.ID > 0 && infor.WeekDay > 0 {
  8285. var cha_time int64
  8286. timeNowStr := time.Now().Format("2006-01-02")
  8287. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8288. //今日的日期减去设置的日期
  8289. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8290. if cha_time >= record_time {
  8291. //查询审核是否允许
  8292. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8293. //申请状态不允许的情况 拒绝修改
  8294. if infor.ApplicationStatus != 1 {
  8295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8296. return
  8297. }
  8298. }
  8299. }
  8300. //出库逻辑
  8301. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8302. if err != nil {
  8303. utils.ErrorLog(err.Error())
  8304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8305. return
  8306. }
  8307. finish := models.XtDialysisFinish{
  8308. IsFinish: 1,
  8309. UserOrgId: adminInfo.Org.Id,
  8310. Status: 1,
  8311. Ctime: time.Now().Unix(),
  8312. Mtime: 0,
  8313. Module: 11,
  8314. RecordDate: record_time,
  8315. Sourse: 1,
  8316. PatientId: patient_id,
  8317. }
  8318. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8319. if dialysisFinish.ID == 0 {
  8320. service.CreateDialysisFinish(finish)
  8321. }
  8322. //查询当天出库的数据
  8323. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8324. for _, item := range list {
  8325. prepare := models.DialysisBeforePrepare{
  8326. UserOrgId: item.OrgId,
  8327. PatientId: item.PatientId,
  8328. RecordDate: item.RecordTime,
  8329. GoodId: item.GoodId,
  8330. GoodTypeId: item.GoodTypeId,
  8331. Count: item.Count,
  8332. Creater: adminInfo.AdminUser.Id,
  8333. Status: 1,
  8334. Ctime: time.Now().Unix(),
  8335. ProjectId: item.ProjectId,
  8336. StorehouseId: houseConfig.StorehouseOutInfo,
  8337. }
  8338. //清空准备表的数据
  8339. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8340. //插入准备表数据
  8341. service.CreateDialysisBeforePrepareOne(&prepare)
  8342. //查询默认仓库
  8343. //查询默认仓库
  8344. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8345. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8346. var total_count int64
  8347. for _, it := range stockList {
  8348. total_count += it.StockCount
  8349. }
  8350. //基础库插入数据
  8351. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8352. ////更新剩余库存
  8353. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8354. var flush_count int64
  8355. for _, it := range goodList {
  8356. flush_count += it.StockCount
  8357. }
  8358. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8359. if errs != nil {
  8360. goodErrcode := models.XtGoodErrcode{
  8361. UserOrgId: item.OrgId,
  8362. Errcode: "手动出库更新剩余出库失败",
  8363. GoodId: item.GoodId,
  8364. Status: 1,
  8365. Ctime: time.Now().Unix(),
  8366. Mtime: 0,
  8367. Count: 0,
  8368. StockCount: 0,
  8369. Creater: adminInfo.AdminUser.Id,
  8370. BatchNumberId: 0,
  8371. WarehouseOutId: 0,
  8372. }
  8373. service.CreateGoodErrcode(goodErrcode)
  8374. }
  8375. }
  8376. //更新自动出库的地方
  8377. var errs error
  8378. if errs == nil {
  8379. c.ServeSuccessJSON(map[string]interface{}{
  8380. "msg": "修改成功",
  8381. "message": "2",
  8382. "good_name": "",
  8383. "specification_name": "",
  8384. })
  8385. return
  8386. } else {
  8387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8388. return
  8389. }
  8390. }
  8391. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8392. newArr = make([]*models.DialysisBeforePrepare, 0)
  8393. for i := 0; i < len(arr); i++ {
  8394. repeat := false
  8395. for j := i + 1; j < len(arr); j++ {
  8396. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8397. repeat = true
  8398. break
  8399. }
  8400. }
  8401. if !repeat {
  8402. newArr = append(newArr, arr[i])
  8403. }
  8404. }
  8405. return
  8406. }
  8407. func (c *DialysisAPIController) GetAllDrug() {
  8408. patient_id, _ := c.GetInt64("patient_id", 0)
  8409. adminInfo := c.GetMobileAdminUserInfo()
  8410. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8411. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8412. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8413. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8414. c.ServeSuccessJSON(map[string]interface{}{
  8415. "base_drug_config": drugStockConfig,
  8416. "private_drug_config": privateDrugConfig,
  8417. "base_drug_list": drugList,
  8418. "private_drug_list": privateDrugList,
  8419. })
  8420. }
  8421. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8422. newArr = make([]*models.DialysisBeforePrepare, 0)
  8423. for i := 0; i < len(arr); i++ {
  8424. repeat := false
  8425. for j := i + 1; j < len(arr); j++ {
  8426. if arr[i].GoodId == arr[j].GoodId {
  8427. repeat = true
  8428. break
  8429. }
  8430. }
  8431. if !repeat {
  8432. newArr = append(newArr, arr[i])
  8433. }
  8434. }
  8435. return
  8436. }
  8437. func (c *DialysisAPIController) GetDepartment() {
  8438. adminInfo := c.GetMobileAdminUserInfo()
  8439. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8440. if err == nil {
  8441. c.ServeSuccessJSON(map[string]interface{}{
  8442. "departments": departments,
  8443. })
  8444. } else {
  8445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8446. return
  8447. }
  8448. }
  8449. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8450. types, _ := c.GetInt("type", 0)
  8451. start_time := c.GetString("start_time")
  8452. end_time := c.GetString("end_time")
  8453. orgId := c.GetMobileAdminUserInfo().Org.Id
  8454. timeLayout := "2006-01-02"
  8455. loc, _ := time.LoadLocation("Local")
  8456. var startTime int64
  8457. if len(start_time) > 0 {
  8458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8459. if err != nil {
  8460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8461. return
  8462. }
  8463. startTime = theTime.Unix()
  8464. }
  8465. var endTime int64
  8466. if len(end_time) > 0 {
  8467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8468. if err != nil {
  8469. utils.ErrorLog(err.Error())
  8470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8471. return
  8472. }
  8473. endTime = theTime.Unix()
  8474. }
  8475. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8476. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8477. if err != nil {
  8478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8479. } else {
  8480. c.ServeSuccessJSON(map[string]interface{}{
  8481. "list": list,
  8482. "type": types,
  8483. "stockTotal": stockTotal,
  8484. })
  8485. }
  8486. }
  8487. func (c *DialysisAPIController) GetPrescriptionList() {
  8488. start_time := c.GetString("start_time")
  8489. end_time := c.GetString("end_time")
  8490. schedule_type, _ := c.GetInt64("schedule_type")
  8491. partion_id, _ := c.GetInt64("partion_id")
  8492. orgId := c.GetMobileAdminUserInfo().Org.Id
  8493. timeLayout := "2006-01-02"
  8494. loc, _ := time.LoadLocation("Local")
  8495. var startTime int64
  8496. if len(start_time) > 0 {
  8497. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8498. if err != nil {
  8499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8500. return
  8501. }
  8502. startTime = theTime.Unix()
  8503. }
  8504. var endTime int64
  8505. if len(end_time) > 0 {
  8506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8507. if err != nil {
  8508. utils.ErrorLog(err.Error())
  8509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8510. return
  8511. }
  8512. endTime = theTime.Unix()
  8513. }
  8514. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8515. fmt.Println("schedulelist22222222", schedulelist)
  8516. c.ServeSuccessJSON(map[string]interface{}{
  8517. "list": schedulelist,
  8518. })
  8519. return
  8520. }
  8521. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8522. ids := c.GetString("ids")
  8523. //patient_id, _ := c.GetInt64("patient_id")
  8524. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8525. idArray := strings.Split(ids, ",")
  8526. err := service.BatchDeleteMonitor(idArray)
  8527. fmt.Print("err", err)
  8528. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8529. //redis := service.RedisClient()
  8530. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8531. //redis.Set(key, "", time.Second)
  8532. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8533. //redis.Set(keyOne, "", time.Second)
  8534. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8535. //redis.Close()
  8536. c.ServeSuccessJSON(map[string]interface{}{
  8537. "msg": "批量删除成功",
  8538. })
  8539. return
  8540. }
  8541. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8542. id, _ := c.GetInt64("id")
  8543. timeLayout := "2006-01-02"
  8544. loc, _ := time.LoadLocation("Local")
  8545. //start_time := time.Now().Format("2006-01-02")
  8546. start_time := c.GetString("start_time")
  8547. end_time := c.GetString("end_time")
  8548. var startdateunix int64
  8549. if len(start_time) > 0 {
  8550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8551. if err != nil {
  8552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8553. return
  8554. }
  8555. startdateunix = theTime.Unix()
  8556. }
  8557. var enddateunix int64
  8558. if len(end_time) > 0 {
  8559. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8560. if err != nil {
  8561. utils.ErrorLog(err.Error())
  8562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8563. return
  8564. }
  8565. enddateunix = theTime.Unix()
  8566. }
  8567. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8568. //nowTime := time.Now()
  8569. //endTime := nowTime.AddDate(-30, 0, 0)
  8570. //endTimes := endTime.Format("2006-01-02")
  8571. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8572. org_id := c.GetMobileAdminUserInfo().Org.Id
  8573. //if org_id == 10579 {
  8574. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8575. // c.ServeSuccessJSON(map[string]interface{}{
  8576. // "list": list,
  8577. // })
  8578. // return
  8579. //} else {
  8580. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8581. // c.ServeSuccessJSON(map[string]interface{}{
  8582. // "list": list,
  8583. // })
  8584. // return
  8585. //}
  8586. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8587. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8588. c.ServeSuccessJSON(map[string]interface{}{
  8589. "list": list,
  8590. })
  8591. return
  8592. } else {
  8593. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8594. c.ServeSuccessJSON(map[string]interface{}{
  8595. "list": list,
  8596. })
  8597. }
  8598. return
  8599. }
  8600. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8601. dataBody := make(map[string]interface{}, 0)
  8602. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8603. ids := c.GetString("ids")
  8604. idArray := strings.Split(ids, ",")
  8605. origin, _ := c.GetInt64("origin")
  8606. if origin == 1 {
  8607. err = service.BatchDeleteAdvice(idArray)
  8608. fmt.Print("err", err)
  8609. c.ServeSuccessJSON(map[string]interface{}{
  8610. "msg": "批量删除成功",
  8611. })
  8612. return
  8613. }
  8614. if origin == 2 {
  8615. service.BatchDeleteHisAdvice(idArray)
  8616. }
  8617. }
  8618. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8619. good_id, _ := c.GetInt64("good_id")
  8620. count, _ := c.GetInt64("count")
  8621. record_time, _ := c.GetInt64("record_time")
  8622. patient_id, _ := c.GetInt64("patient_id")
  8623. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8624. c.ServeSuccessJSON(map[string]interface{}{
  8625. "detail": detail,
  8626. })
  8627. return
  8628. }
  8629. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8630. good_id, _ := c.GetInt64("good_id")
  8631. record_time, _ := c.GetInt64("record_time")
  8632. patient_id, _ := c.GetInt64("patient_id")
  8633. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8634. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8635. fmt.Print("err", err)
  8636. c.ServeSuccessJSON(map[string]interface{}{
  8637. "msg": "批量删除成功",
  8638. })
  8639. return
  8640. }
  8641. func (c *DialysisAPIController) BatchAdviceCheck() {
  8642. ids := c.GetString("ids")
  8643. idArray := strings.Split(ids, ",")
  8644. creator, _ := c.GetInt64("creator")
  8645. origin, _ := c.GetInt64("origin")
  8646. if origin == 1 {
  8647. err := service.BatchAdviceCheck(idArray, creator)
  8648. fmt.Println(err)
  8649. list, _ := service.GetAdviceExecutionById(idArray)
  8650. c.ServeSuccessJSON(map[string]interface{}{
  8651. "list": list,
  8652. })
  8653. return
  8654. }
  8655. if origin == 2 {
  8656. service.BatchHisAdviceCheck(idArray, creator)
  8657. list, _ := service.GetHisAdviceExecutionById(idArray)
  8658. c.ServeSuccessJSON(map[string]interface{}{
  8659. "list": list,
  8660. })
  8661. return
  8662. }
  8663. }
  8664. func (c *DialysisAPIController) BatchAdviceExecution() {
  8665. ids := c.GetString("ids")
  8666. idArray := strings.Split(ids, ",")
  8667. executionTime := c.GetString("execution_time")
  8668. creator, _ := c.GetInt64("creator")
  8669. timeLayout := "2006-01-02 15:04:05"
  8670. loc, _ := time.LoadLocation("Local")
  8671. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8672. orgin, _ := c.GetInt64("origin")
  8673. if orgin == 1 {
  8674. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8675. list, _ := service.GetAdviceExecutionById(idArray)
  8676. fmt.Println(err)
  8677. c.ServeSuccessJSON(map[string]interface{}{
  8678. "list": list,
  8679. })
  8680. return
  8681. }
  8682. if orgin == 2 {
  8683. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8684. list, _ := service.GetHisAdviceExecutionById(idArray)
  8685. fmt.Println(err)
  8686. c.ServeSuccessJSON(map[string]interface{}{
  8687. "list": list,
  8688. })
  8689. return
  8690. }
  8691. }
  8692. func (c *DialysisAPIController) UpdateStockGoods() {
  8693. good_id, _ := c.GetInt64("good_id")
  8694. record_time, _ := c.GetInt64("record_time")
  8695. patient_id, _ := c.GetInt64("patient_id")
  8696. count, _ := c.GetInt64("count")
  8697. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8698. fmt.Print("err", err)
  8699. c.ServeSuccessJSON(map[string]interface{}{
  8700. "msg": "更新成功",
  8701. })
  8702. return
  8703. }
  8704. // 当前数据比上一次出库数据少
  8705. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8706. //查询该患者当天已经出库的耗材信息
  8707. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8708. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8709. for i := len(goods_yc) - 1; i >= 0; i-- {
  8710. goods_yc_temp := goods_yc[i]
  8711. for j := len(goods) - 1; j >= 0; j-- {
  8712. goods_temp := goods[j]
  8713. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8714. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8715. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8716. if goods_yc_temp.Count == goods_temp.Count {
  8717. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8718. goods = append(goods[:j], goods[j+1:]...)
  8719. break
  8720. }
  8721. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8722. if goods_yc_temp.Count > goods_temp.Count {
  8723. temp_count := goods_yc_temp.Count - goods_temp.Count
  8724. goods_yc[i].Count = temp_count
  8725. goods = append(goods[:j], goods[j+1:]...)
  8726. break
  8727. }
  8728. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8729. if goods_yc_temp.Count < goods_temp.Count {
  8730. temp_count := goods_temp.Count - goods_yc_temp.Count
  8731. goods[j].Count = temp_count
  8732. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8733. break
  8734. }
  8735. }
  8736. }
  8737. }
  8738. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8739. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8740. //退库
  8741. if len(goods_yc) > 0 {
  8742. for _, good_yc := range goods_yc {
  8743. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8744. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8745. }
  8746. }
  8747. return nil
  8748. }
  8749. // 耗材出库删除
  8750. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8751. // 先根据相关信息查询当天该耗材的出库信息
  8752. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8753. if err != nil {
  8754. return err
  8755. }
  8756. var delete_count int64 = 0
  8757. delete_count = warehouseOutInfos.Count - count
  8758. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8759. // 在出库记录表里记录退库详情
  8760. warehouseOutInfo := &models.WarehouseOutInfo{
  8761. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8762. WarehouseOutId: warehouseOut.ID,
  8763. Status: 1,
  8764. Ctime: time.Now().Unix(),
  8765. OrgId: orgID,
  8766. Type: 1,
  8767. IsSys: 1,
  8768. SysRecordTime: record_time,
  8769. GoodTypeId: good_yc.GoodTypeId,
  8770. GoodId: good_yc.GoodId,
  8771. PatientId: good_yc.PatientId,
  8772. ConsumableType: 2,
  8773. StorehouseId: houseConfig.StorehouseOutInfo,
  8774. IsCheck: 1,
  8775. }
  8776. warehouseOutInfo.Count = count
  8777. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8778. warehouseOutInfo.Price = stockInInfo.Price
  8779. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8780. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8781. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8782. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8783. warehouseOutInfo.Number = warehouseOutInfos.Number
  8784. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8785. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8786. //查找当天是否存在出库记录
  8787. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8788. if errcod == gorm.ErrRecordNotFound {
  8789. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8790. //插入详情明细表
  8791. stockFlow := models.VmStockFlow{
  8792. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8793. WarehouseOutId: warehouseOut.ID,
  8794. GoodId: good_yc.GoodId,
  8795. Number: warehouseOutInfos.Number,
  8796. ProductDate: stockInInfo.ProductDate,
  8797. ExpireDate: stockInInfo.ExpiryDate,
  8798. Count: count,
  8799. Price: stockInInfo.Price,
  8800. Status: 1,
  8801. Ctime: time.Now().Unix(),
  8802. UserOrgId: good_yc.OrgId,
  8803. Manufacturer: stockInInfo.Manufacturer,
  8804. Dealer: stockInInfo.Dealer,
  8805. LicenseNumber: stockInInfo.LicenseNumber,
  8806. IsEdit: 2,
  8807. Creator: creater,
  8808. SystemTime: record_time,
  8809. ConsumableType: 3,
  8810. WarehousingDetailId: 0,
  8811. IsSys: 1,
  8812. UpdateCreator: creater,
  8813. PatientId: patient_id,
  8814. StorehouseId: houseConfig.StorehouseOutInfo,
  8815. }
  8816. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8817. if errflow == gorm.ErrRecordNotFound {
  8818. //创建流水表
  8819. err := service.CreateStockFlowOne(stockFlow)
  8820. fmt.Println("err", err)
  8821. } else if errflow == nil {
  8822. //插入详情明细表
  8823. stockFlow := models.VmStockFlow{
  8824. ID: exsit.ID,
  8825. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8826. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8827. WarehouseOutId: warehouseOut.ID,
  8828. GoodId: good_yc.GoodId,
  8829. Number: warehouseOutInfos.Number,
  8830. ProductDate: stockInInfo.ProductDate,
  8831. ExpireDate: stockInInfo.ExpiryDate,
  8832. Count: exsit.Count - delete_count,
  8833. Price: stockInInfo.Price,
  8834. Status: 1,
  8835. Ctime: time.Now().Unix(),
  8836. UserOrgId: good_yc.OrgId,
  8837. Manufacturer: stockInInfo.Manufacturer,
  8838. Dealer: stockInInfo.Dealer,
  8839. LicenseNumber: stockInInfo.LicenseNumber,
  8840. IsEdit: 2,
  8841. Creator: creater,
  8842. SystemTime: record_time,
  8843. ConsumableType: 3,
  8844. WarehousingDetailId: 0,
  8845. IsSys: 1,
  8846. UpdateCreator: creater,
  8847. PatientId: patient_id,
  8848. StorehouseId: houseConfig.StorehouseOutInfo,
  8849. }
  8850. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8851. }
  8852. if errOne != nil {
  8853. return errOne
  8854. }
  8855. } else if errcod == nil {
  8856. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8857. //插入详情明细表
  8858. stockFlow := models.VmStockFlow{
  8859. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8860. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8861. WarehouseOutId: warehouseOut.ID,
  8862. GoodId: good_yc.GoodId,
  8863. Number: warehouseOutInfos.Number,
  8864. ProductDate: stockInInfo.ProductDate,
  8865. ExpireDate: stockInInfo.ExpiryDate,
  8866. Count: count,
  8867. Price: stockInInfo.Price,
  8868. Status: 1,
  8869. Ctime: time.Now().Unix(),
  8870. UserOrgId: good_yc.OrgId,
  8871. Manufacturer: stockInInfo.Manufacturer,
  8872. Dealer: stockInInfo.Dealer,
  8873. LicenseNumber: stockInInfo.LicenseNumber,
  8874. IsEdit: 2,
  8875. Creator: creater,
  8876. SystemTime: record_time,
  8877. ConsumableType: 3,
  8878. WarehousingDetailId: 0,
  8879. IsSys: 1,
  8880. UpdateCreator: creater,
  8881. PatientId: patient_id,
  8882. ReturnCount: delete_count,
  8883. StorehouseId: houseConfig.StorehouseOutInfo,
  8884. }
  8885. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8886. if errflows == gorm.ErrRecordNotFound {
  8887. //创建流水表
  8888. service.CreateStockFlowOne(stockFlow)
  8889. } else if errflows == nil {
  8890. stockFlow := models.VmStockFlow{
  8891. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8892. ID: exsit.ID,
  8893. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8894. WarehouseOutId: warehouseOut.ID,
  8895. GoodId: good_yc.GoodId,
  8896. Number: warehouseOutInfos.Number,
  8897. ProductDate: stockInInfo.ProductDate,
  8898. ExpireDate: stockInInfo.ExpiryDate,
  8899. Count: exsit.Count - delete_count,
  8900. Price: stockInInfo.Price,
  8901. Status: 1,
  8902. Ctime: time.Now().Unix(),
  8903. UserOrgId: good_yc.OrgId,
  8904. Manufacturer: stockInInfo.Manufacturer,
  8905. Dealer: stockInInfo.Dealer,
  8906. LicenseNumber: stockInInfo.LicenseNumber,
  8907. IsEdit: 2,
  8908. Creator: creater,
  8909. SystemTime: record_time,
  8910. ConsumableType: 3,
  8911. WarehousingDetailId: 0,
  8912. IsSys: 1,
  8913. UpdateCreator: creater,
  8914. PatientId: patient_id,
  8915. ReturnCount: delete_count,
  8916. StorehouseId: houseConfig.StorehouseOutInfo,
  8917. }
  8918. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8919. }
  8920. }
  8921. //更改自动出库的表格
  8922. details := models.BloodAutomaticReduceDetail{
  8923. WarehouseOutId: warehouseOutInfo.ID,
  8924. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8925. PatientId: patient_id,
  8926. Ctime: time.Now().Unix(),
  8927. Mtime: time.Now().Unix(),
  8928. Status: 1,
  8929. RecordTime: record_time,
  8930. OrgId: orgID,
  8931. GoodId: good_yc.GoodId,
  8932. GoodTypeId: good_yc.GoodTypeId,
  8933. Count: count,
  8934. StorehouseId: houseConfig.StorehouseOutInfo,
  8935. }
  8936. //查询当天耗材是否已经存在数据
  8937. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8938. if errcode == gorm.ErrRecordNotFound {
  8939. errTwo := service.CreateAutoReduceRecord(&details)
  8940. if errTwo != nil {
  8941. return errTwo
  8942. }
  8943. } else if errcode == nil {
  8944. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8945. service.CreateAutoReduceRecord(&details)
  8946. }
  8947. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8948. //增加出库库存数量
  8949. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8950. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8951. fmt.Println("errOne", errOne)
  8952. // 删除出库完成后,要增加对应批次的库存数量
  8953. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8954. if errThree != nil {
  8955. return errThree
  8956. }
  8957. if good_yc.Count == 0 {
  8958. return nil
  8959. } else {
  8960. return errors.New("退库和出库数据不匹配")
  8961. }
  8962. }
  8963. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8964. //查询该患者当天已经出库的耗材信息
  8965. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8966. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8967. for i := len(goods_yc) - 1; i >= 0; i-- {
  8968. goods_yc_temp := goods_yc[i]
  8969. for j := len(goods) - 1; j >= 0; j-- {
  8970. goods_temp := goods[j]
  8971. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8972. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8973. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8974. if goods_yc_temp.Count == goods_temp.Count {
  8975. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8976. goods = append(goods[:j], goods[j+1:]...)
  8977. break
  8978. }
  8979. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8980. if goods_yc_temp.Count > goods_temp.Count {
  8981. temp_count := goods_yc_temp.Count - goods_temp.Count
  8982. goods_yc[i].Count = temp_count
  8983. goods = append(goods[:j], goods[j+1:]...)
  8984. break
  8985. }
  8986. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8987. if goods_yc_temp.Count < goods_temp.Count {
  8988. temp_count := goods_temp.Count - goods_yc_temp.Count
  8989. goods[j].Count = temp_count
  8990. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8991. break
  8992. }
  8993. }
  8994. }
  8995. }
  8996. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8997. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8998. fmt.Println("剩余需要出库的", len(goods))
  8999. if len(goods) > 0 {
  9000. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  9001. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9002. if err == gorm.ErrRecordNotFound {
  9003. //没有记录,则创建出库单
  9004. timeStr := time.Now().Format("2006-01-02")
  9005. timeArr := strings.Split(timeStr, "-")
  9006. total, _ := service.FindAllWarehouseOut(orgID)
  9007. total = total + 1
  9008. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9009. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9010. number = number + total
  9011. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9012. warehouseOut := models.WarehouseOut{
  9013. WarehouseOutOrderNumber: warehousing_out_order,
  9014. OperationTime: time.Now().Unix(),
  9015. OrgId: orgID,
  9016. Creater: creater,
  9017. Ctime: time.Now().Unix(),
  9018. Status: 1,
  9019. WarehouseOutTime: record_time,
  9020. Dealer: 0,
  9021. Manufacturer: 0,
  9022. Type: 1,
  9023. IsSys: 1,
  9024. StorehouseId: houseConfig.StorehouseOutInfo,
  9025. IsCheck: 1,
  9026. }
  9027. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  9028. if err != nil {
  9029. utils.TraceLog("创建出库单失败 err = %v", err)
  9030. return err
  9031. } else {
  9032. out = warehouseOut
  9033. }
  9034. }
  9035. for _, item := range goods {
  9036. var newCount int64 = 0
  9037. for _, it := range goodOne {
  9038. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  9039. newCount = it.Count
  9040. }
  9041. }
  9042. prepare := models.DialysisBeforePrepare{
  9043. GoodTypeId: item.GoodTypeId,
  9044. GoodId: item.GoodId,
  9045. Count: item.Count,
  9046. StorehouseId: houseConfig.StorehouseOutInfo,
  9047. }
  9048. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  9049. //增加出库数量
  9050. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  9051. }
  9052. }
  9053. if len(goods_yc) > 0 {
  9054. for _, good_yc := range goods_yc {
  9055. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  9056. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  9057. }
  9058. }
  9059. return nil
  9060. }
  9061. // 耗材出库删除
  9062. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  9063. // 先根据相关信息查询当天该耗材的出库信息
  9064. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  9065. if err != nil {
  9066. return err
  9067. }
  9068. var delete_count int64 = 0
  9069. for _, ware := range warehouseOutInfos {
  9070. // 判断当前出库的数据和删除出库数量
  9071. if good_yc.Count <= ware.Count {
  9072. delete_count = good_yc.Count
  9073. } else {
  9074. delete_count = ware.Count
  9075. }
  9076. warehouseOutInfo := &models.WarehouseOutInfo{
  9077. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9078. WarehouseOutId: warehouseOut.ID,
  9079. Status: 1,
  9080. Ctime: time.Now().Unix(),
  9081. Remark: "",
  9082. OrgId: orgID,
  9083. Type: 1,
  9084. Manufacturer: 0,
  9085. Dealer: 0,
  9086. IsSys: 0,
  9087. SysRecordTime: record_time,
  9088. GoodTypeId: good_yc.GoodTypeId,
  9089. GoodId: good_yc.GoodId,
  9090. StorehouseId: warehouseOut.StorehouseId,
  9091. IsCheck: 1,
  9092. }
  9093. warehouseOutInfo.Count = delete_count
  9094. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9095. warehouseOutInfo.Price = stockInInfo.Price
  9096. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9097. if errOne != nil {
  9098. return errOne
  9099. }
  9100. // 删除出库完成后,要改变流水库存(有疑问)
  9101. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9102. fmt.Println("errOne", errOne)
  9103. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  9104. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9105. //扣减出库数量
  9106. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  9107. if errThree != nil {
  9108. return errThree
  9109. }
  9110. }
  9111. if good_yc.Count == 0 {
  9112. return nil
  9113. } else {
  9114. return errors.New("退库和出库数据不匹配")
  9115. }
  9116. }
  9117. func (this *DialysisAPIController) GetMobileScheduleList() {
  9118. limit, _ := this.GetInt64("limit")
  9119. page, _ := this.GetInt64("page")
  9120. type_options_visible, _ := this.GetInt64("type_options_visible")
  9121. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9122. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9123. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9124. }
  9125. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9126. newArr = make([]*models.HisPrescriptionProject, 0)
  9127. for i := 0; i < len(arr); i++ {
  9128. repeat := false
  9129. for j := i + 1; j < len(arr); j++ {
  9130. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9131. repeat = true
  9132. break
  9133. }
  9134. }
  9135. if !repeat {
  9136. newArr = append(newArr, arr[i])
  9137. }
  9138. }
  9139. return
  9140. }
  9141. func (this *DialysisAPIController) GetRoleList() {
  9142. admin_user_id, _ := this.GetInt64("admin_user_id")
  9143. orgid := this.GetMobileAdminUserInfo().Org.Id
  9144. list, err := service.GetRoleList(orgid, admin_user_id)
  9145. fmt.Println(err)
  9146. this.ServeSuccessJSON(map[string]interface{}{
  9147. "list": list,
  9148. })
  9149. return
  9150. }
  9151. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9152. // 先根据相关信息查询当天该耗材的出库信息
  9153. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9154. if err != nil {
  9155. return err
  9156. }
  9157. var delete_count int64 = 0
  9158. delete_count = warehouseOutInfos.Count - count
  9159. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9160. // 删除出库完成后,要增加对应批次的库存数量
  9161. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9162. if errThree != nil {
  9163. return errThree
  9164. }
  9165. //增加退库数量
  9166. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9167. //扣减出库数量
  9168. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9169. //查询剩余库存
  9170. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9171. var sum_count int64
  9172. for _, item := range goodList {
  9173. sum_count += item.StockCount
  9174. }
  9175. // 在出库记录表里记录退库详情
  9176. warehouseOutInfo := &models.WarehouseOutInfo{
  9177. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9178. WarehouseOutId: warehouseOut.ID,
  9179. Status: 1,
  9180. Ctime: time.Now().Unix(),
  9181. OrgId: orgID,
  9182. Type: 1,
  9183. IsSys: 1,
  9184. SysRecordTime: record_time,
  9185. GoodTypeId: good_yc.GoodTypeId,
  9186. GoodId: good_yc.GoodId,
  9187. PatientId: good_yc.PatientId,
  9188. ConsumableType: 2,
  9189. StorehouseId: houseConfig.StorehouseOutInfo,
  9190. IsCheck: 1,
  9191. OverCount: sum_count,
  9192. }
  9193. warehouseOutInfo.Count = count
  9194. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9195. warehouseOutInfo.Price = stockInInfo.Price
  9196. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9197. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9198. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9199. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9200. warehouseOutInfo.Number = warehouseOutInfos.Number
  9201. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9202. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9203. //查找当天是否存在出库记录
  9204. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9205. if errcod == gorm.ErrRecordNotFound {
  9206. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9207. //插入详情明细表
  9208. if errOne != nil {
  9209. return errOne
  9210. }
  9211. //插入详情明细表
  9212. stockFlow := models.VmStockFlow{
  9213. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9214. WarehouseOutId: warehouseOut.ID,
  9215. GoodId: good_yc.GoodId,
  9216. Number: warehouseOutInfos.Number,
  9217. ProductDate: stockInInfo.ProductDate,
  9218. ExpireDate: stockInInfo.ExpiryDate,
  9219. Count: count,
  9220. Price: stockInInfo.Price,
  9221. Status: 1,
  9222. Ctime: record_time,
  9223. UserOrgId: good_yc.OrgId,
  9224. Manufacturer: stockInInfo.Manufacturer,
  9225. Dealer: stockInInfo.Dealer,
  9226. LicenseNumber: stockInInfo.LicenseNumber,
  9227. IsEdit: 2,
  9228. Creator: creater,
  9229. SystemTime: record_time,
  9230. ConsumableType: 3,
  9231. WarehousingDetailId: 0,
  9232. IsSys: 1,
  9233. UpdateCreator: creater,
  9234. PatientId: patient_id,
  9235. StorehouseId: houseConfig.StorehouseOutInfo,
  9236. OverCount: sum_count,
  9237. ProjectId: good_yc.ProjectId,
  9238. }
  9239. err := service.CreateStockFlowOne(stockFlow)
  9240. fmt.Println("err", err)
  9241. } else if errcod == nil {
  9242. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9243. }
  9244. //创建退库单
  9245. operation_time := time.Now().Unix()
  9246. //创建退库单
  9247. timeStr := time.Now().Format("2006-01-02")
  9248. timeArr := strings.Split(timeStr, "-")
  9249. total, _ := service.FindAllCancelStockTotal(orgID)
  9250. total = total + 1
  9251. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9252. cancelStock := models.CancelStock{
  9253. OrderNumber: orderNumber,
  9254. OperaTime: operation_time,
  9255. OrgId: orgID,
  9256. Creater: warehouseOut.Creater,
  9257. Ctime: time.Now().Unix(),
  9258. Status: 1,
  9259. ReturnTime: record_time,
  9260. Type: 1,
  9261. StorehouseId: stockInInfo.StorehouseId,
  9262. IsCheck: 1,
  9263. }
  9264. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9265. if msgerrkonde == gorm.ErrRecordNotFound {
  9266. service.AddSigleCancelStock(&cancelStock)
  9267. }
  9268. cancel, _ := service.GetLastCancelStockById(orgID)
  9269. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9270. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9271. cancelStockInfo := models.CancelStockInfo{
  9272. GoodId: stockInInfo.GoodId,
  9273. CancelStockId: cancel.ID,
  9274. GoodTypeId: stockInInfo.GoodTypeId,
  9275. Count: delete_count,
  9276. Price: stockInInfo.PackingPrice,
  9277. Total: 0,
  9278. ProductDate: stockInInfo.ProductDate,
  9279. ExpiryDate: stockInInfo.ExpiryDate,
  9280. Ctime: record_time,
  9281. Status: 1,
  9282. OrgId: orgID,
  9283. OrderNumber: cancel.OrderNumber,
  9284. Type: 0,
  9285. Dealer: deaerler.DealerName,
  9286. Manufacturer: manufacturer.ManufacturerName,
  9287. Number: stockInInfo.Number,
  9288. RegisterAccount: "",
  9289. Remark: "",
  9290. WarehouseInfoId: stockInInfo.ID,
  9291. PatientId: patient_id,
  9292. RecordDate: record_time,
  9293. StorehouseId: stockInInfo.StorehouseId,
  9294. IsCheck: 1,
  9295. }
  9296. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9297. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9298. flow := models.VmStockFlow{
  9299. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9300. GoodId: good_yc.GoodId,
  9301. Number: warehouseOutInfos.Number,
  9302. LicenseNumber: stockInInfo.LicenseNumber,
  9303. Count: delete_count,
  9304. UserOrgId: orgID,
  9305. PatientId: patient_id,
  9306. SystemTime: record_time,
  9307. ConsumableType: 7,
  9308. IsSys: 0,
  9309. WarehousingOrder: "",
  9310. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9311. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9312. IsEdit: 0,
  9313. CancelStockId: cancel.ID,
  9314. CancelOrderNumber: cancel.OrderNumber,
  9315. Manufacturer: manufacturer.ID,
  9316. Dealer: 0,
  9317. Creator: warehouseOut.Creater,
  9318. UpdateCreator: 0,
  9319. Status: 1,
  9320. Ctime: record_time,
  9321. Mtime: 0,
  9322. Price: stockInInfo.Price,
  9323. WarehousingDetailId: stockInInfo.ID,
  9324. WarehouseOutDetailId: warehouseOutInfos.ID,
  9325. CancelOutDetailId: cancelInfo.ID,
  9326. ProductDate: stockInInfo.ProductDate,
  9327. ExpireDate: stockInInfo.ExpiryDate,
  9328. StorehouseId: houseConfig.StorehouseOutInfo,
  9329. OverCount: sum_count,
  9330. }
  9331. service.CreateStockFlowOne(flow)
  9332. //更改自动出库的表格
  9333. details := models.BloodAutomaticReduceDetail{
  9334. WarehouseOutId: warehouseOutInfo.ID,
  9335. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9336. PatientId: patient_id,
  9337. Ctime: time.Now().Unix(),
  9338. Mtime: time.Now().Unix(),
  9339. Status: 1,
  9340. RecordTime: record_time,
  9341. OrgId: orgID,
  9342. GoodId: good_yc.GoodId,
  9343. GoodTypeId: good_yc.GoodTypeId,
  9344. Count: count,
  9345. StorehouseId: houseConfig.StorehouseOutInfo,
  9346. }
  9347. //查询当天耗材是否已经存在数据
  9348. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9349. if errcode == gorm.ErrRecordNotFound {
  9350. errTwo := service.CreateAutoReduceRecord(&details)
  9351. if errTwo != nil {
  9352. return errTwo
  9353. }
  9354. } else if errcode == nil {
  9355. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9356. service.CreateAutoReduceRecord(&details)
  9357. }
  9358. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9359. //增加出库库存数量
  9360. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9361. if good_yc.Count == 0 {
  9362. return nil
  9363. } else {
  9364. return errors.New("退库和出库数据不匹配")
  9365. }
  9366. }
  9367. func (this *DialysisAPIController) SavePatientSign() {
  9368. adminUserInfo := this.GetMobileAdminUserInfo()
  9369. patient_id, _ := this.GetInt64("patient_id")
  9370. dialysis_date, _ := this.GetInt64("dialysis_date")
  9371. orgid := adminUserInfo.Org.Id
  9372. var esdata models.DialysisOrder
  9373. var err error
  9374. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9376. return
  9377. }
  9378. esdata.Hash = esdata.Hash
  9379. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9380. order := models.DialysisOrder{
  9381. Hash: esdata.Hash,
  9382. Url: esdata.Url,
  9383. }
  9384. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9385. redis := service.RedisClient()
  9386. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9387. redis.Set(key, "", time.Second)
  9388. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9389. //清空key 值
  9390. redis.Set(keyOne, "", time.Second)
  9391. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9392. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9393. //redis.Set(keyTwo, "", time.Second)
  9394. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9395. redis.Set(keyThree, "", time.Second)
  9396. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9397. redis.Set(keyFour, "", time.Second)
  9398. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9399. redis.Set(keyFive, "", time.Second)
  9400. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9401. redis.Set(keySix, "", time.Second)
  9402. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9403. redis.Set(keySeven, "", time.Second)
  9404. if err != nil {
  9405. fmt.Println(err)
  9406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9407. return
  9408. }
  9409. this.ServeSuccessJSON(map[string]interface{}{
  9410. "electronic_signature": esdata,
  9411. })
  9412. }
  9413. func (this *DialysisAPIController) GetPatientSign() {
  9414. patient_id, _ := this.GetInt64("patient_id")
  9415. dialysis_date, _ := this.GetInt64("dialysis_date")
  9416. adminUserInfo := this.GetMobileAdminUserInfo()
  9417. orgId := adminUserInfo.Org.Id
  9418. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9419. if err != nil {
  9420. fmt.Println(err)
  9421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9422. return
  9423. }
  9424. this.ServeSuccessJSON(map[string]interface{}{
  9425. "dialysisOrder": dialysisOrder,
  9426. })
  9427. }
  9428. func (this *DialysisAPIController) GetScheduleByPatient() {
  9429. patient_id, _ := this.GetInt64("patient_id")
  9430. schedule_date, _ := this.GetInt64("schedule_date")
  9431. orgid := this.GetMobileAdminUserInfo().Org.Id
  9432. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9433. this.ServeSuccessJSON(map[string]interface{}{
  9434. "schedule": schedule,
  9435. })
  9436. }
  9437. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9438. org_id := this.GetMobileAdminUserInfo().Org.Id
  9439. patient_id, _ := this.GetInt64("patient_id")
  9440. schedule_date, _ := this.GetInt64("schedule_date")
  9441. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9442. this.ServeSuccessJSON(map[string]interface{}{
  9443. "order": order,
  9444. })
  9445. }
  9446. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9447. org_id := this.GetMobileAdminUserInfo().Org.Id
  9448. schedule_date := this.GetString("schedule_date")
  9449. schedule_type, _ := this.GetInt64("schedule_type")
  9450. timeLayout := "2006-01-02"
  9451. loc, _ := time.LoadLocation("Local")
  9452. var startdateunix int64
  9453. if len(schedule_date) > 0 {
  9454. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9455. if err != nil {
  9456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9457. return
  9458. }
  9459. startdateunix = theTime.Unix()
  9460. }
  9461. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9462. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9463. devices, _ := service.GetAllDevicetByListSix(org_id)
  9464. for key, item := range scheduals {
  9465. // 床位信息
  9466. for _, device := range devices {
  9467. if item.BedId == device.ID {
  9468. scheduals[key].DeviceNumber = device
  9469. break
  9470. }
  9471. }
  9472. }
  9473. this.ServeSuccessJSON(map[string]interface{}{
  9474. "list": list,
  9475. "scheduals": scheduals,
  9476. })
  9477. }
  9478. func (this *DialysisAPIController) SavePatientPicture() {
  9479. patient_id, _ := this.GetInt64("patient_id")
  9480. dialysis_date, _ := this.GetInt64("schedule_date")
  9481. avatar := this.GetString("avatar")
  9482. fmt.Println("patient_id", patient_id)
  9483. orgId := this.GetMobileAdminUserInfo().Org.Id
  9484. order := models.DialysisOrder{
  9485. Url: avatar,
  9486. }
  9487. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9488. redis := service.RedisClient()
  9489. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9490. redis.Set(key, "", time.Second)
  9491. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9492. //清空key 值
  9493. redis.Set(keyOne, "", time.Second)
  9494. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9495. redis.Set(keyThree, "", time.Second)
  9496. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9497. redis.Set(keyFour, "", time.Second)
  9498. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9499. redis.Set(keyFive, "", time.Second)
  9500. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9501. redis.Set(keySix, "", time.Second)
  9502. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9503. redis.Set(keySeven, "", time.Second)
  9504. if err != nil {
  9505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9506. return
  9507. }
  9508. this.ServeSuccessJSON(map[string]interface{}{
  9509. "order": order,
  9510. })
  9511. }
  9512. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9513. ids := this.GetString("ids")
  9514. idSplit := strings.Split(ids, ",")
  9515. orgId := this.GetMobileAdminUserInfo().Org.Id
  9516. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9517. execution_time := this.GetString("exce_time")
  9518. timeLayout2 := "2006-01-02 15:04:05"
  9519. loc, _ := time.LoadLocation("Local")
  9520. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9521. if errs != nil {
  9522. utils.ErrorLog(errs.Error())
  9523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9524. return
  9525. }
  9526. //his客户
  9527. if config.IsOpen == 1 {
  9528. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9529. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9530. for _, item := range list {
  9531. for _, it := range adviceList {
  9532. if item.DrugId == it.DrugId {
  9533. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9534. }
  9535. }
  9536. }
  9537. for _, item := range list {
  9538. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9539. var sum_out_count int64
  9540. for _, itemThree := range item.ChildDoctorAdvice {
  9541. var prescribing_number int64
  9542. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9543. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9544. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9545. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9546. }
  9547. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9548. prescribing_number = parseIntPrescribingNumber
  9549. }
  9550. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9551. prescribing_number = parseIntPrescribingNumber
  9552. }
  9553. sum_out_count += prescribing_number
  9554. }
  9555. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9556. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9557. //库存不足
  9558. if sum_out_count > drugStockOut.FlushCount {
  9559. this.ServeSuccessJSON(map[string]interface{}{
  9560. "msg": "2",
  9561. "drug": medical,
  9562. "ids": ids,
  9563. })
  9564. return
  9565. }
  9566. }
  9567. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9568. //执行医嘱
  9569. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9570. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9571. for _, item := range advices {
  9572. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9573. redis := service.RedisClient()
  9574. //清空key 值
  9575. redis.Set(key, "", time.Second)
  9576. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9577. redis.Set(keyTwo, "", time.Second)
  9578. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9579. redis.Set(keyThree, "", time.Second)
  9580. recordDate := theTime.Format("2006-01-02")
  9581. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9582. redis.Set(keyFour, "", time.Second)
  9583. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9584. redis.Set(keyFive, "", time.Second)
  9585. defer redis.Close()
  9586. }
  9587. if errs == nil {
  9588. //药品管理信息
  9589. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9590. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9591. if drugStockConfig.IsOpen == 1 {
  9592. for _, item := range advices {
  9593. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9594. config, _ := service.GetDrugOpenConfigOne(orgId)
  9595. if config.IsOpen != 1 {
  9596. //查询该药品是否有库存
  9597. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9598. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9599. if medical.IsUse == 2 {
  9600. if config.IsOpen != 1 {
  9601. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9602. service.HisDrugsDelivery(orgId, creater, &advice)
  9603. if orgId == 3877 || orgId == 10265 {
  9604. //查询该药品是否有出库记录
  9605. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9606. if len(flowMap) == 0 {
  9607. errs := service.UpdateHisAdviceById(advice.ID)
  9608. if errs != nil {
  9609. drugError := models.XtDrugError{
  9610. UserOrgId: orgId,
  9611. DrugId: item.DrugId,
  9612. RecordDate: item.AdviceDate,
  9613. PatientId: item.PatientId,
  9614. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9615. Status: 1,
  9616. Ctime: time.Now().Unix(),
  9617. Mtime: 0,
  9618. SumCount: 0,
  9619. Prescribingnumber: advice.PrescribingNumber,
  9620. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9621. }
  9622. service.CreateDrugError(drugError)
  9623. }
  9624. this.ServeSuccessJSON(map[string]interface{}{
  9625. "msg": "2",
  9626. "drug": medical,
  9627. "ids": ids,
  9628. })
  9629. return
  9630. }
  9631. }
  9632. }
  9633. if pharmacyConfig.IsOpen != 1 {
  9634. service.HisDrugsDelivery(orgId, creater, &advice)
  9635. if orgId == 3877 || orgId == 10265 {
  9636. //查询该药品是否有出库记录
  9637. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9638. if len(flowMap) == 0 {
  9639. errs := service.UpdateHisAdviceById(advice.ID)
  9640. if errs != nil {
  9641. drugError := models.XtDrugError{
  9642. UserOrgId: orgId,
  9643. DrugId: item.DrugId,
  9644. RecordDate: item.AdviceDate,
  9645. PatientId: item.PatientId,
  9646. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9647. Status: 1,
  9648. Ctime: time.Now().Unix(),
  9649. Mtime: 0,
  9650. SumCount: 0,
  9651. Prescribingnumber: advice.PrescribingNumber,
  9652. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9653. }
  9654. service.CreateDrugError(drugError)
  9655. }
  9656. this.ServeSuccessJSON(map[string]interface{}{
  9657. "msg": "2",
  9658. "drug": medical,
  9659. "ids": ids,
  9660. })
  9661. return
  9662. }
  9663. }
  9664. }
  9665. //更新字典里面的库存
  9666. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9667. var sum_count int64
  9668. for _, its := range stockInfo {
  9669. if its.MaxUnit == medical.MaxUnit {
  9670. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9671. }
  9672. sum_count += its.StockMaxNumber + its.StockMinNumber
  9673. }
  9674. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9675. //剩余库存
  9676. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9677. }
  9678. }
  9679. }
  9680. }
  9681. }
  9682. this.ServeSuccessJSON(map[string]interface{}{
  9683. "msg": "1",
  9684. "ids": ids,
  9685. })
  9686. return
  9687. } else {
  9688. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9689. }
  9690. }
  9691. //血透客户
  9692. if config.IsOpen == 2 || config.IsOpen == 0 {
  9693. //药品管理信息
  9694. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9695. if drugStockConfig.IsOpen == 1 {
  9696. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9697. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9698. for _, item := range list {
  9699. for _, it := range adviceList {
  9700. if item.DrugId == it.DrugId {
  9701. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9702. }
  9703. }
  9704. }
  9705. for _, item := range list {
  9706. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9707. var sum_out_count int64
  9708. for _, itemThree := range item.ChildDoctorAdvice {
  9709. var prescribing_number int64
  9710. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9711. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9712. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9713. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9714. }
  9715. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9716. prescribing_number = parseIntPrescribingNumber
  9717. }
  9718. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9719. prescribing_number = parseIntPrescribingNumber
  9720. }
  9721. sum_out_count += prescribing_number
  9722. }
  9723. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9724. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9725. //库存不足
  9726. if sum_out_count > drugStockOut.FlushCount {
  9727. this.ServeSuccessJSON(map[string]interface{}{
  9728. "msg": "2",
  9729. "drug": medical,
  9730. "ids": ids,
  9731. })
  9732. return
  9733. }
  9734. }
  9735. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9736. //执行医嘱
  9737. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9738. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9739. for _, item := range advices {
  9740. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9741. redis := service.RedisClient()
  9742. //清空key 值
  9743. redis.Set(key, "", time.Second)
  9744. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9745. redis.Set(keyTwo, "", time.Second)
  9746. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9747. redis.Set(keyThree, "", time.Second)
  9748. recordDate := theTime.Format("2006-01-02")
  9749. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9750. redis.Set(keyFour, "", time.Second)
  9751. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9752. redis.Set(keyFive, "", time.Second)
  9753. defer redis.Close()
  9754. }
  9755. if errs == nil {
  9756. for _, item := range advices {
  9757. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9758. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9759. //查询是否出库按钮开启
  9760. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9761. if adviceSetting.IsAdviceOpen == 1 {
  9762. //查询是否出库按钮开启
  9763. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9764. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9765. if prescriptionConfig.IsOpen == 1 {
  9766. if medical.IsUse == 2 {
  9767. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9768. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9769. }
  9770. if pharmacyConfig.IsOpen != 1 {
  9771. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9772. }
  9773. //更新字典里面的库存
  9774. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9775. var sum_count int64
  9776. for _, its := range stockInfo {
  9777. if its.MaxUnit == medical.MaxUnit {
  9778. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9779. }
  9780. sum_count += its.StockMaxNumber + its.StockMinNumber
  9781. }
  9782. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9783. //剩余库存
  9784. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9785. }
  9786. }
  9787. } else {
  9788. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9789. if medical.IsUse == 2 {
  9790. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9791. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9792. }
  9793. if pharmacyConfig.IsOpen != 1 {
  9794. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9795. }
  9796. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9797. var sum_count int64
  9798. for _, its := range stockInfo {
  9799. if its.MaxUnit == medical.MaxUnit {
  9800. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9801. }
  9802. sum_count += its.StockMaxNumber + its.StockMinNumber
  9803. }
  9804. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9805. //剩余库存
  9806. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9807. }
  9808. }
  9809. }
  9810. }
  9811. this.ServeSuccessJSON(map[string]interface{}{
  9812. "msg": "1",
  9813. "ids": ids,
  9814. })
  9815. return
  9816. } else {
  9817. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9818. //执行医嘱
  9819. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9820. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9821. for _, item := range advices {
  9822. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9823. redis := service.RedisClient()
  9824. //清空key 值
  9825. redis.Set(key, "", time.Second)
  9826. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9827. redis.Set(keyTwo, "", time.Second)
  9828. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9829. redis.Set(keyThree, "", time.Second)
  9830. recordDate := theTime.Format("2006-01-02")
  9831. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9832. redis.Set(keyFour, "", time.Second)
  9833. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9834. redis.Set(keyFive, "", time.Second)
  9835. defer redis.Close()
  9836. }
  9837. this.ServeSuccessJSON(map[string]interface{}{
  9838. "msg": "1",
  9839. "ids": ids,
  9840. })
  9841. return
  9842. }
  9843. }
  9844. }
  9845. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9846. ids := this.GetString("ids")
  9847. idSplit := strings.Split(ids, ",")
  9848. orgId := this.GetMobileAdminUserInfo().Org.Id
  9849. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9850. if config.IsOpen == 1 {
  9851. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9852. this.ServeSuccessJSON(map[string]interface{}{
  9853. "msg": "1",
  9854. "ids": ids,
  9855. })
  9856. return
  9857. }
  9858. if config.IsOpen == 0 || config.IsOpen == 2 {
  9859. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9860. this.ServeSuccessJSON(map[string]interface{}{
  9861. "msg": "1",
  9862. "ids": ids,
  9863. })
  9864. return
  9865. }
  9866. }
  9867. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9868. ids := this.GetString("ids")
  9869. idSplit := strings.Split(ids, ",")
  9870. orgId := this.GetMobileAdminUserInfo().Org.Id
  9871. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9872. //his
  9873. if config.IsOpen == 1 {
  9874. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9875. theTime := time.Now()
  9876. advices := models.HisDoctorAdviceThirty{
  9877. CheckTime: theTime.Unix(),
  9878. Checker: checker,
  9879. UpdatedTime: time.Now().Unix(),
  9880. }
  9881. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9882. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9883. for _, item := range list {
  9884. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9885. redis := service.RedisClient()
  9886. //清空key 值
  9887. redis.Set(key, "", time.Second)
  9888. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9889. redis.Set(keyTwo, "", time.Second)
  9890. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9891. redis.Set(keyThree, "", time.Second)
  9892. recordDate := theTime.Format("2006-01-02")
  9893. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9894. redis.Set(keyFour, "", time.Second)
  9895. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9896. redis.Set(keyFive, "", time.Second)
  9897. defer redis.Close()
  9898. }
  9899. this.ServeSuccessJSON(map[string]interface{}{
  9900. "msg": "1",
  9901. "ids": ids,
  9902. })
  9903. return
  9904. }
  9905. //血透
  9906. if config.IsOpen == 0 || config.IsOpen == 2 {
  9907. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9908. theTime := time.Now()
  9909. advices := models.DoctorAdvice{
  9910. CheckTime: theTime.Unix(),
  9911. Checker: checker,
  9912. UpdatedTime: time.Now().Unix(),
  9913. }
  9914. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9915. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9916. for _, item := range list {
  9917. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9918. redis := service.RedisClient()
  9919. //清空key 值
  9920. redis.Set(key, "", time.Second)
  9921. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9922. redis.Set(keyTwo, "", time.Second)
  9923. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9924. redis.Set(keyThree, "", time.Second)
  9925. recordDate := theTime.Format("2006-01-02")
  9926. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9927. redis.Set(keyFour, "", time.Second)
  9928. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9929. redis.Set(keyFive, "", time.Second)
  9930. defer redis.Close()
  9931. }
  9932. this.ServeSuccessJSON(map[string]interface{}{
  9933. "msg": "1",
  9934. "ids": ids,
  9935. })
  9936. return
  9937. }
  9938. }
  9939. func (this *DialysisAPIController) CheckSchedule() {
  9940. patientID, _ := this.GetInt64("patient_id")
  9941. recordDateStr := this.GetString("record_date")
  9942. nurseID, _ := this.GetInt64("start_nurse")
  9943. schedual_type, _ := this.GetInt64("schedual_type")
  9944. bedID, _ := this.GetInt64("bed")
  9945. start_time := this.GetString("start_time")
  9946. fmt.Println("patientID", patientID)
  9947. fmt.Println("recordDateStr", recordDateStr)
  9948. fmt.Println("nurseID", nurseID)
  9949. fmt.Println("schedual_type------", schedual_type)
  9950. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9952. return
  9953. }
  9954. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9955. if parseStartDateErr != nil {
  9956. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9958. return
  9959. }
  9960. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9961. if parseErr != nil {
  9962. this.ErrorLog("时间解析失败:%v", parseErr)
  9963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9964. return
  9965. }
  9966. adminUserInfo := this.GetMobileAdminUserInfo()
  9967. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9968. if getPatientErr != nil {
  9969. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9971. return
  9972. } else if patient == nil {
  9973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9974. return
  9975. }
  9976. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9977. if getNurseErr != nil {
  9978. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9980. return
  9981. } else if nurse == nil {
  9982. this.ErrorLog("护士不存在")
  9983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9984. return
  9985. }
  9986. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9987. if getDeviceNumberErr != nil {
  9988. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9990. return
  9991. } else if deviceNumber == nil {
  9992. this.ErrorLog("床位号不存在")
  9993. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9994. return
  9995. }
  9996. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9997. if getRecordErr != nil {
  9998. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10000. return
  10001. } else if dialysisRecord != nil {
  10002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  10003. return
  10004. }
  10005. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  10006. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  10007. timeLayout := "2006-01-02 15:04:05"
  10008. loc, _ := time.LoadLocation("Local")
  10009. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  10010. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  10011. schedulestartTime := theStartTime.Unix()
  10012. scheduleendTime := theEndTime.Unix()
  10013. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  10014. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  10015. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10016. //查询该床位是否有人用了
  10017. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10018. if err == nil {
  10019. if schedule.ID == 0 {
  10020. this.ServeSuccessJSON(map[string]interface{}{
  10021. "status": 0,
  10022. "msg": "请求失败",
  10023. })
  10024. } else {
  10025. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  10026. if order.ID > 0 { //该机位被其他人占用了
  10027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  10028. return
  10029. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  10030. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  10031. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  10032. this.ServeSuccessJSON(map[string]interface{}{
  10033. "status": 1,
  10034. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  10035. })
  10036. return
  10037. } else {
  10038. this.ServeSuccessJSON(map[string]interface{}{
  10039. "status": 0,
  10040. "msg": "",
  10041. })
  10042. }
  10043. }
  10044. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  10045. this.ServeSuccessJSON(map[string]interface{}{
  10046. "status": 2,
  10047. "msg": "当前机位已有患者在使用,请重新选择!",
  10048. })
  10049. }
  10050. }
  10051. } else {
  10052. this.ServeSuccessJSON(map[string]interface{}{
  10053. "status": 0,
  10054. "msg": "",
  10055. })
  10056. }
  10057. }
  10058. func (this *DialysisAPIController) GetNewDoctorListToday() {
  10059. orgId := this.GetMobileAdminUserInfo().Org.Id
  10060. schedule_type, _ := this.GetInt64("schedule_type")
  10061. partion_type, _ := this.GetInt64("partion_type")
  10062. start_time := this.GetString("start_time")
  10063. timeLayout := "2006-01-02"
  10064. loc, _ := time.LoadLocation("Local")
  10065. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10066. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  10067. _, config := service.FindXTHisRecordByOrgId(orgId)
  10068. appId := this.GetMobileAdminUserInfo().App.Id
  10069. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  10070. if err == nil {
  10071. this.ServeSuccessJSON(map[string]interface{}{
  10072. "list": list,
  10073. "config": config,
  10074. "doctorList": doctorList,
  10075. })
  10076. return
  10077. } else {
  10078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10079. return
  10080. }
  10081. }
  10082. func (this *DialysisAPIController) SaveMobileInformation() {
  10083. patient_id, _ := this.GetInt64("patient_id")
  10084. record_date, _ := this.GetInt64("record_date")
  10085. startTime := this.GetString("start_time")
  10086. module, _ := this.GetInt64("module")
  10087. remark := this.GetString("remark")
  10088. timeLayout := "2006-01-02 15:04"
  10089. loc, _ := time.LoadLocation("Local")
  10090. if len(startTime) == 0 {
  10091. utils.ErrorLog("len(start_time) == 0")
  10092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10093. return
  10094. }
  10095. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  10096. if err != nil {
  10097. utils.ErrorLog(err.Error())
  10098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10099. return
  10100. }
  10101. StartTime := theTime.Unix()
  10102. fmt.Println("startime-------------", StartTime)
  10103. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  10104. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  10105. information := models.XtDialysisInformation{
  10106. Module: module,
  10107. PatientId: patient_id,
  10108. RecordDate: record_date,
  10109. ApplicationDate: StartTime,
  10110. Creater: creater,
  10111. ApplicationStatus: 2,
  10112. Checker: 0,
  10113. CheckTime: 0,
  10114. Remark: remark,
  10115. UserOrgId: user_org_id,
  10116. Ctime: time.Now().Unix(),
  10117. Status: 1,
  10118. Mtime: 0,
  10119. }
  10120. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10121. if infor.ID == 0 {
  10122. service.SaveDialysisInformation(information)
  10123. }
  10124. if infor.ID > 0 {
  10125. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10126. }
  10127. this.ServeSuccessJSON(map[string]interface{}{
  10128. "information": information,
  10129. })
  10130. return
  10131. }
  10132. func (this *DialysisAPIController) GetMobileInformation() {
  10133. limit, _ := this.GetInt64("limit")
  10134. page, _ := this.GetInt64("page")
  10135. orgid := this.GetMobileAdminUserInfo().Org.Id
  10136. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10137. appid := this.GetMobileAdminUserInfo().App.Id
  10138. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10139. patients, _ := service.GetAllpatientThirty(orgid)
  10140. this.ServeSuccessJSON(map[string]interface{}{
  10141. "information": information,
  10142. "total": total,
  10143. "doclist": doclist,
  10144. "patients": patients,
  10145. })
  10146. return
  10147. }
  10148. func (this *DialysisAPIController) GetMobileInformationOne() {
  10149. limit, _ := this.GetInt64("limit")
  10150. page, _ := this.GetInt64("page")
  10151. orgid := this.GetMobileAdminUserInfo().Org.Id
  10152. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10153. appid := this.GetMobileAdminUserInfo().App.Id
  10154. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10155. patients, _ := service.GetAllpatientThirty(orgid)
  10156. this.ServeSuccessJSON(map[string]interface{}{
  10157. "information": information,
  10158. "total": total,
  10159. "doclist": doclist,
  10160. "patients": patients,
  10161. })
  10162. return
  10163. }
  10164. func (this *DialysisAPIController) CheckMobileInformation() {
  10165. id, _ := this.GetInt64("id")
  10166. application_status, _ := this.GetInt64("application_status")
  10167. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10168. checktime := time.Now().Unix()
  10169. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10170. if err == nil {
  10171. this.ServeSuccessJSON(map[string]interface{}{
  10172. "msg": "ok",
  10173. })
  10174. return
  10175. }
  10176. }
  10177. func (c *DialysisAPIController) GetControlMonitorList() {
  10178. partition, _ := c.GetInt64("partition")
  10179. monitorDate := c.GetString("date")
  10180. patient_id, _ := c.GetInt64("patient_id")
  10181. pat_type, _ := c.GetInt64("pat_type")
  10182. timeLayout := "2006-01-02"
  10183. loc, _ := time.LoadLocation("Local")
  10184. var theStartTime int64
  10185. if len(monitorDate) > 0 {
  10186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10187. if err != nil {
  10188. theStartTime = 0
  10189. }
  10190. theStartTime = theTime.Unix()
  10191. }
  10192. adminInfo := c.GetMobileAdminUserInfo()
  10193. orgID := adminInfo.Org.Id
  10194. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10195. if err != nil {
  10196. c.ErrorLog("获取排班信息失败:%v", err)
  10197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10198. } else {
  10199. if len(monitor) > 0 {
  10200. //获取所有床位
  10201. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10202. //获取所有分区
  10203. zoneList, _ := service.GetAllZoneByList(orgID)
  10204. //获取透析处方
  10205. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10206. //获取透前评估
  10207. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10208. //获取上机
  10209. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10210. //获取透后
  10211. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10212. //获取透后监测
  10213. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10214. //获取所有的患者
  10215. patients, _ := service.GetAllPatientListByListOne(orgID)
  10216. //获取所有透析模式
  10217. treatments, _ := service.GetAllTreatModeByList(orgID)
  10218. //获取所有医嘱
  10219. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10220. //获取双人核对
  10221. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10222. //治疗小结
  10223. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10224. //待消毒
  10225. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10226. for key, item := range monitor {
  10227. // 获取床位信息
  10228. for _, it := range numberList {
  10229. if item.BedId == it.ID {
  10230. monitor[key].DeviceNumber = it
  10231. break
  10232. }
  10233. }
  10234. //获取分区信息
  10235. for _, it := range zoneList {
  10236. if item.PartitionId == it.ID {
  10237. monitor[key].DeviceZone = it
  10238. }
  10239. }
  10240. for _, prescription := range prescriptions {
  10241. if item.PatientId == prescription.PatientId {
  10242. monitor[key].Prescription = prescription
  10243. break
  10244. }
  10245. }
  10246. for _, it := range checkList {
  10247. if item.PatientId == it.PatientId {
  10248. monitor[key].DoubleCheck = it
  10249. break
  10250. }
  10251. }
  10252. for _, it := range summaryList {
  10253. if item.PatientId == it.PatientId {
  10254. monitor[key].TreatmentSummaryForList = it
  10255. break
  10256. }
  10257. }
  10258. // 透前评估
  10259. for _, assessmentBefore := range assessmentBefores {
  10260. if item.PatientId == assessmentBefore.PatientId {
  10261. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10262. break
  10263. }
  10264. }
  10265. // 透析上下机
  10266. for _, dialysisOrder := range dialysisOrders {
  10267. if item.PatientId == dialysisOrder.PatientId {
  10268. monitor[key].DialysisOrder = dialysisOrder
  10269. break
  10270. }
  10271. }
  10272. // 治疗小节
  10273. for _, afterDislysis := range AssessmentAfterDislysis {
  10274. if item.PatientId == afterDislysis.PatientId {
  10275. monitor[key].AssessmentAfterDislysis = afterDislysis
  10276. break
  10277. }
  10278. }
  10279. for _, it := range monitorlist {
  10280. if item.PatientId == it.PatientId {
  10281. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10282. }
  10283. }
  10284. for _, it := range adviceList {
  10285. if item.PatientId == it.PatientId {
  10286. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10287. }
  10288. }
  10289. for _, patient := range patients {
  10290. if item.PatientId == patient.ID {
  10291. monitor[key].MonitorPatients = patient
  10292. break
  10293. }
  10294. }
  10295. for _, treatment := range treatments {
  10296. if item.ModeId == treatment.ID {
  10297. monitor[key].TreatmentMode = treatment
  10298. break
  10299. }
  10300. }
  10301. for _, infor := range informationList {
  10302. if item.PatientId == infor.PatientId {
  10303. monitor[key].NewDeviceInformation = infor
  10304. break
  10305. }
  10306. }
  10307. }
  10308. }
  10309. }
  10310. patients, err := service.GetAllpatientFourty(orgID)
  10311. var mds []*models.NewMonitorDialysisScheduleList
  10312. if pat_type == 0 {
  10313. for _, item := range monitor {
  10314. mds = append(mds, item)
  10315. }
  10316. }
  10317. //待医嘱核对
  10318. if pat_type == 1 {
  10319. for _, item := range monitor {
  10320. if len(item.AdviceList) > 0 {
  10321. mds = append(mds, item)
  10322. }
  10323. }
  10324. }
  10325. //待开小结
  10326. if pat_type == 2 {
  10327. for _, item := range monitor {
  10328. if item.TreatmentSummaryForList == nil {
  10329. mds = append(mds, item)
  10330. }
  10331. }
  10332. }
  10333. //待下机
  10334. if pat_type == 3 {
  10335. for _, item := range monitor {
  10336. if item.DialysisOrder != nil {
  10337. if item.DialysisOrder.ID > 0 {
  10338. mds = append(mds, item)
  10339. }
  10340. }
  10341. }
  10342. }
  10343. //待消毒
  10344. if pat_type == 4 {
  10345. for _, item := range monitor {
  10346. if item.NewDeviceInformation == nil {
  10347. mds = append(mds, item)
  10348. }
  10349. }
  10350. }
  10351. //待双人核对
  10352. if pat_type == 5 {
  10353. for _, item := range monitor {
  10354. if item.DoubleCheck == nil {
  10355. mds = append(mds, item)
  10356. }
  10357. }
  10358. }
  10359. //医嘱未执行
  10360. if pat_type == 6 {
  10361. for _, item := range monitor {
  10362. if len(item.AdviceList) > 0 {
  10363. mds = append(mds, item)
  10364. }
  10365. }
  10366. }
  10367. //患者未签名
  10368. if pat_type == 7 {
  10369. for _, item := range monitor {
  10370. if item.DialysisOrder != nil {
  10371. if item.DialysisOrder.ID > 0 {
  10372. mds = append(mds, item)
  10373. }
  10374. }
  10375. }
  10376. }
  10377. //目标超滤于实际超滤不同
  10378. if pat_type == 8 {
  10379. for _, item := range monitor {
  10380. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10381. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10382. mds = append(mds, item)
  10383. }
  10384. }
  10385. }
  10386. }
  10387. //血压少于5次
  10388. if pat_type == 9 {
  10389. for _, item := range monitor {
  10390. if len(item.MonitoringRecord) < 5 {
  10391. mds = append(mds, item)
  10392. }
  10393. }
  10394. }
  10395. if pat_type == 13 {
  10396. for _, item := range monitor {
  10397. if len(item.MonitoringRecord) < 3 {
  10398. mds = append(mds, item)
  10399. }
  10400. }
  10401. }
  10402. if pat_type == 10 {
  10403. for _, item := range monitor {
  10404. if len(item.MonitoringRecord) == 0 {
  10405. mds = append(mds, item)
  10406. }
  10407. }
  10408. }
  10409. if pat_type == 11 {
  10410. for _, item := range monitor {
  10411. if len(item.MonitoringRecord) > 0 {
  10412. mds = append(mds, item)
  10413. }
  10414. }
  10415. }
  10416. if pat_type == 12 {
  10417. for _, item := range monitor {
  10418. if len(item.MonitoringRecord) > 0 {
  10419. mds = append(mds, item)
  10420. }
  10421. }
  10422. }
  10423. if err == nil {
  10424. c.ServeSuccessJSON(map[string]interface{}{
  10425. "monitor": mds,
  10426. "patients": patients,
  10427. })
  10428. } else {
  10429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10430. }
  10431. }
  10432. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10433. admin_user_id, _ := c.GetInt64("admin_user_id")
  10434. timeStr := time.Now().Format("2006-01-02")
  10435. timeLayout := "2006-01-02 15:04:05"
  10436. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10437. timenow := timeStringToTime.Unix()
  10438. orgId := c.GetMobileAdminUserInfo().Org.Id
  10439. //查询当前护士的患者
  10440. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10441. var patientIds []int64
  10442. for _, item := range orderList {
  10443. patientIds = append(patientIds, item.PatientId)
  10444. }
  10445. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10446. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10447. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10448. //药品管理信息
  10449. _, drugStockConfig := service.FindHisConfig(orgId)
  10450. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10451. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10452. c.ServeSuccessJSON(map[string]interface{}{
  10453. "adviceList": adviceList,
  10454. "hisAdviceList": hisAdviceList,
  10455. "projectList": projectList,
  10456. "drugStockConfig": drugStockConfig,
  10457. "patientList": patientList,
  10458. "projectConfig": projectConfig,
  10459. })
  10460. }
  10461. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10462. patient_id, _ := c.GetInt64("patient_id")
  10463. org_id := c.GetMobileAdminUserInfo().Org.Id
  10464. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10465. c.ServeSuccessJSON(map[string]interface{}{
  10466. "recrods": recrods,
  10467. })
  10468. }
  10469. func (c *DialysisAPIController) ExMobileChangeSch() {
  10470. id_one, _ := c.GetInt64("id_one")
  10471. id_two, _ := c.GetInt64("id_two")
  10472. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10473. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10474. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10475. //if order2.ID > 0 {
  10476. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10477. // return
  10478. //}
  10479. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10480. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10481. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10482. if count > 0 {
  10483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10484. return
  10485. }
  10486. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10487. if count1 > 0 {
  10488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10489. return
  10490. }
  10491. }
  10492. err := service.UpdateScheduleThree(sch, sch_two)
  10493. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10494. if order.ID > 0 {
  10495. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10496. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10497. redis := service.RedisClient()
  10498. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10499. redis.Set(key, "", time.Second)
  10500. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10501. //清空key 值
  10502. redis.Set(keyOne, "", time.Second)
  10503. }
  10504. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10505. if orderOne.ID > 0 {
  10506. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10507. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10508. redis := service.RedisClient()
  10509. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10510. redis.Set(key, "", time.Second)
  10511. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10512. //清空key 值
  10513. redis.Set(keyOne, "", time.Second)
  10514. }
  10515. if err == nil {
  10516. //去除当天患者排班中重复数据,保留最后一条数据
  10517. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10518. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10519. c.ServeSuccessJSON(map[string]interface{}{
  10520. "msg": "交换成功",
  10521. })
  10522. } else {
  10523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10524. return
  10525. }
  10526. }
  10527. func (c *DialysisAPIController) MobileCoverSch() {
  10528. id_one, _ := c.GetInt64("id_one")
  10529. id_two, _ := c.GetInt64("id_two")
  10530. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10531. //针对凤凰医院
  10532. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10533. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10534. if len(advice) > 0 {
  10535. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10536. }
  10537. }
  10538. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10539. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10540. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10541. if len(hisAdvice) > 0 {
  10542. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10543. }
  10544. if len(project) > 0 {
  10545. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10546. }
  10547. }
  10548. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10549. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10550. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10551. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10552. if count > 0 {
  10553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10554. return
  10555. }
  10556. }
  10557. var new_sch models.Schedule
  10558. new_sch = sch
  10559. new_sch.BedId = sch_two.BedId
  10560. new_sch.ScheduleDate = sch_two.ScheduleDate
  10561. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10562. new_sch.PartitionId = sch_two.PartitionId
  10563. new_sch.ScheduleType = sch_two.ScheduleType
  10564. new_sch.ID = 0
  10565. //删除原来的排班
  10566. err := service.SaveSchTwo(sch, sch_two)
  10567. //生成新的排班
  10568. if err == nil {
  10569. err2 := service.SaveSch(&new_sch)
  10570. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10571. if order.ID > 0 {
  10572. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10573. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10574. redis := service.RedisClient()
  10575. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10576. redis.Set(key, "", time.Second)
  10577. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10578. //清空key 值
  10579. redis.Set(keyOne, "", time.Second)
  10580. }
  10581. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10582. if orderOne.ID > 0 {
  10583. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10584. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10585. redis := service.RedisClient()
  10586. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10587. redis.Set(key, "", time.Second)
  10588. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10589. //清空key 值
  10590. redis.Set(keyOne, "", time.Second)
  10591. }
  10592. if err2 == nil {
  10593. //去除当天患者排班中重复数据,保留最后一条数据
  10594. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10595. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10596. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10597. c.ServeSuccessJSON(map[string]interface{}{
  10598. "msg": "覆盖成功",
  10599. "new_sch": new_sch,
  10600. })
  10601. } else {
  10602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10603. return
  10604. }
  10605. } else {
  10606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10607. return
  10608. }
  10609. }
  10610. func (c *DialysisAPIController) BatchCheckAdvice() {
  10611. patient_id, _ := c.GetInt64("patient_id")
  10612. advice_date, _ := c.GetInt64("advice_date")
  10613. org_id := c.GetMobileAdminUserInfo().Org.Id
  10614. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10615. //查询是his系统还是血透系统
  10616. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10617. //his客户
  10618. if configs.IsOpen == 1 {
  10619. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10620. for _, item := range adviceList {
  10621. service.BatchCheckHisAdvice(item.ID, creater)
  10622. }
  10623. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10624. for _, item := range projectList {
  10625. service.BatchCheckProject(item.ID, creater)
  10626. }
  10627. c.ServeSuccessJSON(map[string]interface{}{
  10628. "adviceList": adviceList,
  10629. "projectList": projectList,
  10630. })
  10631. }
  10632. if configs.IsOpen != 1 {
  10633. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10634. for _, item := range adviceList {
  10635. service.BatchAdviceList(item.ID, creater)
  10636. }
  10637. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10638. for _, item := range projectList {
  10639. service.BatchCheckProject(item.ID, creater)
  10640. }
  10641. c.ServeSuccessJSON(map[string]interface{}{
  10642. "adviceList": adviceList,
  10643. "projectList": projectList,
  10644. })
  10645. }
  10646. return
  10647. }
  10648. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10649. org_id := c.GetMobileAdminUserInfo().Org.Id
  10650. drugList, _ := service.GetAllDrugList(org_id)
  10651. c.ServeSuccessJSON(map[string]interface{}{
  10652. "drugList": drugList,
  10653. })
  10654. }
  10655. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10656. org_id := c.GetMobileAdminUserInfo().Org.Id
  10657. dataBody := make(map[string]interface{}, 0)
  10658. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10659. if err != nil {
  10660. utils.ErrorLog(err.Error())
  10661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10662. return
  10663. }
  10664. timeLayout := "2006-01-02"
  10665. loc, _ := time.LoadLocation("Local")
  10666. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10667. utils.ErrorLog("advice_type")
  10668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10669. return
  10670. }
  10671. adviceType := int64(dataBody["advice_type"].(float64))
  10672. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10673. utils.ErrorLog("start_time")
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. startTime2, _ := dataBody["start_time"].(string)
  10678. time_arr := strings.Split(startTime2, " ")
  10679. if len(time_arr) > 0 {
  10680. startTime2 = time_arr[0]
  10681. }
  10682. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10683. utils.ErrorLog("advice_date")
  10684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10685. return
  10686. }
  10687. advice_date, _ := dataBody["advice_date"].(string)
  10688. var advicedateunix int64
  10689. if len(advice_date) > 0 {
  10690. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10691. if err != nil {
  10692. fmt.Println(err)
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10694. return
  10695. }
  10696. advicedateunix = theTime.Unix()
  10697. }
  10698. adviceDate := startTime2
  10699. if len(adviceDate) == 0 {
  10700. utils.ErrorLog("len(adviceDate) == 0")
  10701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10702. return
  10703. }
  10704. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10705. if err != nil {
  10706. utils.ErrorLog(err.Error())
  10707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10708. return
  10709. }
  10710. AdviceDate := advicedateunix
  10711. RecordDate := advicedateunix
  10712. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10713. utils.ErrorLog("start_time")
  10714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10715. return
  10716. }
  10717. startTime, _ := dataBody["start_time"].(string)
  10718. if len(startTime) == 0 {
  10719. utils.ErrorLog("len(start_time) == 0")
  10720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10721. return
  10722. }
  10723. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10724. if err != nil {
  10725. utils.ErrorLog(err.Error())
  10726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10727. return
  10728. }
  10729. StartTime := theTime.Unix()
  10730. advice_name, _ := dataBody["advice_name"].(string)
  10731. advice_desc, _ := dataBody["advice_desc"].(string)
  10732. delivery_way, _ := dataBody["delivery_way"].(string)
  10733. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10734. frequency_type := int64(dataBody["frequency_type"].(float64))
  10735. frequency_week, _ := dataBody["frequency_week"].(string)
  10736. prescribing_number := dataBody["prescribing_number"].(float64)
  10737. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10738. remark := dataBody["remark"].(string)
  10739. single_dose := dataBody["single_dose"].(float64)
  10740. single_dose_unit := dataBody["single_dose_unit"].(string)
  10741. patient_id := int64(dataBody["patient_id"].(float64))
  10742. day_count := int64(dataBody["day_count"].(float64))
  10743. groupNo := int64(dataBody["group_no"].(float64))
  10744. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10745. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10746. if groupNo <= 0 {
  10747. group := service.GetMaxAdviceGroupID(org_id)
  10748. groupNo = group + 1
  10749. }
  10750. var template_id = ""
  10751. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10752. template_id = "M" + adviceLastId
  10753. advice := models.DoctorAdvice{
  10754. UserOrgId: org_id,
  10755. PatientId: patient_id,
  10756. AdviceType: adviceType,
  10757. AdviceDate: AdviceDate,
  10758. StartTime: StartTime,
  10759. AdviceName: advice_name,
  10760. AdviceDesc: advice_desc,
  10761. ReminderDate: 0,
  10762. SingleDose: single_dose,
  10763. SingleDoseUnit: single_dose_unit,
  10764. DrugSpec: 0,
  10765. DrugSpecUnit: "",
  10766. PrescribingNumber: prescribing_number,
  10767. PrescribingNumberUnit: prescribing_number_unit,
  10768. DeliveryWay: delivery_way,
  10769. ExecutionFrequency: execution_frequency,
  10770. AdviceDoctor: advice_doctor,
  10771. Status: 1,
  10772. CreatedTime: time.Now().Unix(),
  10773. UpdatedTime: 0,
  10774. AdviceAffirm: "",
  10775. Remark: remark,
  10776. StopTime: 0,
  10777. StopReason: "",
  10778. StopDoctor: 0,
  10779. StopState: 2,
  10780. ParentId: 0,
  10781. ExecutionTime: 0,
  10782. ExecutionStaff: 0,
  10783. ExecutionState: 0,
  10784. Checker: 0,
  10785. RecordDate: RecordDate,
  10786. DialysisOrderId: 0,
  10787. CheckTime: 0,
  10788. CheckState: 0,
  10789. AdviceId: 0,
  10790. RemindType: 0,
  10791. FrequencyType: frequency_type,
  10792. DayCount: day_count,
  10793. WeekDay: frequency_week,
  10794. ChildDoctorAdvice: nil,
  10795. TemplateId: template_id,
  10796. Modifier: 0,
  10797. IsCheck: 0,
  10798. Way: 0,
  10799. DrugId: 0,
  10800. DrugNameId: 0,
  10801. IsMedicine: 0,
  10802. PushStartTime: 0,
  10803. IsSettle: 0,
  10804. IsPrescription: 0,
  10805. GroupNo: groupNo,
  10806. }
  10807. service.CreateMobileAdivce(advice)
  10808. c.ServeSuccessJSON(map[string]interface{}{
  10809. "msg": "保存成功!",
  10810. })
  10811. }
  10812. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10813. patient_id, _ := c.GetInt64("patient_id")
  10814. org_id := c.GetMobileAdminUserInfo().Org.Id
  10815. app_id := c.GetMobileAdminUserInfo().App.Id
  10816. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10817. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10818. c.ServeSuccessJSON(map[string]interface{}{
  10819. "adviceList": adviceList,
  10820. "adminRoles": adminRoles,
  10821. })
  10822. }
  10823. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10824. org_id := c.GetMobileAdminUserInfo().Org.Id
  10825. dataBody := make(map[string]interface{}, 0)
  10826. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10827. if err != nil {
  10828. utils.ErrorLog(err.Error())
  10829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10830. return
  10831. }
  10832. timeLayout := "2006-01-02"
  10833. loc, _ := time.LoadLocation("Local")
  10834. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10835. utils.ErrorLog("start_time")
  10836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10837. return
  10838. }
  10839. startTime2, _ := dataBody["start_time"].(string)
  10840. time_arr := strings.Split(startTime2, " ")
  10841. if len(time_arr) > 0 {
  10842. startTime2 = time_arr[0]
  10843. }
  10844. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10845. utils.ErrorLog("advice_date")
  10846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10847. return
  10848. }
  10849. advice_date, _ := dataBody["advice_date"].(string)
  10850. var advicedateunix int64
  10851. if len(advice_date) > 0 {
  10852. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10853. if err != nil {
  10854. fmt.Println(err)
  10855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10856. return
  10857. }
  10858. advicedateunix = theTime.Unix()
  10859. }
  10860. adviceDate := startTime2
  10861. if len(adviceDate) == 0 {
  10862. utils.ErrorLog("len(adviceDate) == 0")
  10863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10864. return
  10865. }
  10866. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10867. if err != nil {
  10868. utils.ErrorLog(err.Error())
  10869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10870. return
  10871. }
  10872. AdviceDate := advicedateunix
  10873. RecordDate := advicedateunix
  10874. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10875. utils.ErrorLog("start_time")
  10876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10877. return
  10878. }
  10879. startTime, _ := dataBody["start_time"].(string)
  10880. if len(startTime) == 0 {
  10881. utils.ErrorLog("len(start_time) == 0")
  10882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10883. return
  10884. }
  10885. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10886. if err != nil {
  10887. utils.ErrorLog(err.Error())
  10888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10889. return
  10890. }
  10891. StartTime := theTime.Unix()
  10892. advice_name, _ := dataBody["advice_name"].(string)
  10893. advice_desc, _ := dataBody["advice_desc"].(string)
  10894. delivery_way, _ := dataBody["delivery_way"].(string)
  10895. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10896. prescribing_number := dataBody["prescribing_number"].(float64)
  10897. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10898. remark := dataBody["remark"].(string)
  10899. single_dose := dataBody["single_dose"].(float64)
  10900. single_dose_unit := dataBody["single_dose_unit"].(string)
  10901. patient_id := int64(dataBody["patient_id"].(float64))
  10902. groupNo := int64(dataBody["group_no"].(float64))
  10903. parent_id := int64(dataBody["parent_id"].(float64))
  10904. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10905. advice := models.XtDoctorAdviceOne{
  10906. UserOrgId: org_id,
  10907. PatientId: patient_id,
  10908. AdviceType: 1,
  10909. AdviceDate: AdviceDate,
  10910. StartTime: StartTime,
  10911. AdviceName: advice_name,
  10912. AdviceDesc: advice_desc,
  10913. ReminderDate: 0,
  10914. SingleDose: single_dose,
  10915. SingleDoseUnit: single_dose_unit,
  10916. PrescribingNumber: prescribing_number,
  10917. PrescribingNumberUnit: prescribing_number_unit,
  10918. DeliveryWay: delivery_way,
  10919. ExecutionFrequency: execution_frequency,
  10920. AdviceDoctor: advice_doctor,
  10921. Status: 1,
  10922. CreatedTime: time.Now().Unix(),
  10923. UpdatedTime: time.Now().Unix(),
  10924. AdviceAffirm: "",
  10925. Remark: remark,
  10926. StopTime: 0,
  10927. StopReason: "",
  10928. StopDoctor: 0,
  10929. StopState: 2,
  10930. ParentId: parent_id,
  10931. ExecutionTime: 0,
  10932. ExecutionStaff: 0,
  10933. ExecutionState: 0,
  10934. Checker: 0,
  10935. RecordDate: RecordDate,
  10936. DialysisOrderId: 0,
  10937. CheckTime: 0,
  10938. CheckState: 0,
  10939. DrugSpec: 0,
  10940. DrugSpecUnit: "",
  10941. Groupno: groupNo,
  10942. RemindType: 0,
  10943. FrequencyType: 0,
  10944. DayCount: 0,
  10945. WeekDay: "",
  10946. TemplateId: "",
  10947. Modifier: 0,
  10948. }
  10949. service.CreateMobileAdivceOne(advice)
  10950. c.ServeSuccessJSON(map[string]interface{}{
  10951. "msg": "保存成功!",
  10952. })
  10953. }
  10954. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10955. id, _ := c.GetInt64("id")
  10956. service.DeleteSelfAdviceSubAdvice(id)
  10957. c.ServeSuccessJSON(map[string]interface{}{
  10958. "msg": "保存成功!",
  10959. })
  10960. }
  10961. func (c *DialysisAPIController) GetEditAdviceAction() {
  10962. id, _ := c.GetInt64("id")
  10963. org_id := c.GetMobileAdminUserInfo().Org.Id
  10964. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10965. drugList, _ := service.GetAllDrugList(org_id)
  10966. c.ServeSuccessJSON(map[string]interface{}{
  10967. "advice": advice,
  10968. "drugList": drugList,
  10969. })
  10970. }
  10971. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10972. dataBody := make(map[string]interface{}, 0)
  10973. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10974. if err != nil {
  10975. utils.ErrorLog(err.Error())
  10976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10977. return
  10978. }
  10979. timeLayout := "2006-01-02"
  10980. loc, _ := time.LoadLocation("Local")
  10981. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10982. utils.ErrorLog("start_time")
  10983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10984. return
  10985. }
  10986. startTime2, _ := dataBody["start_time"].(string)
  10987. time_arr := strings.Split(startTime2, " ")
  10988. if len(time_arr) > 0 {
  10989. startTime2 = time_arr[0]
  10990. }
  10991. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10992. utils.ErrorLog("advice_date")
  10993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10994. return
  10995. }
  10996. advice_date, _ := dataBody["advice_date"].(string)
  10997. var advicedateunix int64
  10998. if len(advice_date) > 0 {
  10999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11000. if err != nil {
  11001. fmt.Println(err)
  11002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11003. return
  11004. }
  11005. advicedateunix = theTime.Unix()
  11006. }
  11007. adviceDate := startTime2
  11008. if len(adviceDate) == 0 {
  11009. utils.ErrorLog("len(adviceDate) == 0")
  11010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11011. return
  11012. }
  11013. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11014. if err != nil {
  11015. utils.ErrorLog(err.Error())
  11016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11017. return
  11018. }
  11019. AdviceDate := advicedateunix
  11020. RecordDate := advicedateunix
  11021. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11022. utils.ErrorLog("start_time")
  11023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11024. return
  11025. }
  11026. startTime, _ := dataBody["start_time"].(string)
  11027. if len(startTime) == 0 {
  11028. utils.ErrorLog("len(start_time) == 0")
  11029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11030. return
  11031. }
  11032. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11033. if err != nil {
  11034. utils.ErrorLog(err.Error())
  11035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11036. return
  11037. }
  11038. StartTime := theTime.Unix()
  11039. advice_name, _ := dataBody["advice_name"].(string)
  11040. advice_desc, _ := dataBody["advice_desc"].(string)
  11041. delivery_way, _ := dataBody["delivery_way"].(string)
  11042. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11043. prescribing_number := dataBody["prescribing_number"].(float64)
  11044. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11045. remark := dataBody["remark"].(string)
  11046. single_dose := dataBody["single_dose"].(float64)
  11047. single_dose_unit := dataBody["single_dose_unit"].(string)
  11048. id := int64(dataBody["id"].(float64))
  11049. frequency_type := int64(dataBody["frequency_type"].(float64))
  11050. frequency_week, _ := dataBody["frequency_week"].(string)
  11051. day_count := int64(dataBody["day_count"].(float64))
  11052. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11053. advice := models.XtDoctorAdviceOne{
  11054. AdviceDate: AdviceDate,
  11055. StartTime: StartTime,
  11056. AdviceName: advice_name,
  11057. AdviceDesc: advice_desc,
  11058. SingleDose: single_dose,
  11059. SingleDoseUnit: single_dose_unit,
  11060. PrescribingNumber: prescribing_number,
  11061. PrescribingNumberUnit: prescribing_number_unit,
  11062. DeliveryWay: delivery_way,
  11063. ExecutionFrequency: execution_frequency,
  11064. AdviceDoctor: advice_doctor,
  11065. Remark: remark,
  11066. RecordDate: RecordDate,
  11067. FrequencyType: frequency_type,
  11068. DayCount: day_count,
  11069. WeekDay: frequency_week,
  11070. }
  11071. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  11072. c.ServeSuccessJSON(map[string]interface{}{
  11073. "advice": advice,
  11074. })
  11075. }
  11076. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  11077. dataBody := make(map[string]interface{}, 0)
  11078. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11079. if err != nil {
  11080. utils.ErrorLog(err.Error())
  11081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11082. return
  11083. }
  11084. timeLayout := "2006-01-02"
  11085. loc, _ := time.LoadLocation("Local")
  11086. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11087. utils.ErrorLog("start_time")
  11088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11089. return
  11090. }
  11091. startTime2, _ := dataBody["start_time"].(string)
  11092. time_arr := strings.Split(startTime2, " ")
  11093. if len(time_arr) > 0 {
  11094. startTime2 = time_arr[0]
  11095. }
  11096. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11097. utils.ErrorLog("advice_date")
  11098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11099. return
  11100. }
  11101. advice_date, _ := dataBody["advice_date"].(string)
  11102. var advicedateunix int64
  11103. if len(advice_date) > 0 {
  11104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11105. if err != nil {
  11106. fmt.Println(err)
  11107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11108. return
  11109. }
  11110. advicedateunix = theTime.Unix()
  11111. }
  11112. adviceDate := startTime2
  11113. if len(adviceDate) == 0 {
  11114. utils.ErrorLog("len(adviceDate) == 0")
  11115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11116. return
  11117. }
  11118. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11119. if err != nil {
  11120. utils.ErrorLog(err.Error())
  11121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11122. return
  11123. }
  11124. AdviceDate := advicedateunix
  11125. RecordDate := advicedateunix
  11126. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11127. utils.ErrorLog("start_time")
  11128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11129. return
  11130. }
  11131. startTime, _ := dataBody["start_time"].(string)
  11132. if len(startTime) == 0 {
  11133. utils.ErrorLog("len(start_time) == 0")
  11134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11135. return
  11136. }
  11137. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11138. if err != nil {
  11139. utils.ErrorLog(err.Error())
  11140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11141. return
  11142. }
  11143. StartTime := theTime.Unix()
  11144. advice_name, _ := dataBody["advice_name"].(string)
  11145. advice_desc, _ := dataBody["advice_desc"].(string)
  11146. delivery_way, _ := dataBody["delivery_way"].(string)
  11147. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11148. prescribing_number := dataBody["prescribing_number"].(float64)
  11149. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11150. remark := dataBody["remark"].(string)
  11151. single_dose := dataBody["single_dose"].(float64)
  11152. single_dose_unit := dataBody["single_dose_unit"].(string)
  11153. id := int64(dataBody["id"].(float64))
  11154. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11155. advice := models.XtDoctorAdviceOne{
  11156. AdviceDate: AdviceDate,
  11157. StartTime: StartTime,
  11158. AdviceName: advice_name,
  11159. AdviceDesc: advice_desc,
  11160. SingleDose: single_dose,
  11161. SingleDoseUnit: single_dose_unit,
  11162. PrescribingNumber: prescribing_number,
  11163. PrescribingNumberUnit: prescribing_number_unit,
  11164. DeliveryWay: delivery_way,
  11165. ExecutionFrequency: execution_frequency,
  11166. AdviceDoctor: advice_doctor,
  11167. Remark: remark,
  11168. RecordDate: RecordDate,
  11169. }
  11170. service.UpdateMobileDoctorAdviceById(id, advice)
  11171. c.ServeSuccessJSON(map[string]interface{}{
  11172. "advice": advice,
  11173. })
  11174. }
  11175. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11176. dataBody := make(map[string]interface{}, 0)
  11177. timeLayout := "2006-01-02"
  11178. loc, _ := time.LoadLocation("Local")
  11179. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11180. if err != nil {
  11181. utils.ErrorLog(err.Error())
  11182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11183. return
  11184. }
  11185. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11186. utils.ErrorLog("start_time")
  11187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11188. return
  11189. }
  11190. startTime2, _ := dataBody["start_time"].(string)
  11191. time_arr := strings.Split(startTime2, " ")
  11192. if len(time_arr) > 0 {
  11193. startTime2 = time_arr[0]
  11194. }
  11195. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11196. utils.ErrorLog("advice_date")
  11197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11198. return
  11199. }
  11200. advice_date, _ := dataBody["advice_date"].(string)
  11201. var advicedateunix int64
  11202. if len(advice_date) > 0 {
  11203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11204. if err != nil {
  11205. fmt.Println(err)
  11206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11207. return
  11208. }
  11209. advicedateunix = theTime.Unix()
  11210. }
  11211. adviceDate := startTime2
  11212. if len(adviceDate) == 0 {
  11213. utils.ErrorLog("len(adviceDate) == 0")
  11214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11215. return
  11216. }
  11217. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11218. if err != nil {
  11219. utils.ErrorLog(err.Error())
  11220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11221. return
  11222. }
  11223. RecordDate := advicedateunix
  11224. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11225. utils.ErrorLog("start_time")
  11226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11227. return
  11228. }
  11229. startTime, _ := dataBody["start_time"].(string)
  11230. if len(startTime) == 0 {
  11231. utils.ErrorLog("len(start_time) == 0")
  11232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11233. return
  11234. }
  11235. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11236. if err != nil {
  11237. utils.ErrorLog(err.Error())
  11238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11239. return
  11240. }
  11241. StartTime := theTime.Unix()
  11242. patient_id := int64(dataBody["patient_id"].(float64))
  11243. group_no := int64(dataBody["group_no"].(float64))
  11244. org_id := c.GetMobileAdminUserInfo().Org.Id
  11245. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11246. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11247. utils.ErrorLog("advices")
  11248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11249. return
  11250. }
  11251. adviceNames := dataBody["advices"].([]interface{})
  11252. var advices []*models.GroupAdvice
  11253. for _, adviceNameMap := range adviceNames {
  11254. var advice models.GroupAdvice
  11255. adviceNameM := adviceNameMap.(map[string]interface{})
  11256. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11257. utils.ErrorLog("advice_name")
  11258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11259. return
  11260. }
  11261. adviceName, _ := adviceNameM["advice_name"].(string)
  11262. if len(adviceName) == 0 {
  11263. utils.ErrorLog("len(advice_name) == 0")
  11264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11265. return
  11266. }
  11267. advice.AdviceName = adviceName
  11268. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11269. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11270. advice.DrugSpec = drugSpec
  11271. }
  11272. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11273. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11274. advice.AdviceDesc = adviceDesc
  11275. }
  11276. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11277. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11278. advice.DrugSpecUnit = drugSpecUnit
  11279. }
  11280. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11281. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11282. advice.SingleDose = singleDose
  11283. }
  11284. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11285. singleDose := adviceNameM["single_dose"].(float64)
  11286. advice.SingleDose = singleDose
  11287. }
  11288. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11289. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11290. advice.SingleDoseUnit = singleDoseUnit
  11291. }
  11292. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11293. tmp := adviceNameM["single_dose_unit"].(float64)
  11294. singleDoseUnit := service.TypeConversion(tmp)
  11295. advice.SingleDoseUnit = singleDoseUnit
  11296. }
  11297. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11298. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11299. advice.PrescribingNumber = prescribingNumber
  11300. }
  11301. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11302. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11303. advice.PrescribingNumber = prescribingNumber
  11304. }
  11305. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11306. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11307. advice.PrescribingNumberUnit = prescribingNumberUnit
  11308. }
  11309. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11310. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11311. advice.DeliveryWay = deliveryWay
  11312. }
  11313. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11314. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11315. advice.ExecutionFrequency = executionFrequency
  11316. }
  11317. remark, _ := adviceNameM["remark"].(string)
  11318. advice.Remark = remark
  11319. advice.AdviceType = 1
  11320. advice.StartTime = StartTime
  11321. advice.RecordDate = RecordDate
  11322. advice.PatientId = patient_id
  11323. advice.UserOrgId = org_id
  11324. advice.AdviceDoctor = advice_doctor
  11325. advice.StopState = 2
  11326. advices = append(advices, &advice)
  11327. }
  11328. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11329. c.ServeSuccessJSON(map[string]interface{}{
  11330. "advice": newAdvices,
  11331. })
  11332. }
  11333. func (c *DialysisAPIController) StopLongAdvice() {
  11334. stop_time := c.GetString("execution_time")
  11335. id, _ := c.GetInt64("id")
  11336. if len(stop_time) <= 0 {
  11337. utils.ErrorLog("stop_time")
  11338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11339. return
  11340. }
  11341. timeLayout2 := "2006-01-02 15:04:05"
  11342. loc, _ := time.LoadLocation("Local")
  11343. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11344. if errs != nil {
  11345. utils.ErrorLog(errs.Error())
  11346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11347. return
  11348. }
  11349. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11350. c.ServeSuccessJSON(map[string]interface{}{
  11351. "advice": advice,
  11352. })
  11353. }
  11354. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11355. dataBody := make(map[string]interface{}, 0)
  11356. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11357. if err != nil {
  11358. utils.ErrorLog(err.Error())
  11359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11360. return
  11361. }
  11362. orgId := c.GetMobileAdminUserInfo().Org.Id
  11363. patient_id := int64(dataBody["patient_id"].(float64))
  11364. record_date := int64(dataBody["record_date"].(float64))
  11365. checker := int64(dataBody["checker"].(float64))
  11366. check_time := dataBody["check_time"].(string)
  11367. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11368. if parseStartDateErr != nil {
  11369. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11371. return
  11372. }
  11373. var advice_id []int64
  11374. var his_advice_id []int64
  11375. var project_id []int64
  11376. var team_list []int64
  11377. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11378. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11379. if len(newAdviceList) > 0 {
  11380. for _, item := range newAdviceList {
  11381. items := item.(map[string]interface{})
  11382. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11383. utils.ErrorLog("id")
  11384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11385. return
  11386. }
  11387. id := int64(items["id"].(float64))
  11388. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11389. utils.ErrorLog("origin")
  11390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11391. return
  11392. }
  11393. origin := int64(items["origin"].(float64))
  11394. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11395. utils.ErrorLog("team_id")
  11396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11397. return
  11398. }
  11399. team_id := int64(items["team_id"].(float64))
  11400. if team_id == 0 {
  11401. //临时医嘱
  11402. if origin == 1 {
  11403. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11404. advice_id = append(advice_id, id)
  11405. }
  11406. //his医嘱
  11407. if origin == 2 {
  11408. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11409. his_advice_id = append(his_advice_id, id)
  11410. }
  11411. //his医嘱
  11412. if origin == 3 {
  11413. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11414. project_id = append(project_id, id)
  11415. }
  11416. }
  11417. if team_id > 0 {
  11418. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11419. team_list = append(team_list, team_id)
  11420. }
  11421. }
  11422. }
  11423. }
  11424. advice, _ := service.GetBatchAdviceList(advice_id)
  11425. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11426. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11427. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11428. c.ServeSuccessJSON(map[string]interface{}{
  11429. "advice": advice,
  11430. "hisadvice": hisadvice,
  11431. "hisproject": hisproject,
  11432. "teamlist": teamlist,
  11433. })
  11434. return
  11435. }
  11436. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11437. dataBody := make(map[string]interface{}, 0)
  11438. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11439. if err != nil {
  11440. utils.ErrorLog(err.Error())
  11441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11442. return
  11443. }
  11444. orgId := c.GetMobileAdminUserInfo().Org.Id
  11445. patient_id := int64(dataBody["patient_id"].(float64))
  11446. record_date := int64(dataBody["record_date"].(float64))
  11447. execution_staff := int64(dataBody["execution_staff"].(float64))
  11448. execution_time := dataBody["execution_time"].(string)
  11449. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11450. if parseStartDateErr != nil {
  11451. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11453. return
  11454. }
  11455. var advice_id []int64
  11456. var his_advice_id []int64
  11457. var project_id []int64
  11458. var team_list []int64
  11459. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11460. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11461. if len(newAdviceList) > 0 {
  11462. for _, item := range newAdviceList {
  11463. items := item.(map[string]interface{})
  11464. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11465. utils.ErrorLog("id")
  11466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11467. return
  11468. }
  11469. id := int64(items["id"].(float64))
  11470. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11471. utils.ErrorLog("origin")
  11472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11473. return
  11474. }
  11475. origin := int64(items["origin"].(float64))
  11476. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11477. utils.ErrorLog("team_id")
  11478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11479. return
  11480. }
  11481. team_id := int64(items["team_id"].(float64))
  11482. if team_id == 0 {
  11483. //临时医嘱
  11484. if origin == 1 {
  11485. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11486. advice_id = append(advice_id, id)
  11487. }
  11488. //his医嘱
  11489. if origin == 2 {
  11490. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11491. his_advice_id = append(his_advice_id, id)
  11492. }
  11493. //his医嘱
  11494. if origin == 3 {
  11495. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11496. project_id = append(project_id, id)
  11497. }
  11498. }
  11499. if team_id > 0 {
  11500. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11501. team_list = append(team_list, team_id)
  11502. }
  11503. }
  11504. }
  11505. }
  11506. advice, _ := service.GetBatchAdviceList(advice_id)
  11507. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11508. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11509. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11510. c.ServeSuccessJSON(map[string]interface{}{
  11511. "advice": advice,
  11512. "hisadvice": hisadvice,
  11513. "hisproject": hisproject,
  11514. "teamlist": teamlist,
  11515. })
  11516. return
  11517. }