dialysis_api_controller.go 481KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523
  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 == 10633 {
  3665. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3666. ultrafiltration_rate = ultrafiltration_rate / 1000
  3667. }
  3668. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3669. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3670. ultrafiltration_rate = ultrafiltration_rate / 1000
  3671. }
  3672. if adminUserInfo.Org.Id == 10580 {
  3673. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3674. ultrafiltration_rate = ultrafiltration_rate / 1000
  3675. }
  3676. if adminUserInfo.Org.Id == 10629 {
  3677. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3678. ultrafiltration_rate = ultrafiltration_rate / 1000
  3679. }
  3680. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3681. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3682. ultrafiltration_rate = ultrafiltration_rate / 1000
  3683. }
  3684. if adminUserInfo.Org.Id == 10751 {
  3685. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3686. ultrafiltration_rate = ultrafiltration_rate / 1000
  3687. }
  3688. if adminUserInfo.Org.Id == 10768 {
  3689. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3690. ultrafiltration_rate = ultrafiltration_rate / 1000
  3691. }
  3692. if adminUserInfo.Org.Id == 10667 {
  3693. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3694. ultrafiltration_rate = ultrafiltration_rate / 1000
  3695. }
  3696. if adminUserInfo.Org.Id == 10693 {
  3697. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3698. ultrafiltration_rate = ultrafiltration_rate
  3699. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3700. }
  3701. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3702. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3703. ultrafiltration_rate = ultrafiltration_rate
  3704. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3705. }
  3706. if adminUserInfo.Org.Id == 10206 {
  3707. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3708. ultrafiltration_rate = ultrafiltration_rate
  3709. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3710. }
  3711. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3712. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3713. ultrafiltration_rate = ultrafiltration_rate
  3714. }
  3715. if adminUserInfo.Org.Id == 10702 {
  3716. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3717. ultrafiltration_rate = ultrafiltration_rate / 1000
  3718. }
  3719. if adminUserInfo.Org.Id == 10752 {
  3720. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3721. ultrafiltration_rate = ultrafiltration_rate / 1000
  3722. }
  3723. if adminUserInfo.Org.Id == 10723 {
  3724. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3725. ultrafiltration_rate = ultrafiltration_rate / 1000
  3726. }
  3727. if adminUserInfo.Org.Id == 10721 {
  3728. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3729. ultrafiltration_rate = ultrafiltration_rate / 1000
  3730. }
  3731. if adminUserInfo.Org.Id == 10766 {
  3732. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3733. ultrafiltration_rate = ultrafiltration_rate / 1000
  3734. }
  3735. if adminUserInfo.Org.Id == 10757 {
  3736. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3737. ultrafiltration_rate = ultrafiltration_rate / 1000
  3738. }
  3739. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3740. if prescription.ModeId == 2 {
  3741. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3742. if totalMin == 0 {
  3743. totalMin = 240
  3744. }
  3745. if prescription.ReplacementTotal == 0 {
  3746. prescription.ReplacementTotal = 15
  3747. }
  3748. //乘10 除10是为了保留一位小数
  3749. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3750. }
  3751. }
  3752. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10768 || adminUserInfo.Org.Id == 9478 {
  3753. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3754. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3755. if totalMin == 0 {
  3756. totalMin = 240
  3757. }
  3758. if prescription.DisplaceLiquiValue == 0 {
  3759. prescription.DisplaceLiquiValue = 15
  3760. }
  3761. //乘10 除10是为了保留一位小数
  3762. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3763. }
  3764. }
  3765. if adminUserInfo.Org.Id == 10752 {
  3766. if prescription.ModeId == 2 {
  3767. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3768. if totalMin == 0 {
  3769. totalMin = 240
  3770. }
  3771. if prescription.ReplacementTotal == 0 {
  3772. prescription.ReplacementTotal = 15
  3773. }
  3774. //乘10 除10是为了保留一位小数
  3775. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3776. }
  3777. }
  3778. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3779. if prescription.ModeId == 2 {
  3780. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3781. if totalMin == 0 {
  3782. totalMin = 240
  3783. }
  3784. if prescription.DisplaceLiquiValue == 0 {
  3785. prescription.ReplacementTotal = 32
  3786. }
  3787. //乘10 除10是为了保留一位小数
  3788. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3789. }
  3790. }
  3791. if adminUserInfo.Org.Id == 10726 {
  3792. if prescription.ID > 0 {
  3793. if prescription.ModeId == 2 {
  3794. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3795. if totalMin == 0 {
  3796. totalMin = 240
  3797. }
  3798. if prescription.DisplaceLiquiValue == 0 {
  3799. prescription.DisplaceLiquiValue = 1500
  3800. }
  3801. //乘10 除10是为了保留一位小数
  3802. replacement_rate = math.Floor(prescription.DisplaceLiquiValue / float64(totalMin))
  3803. }
  3804. }
  3805. }
  3806. }
  3807. }
  3808. if adminUserInfo.Org.Id == 10172 {
  3809. if prescription.ID == 0 {
  3810. if prescription.ModeId == 2 {
  3811. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3812. if totalMin == 0 {
  3813. totalMin = 240
  3814. }
  3815. if prescription.ReplacementTotal == 0 {
  3816. prescription.ReplacementTotal = 15
  3817. }
  3818. //乘10 除10是为了保留一位小数
  3819. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3820. }
  3821. }
  3822. }
  3823. if adminUserInfo.Org.Id == 10726 {
  3824. if prescription.ID == 0 {
  3825. if prescription.ModeId == 2 {
  3826. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3827. if totalMin == 0 {
  3828. totalMin = 240
  3829. }
  3830. if prescription.DisplaceLiquiValue == 0 {
  3831. prescription.DisplaceLiquiValue = 1500
  3832. }
  3833. //乘10 除10是为了保留一位小数
  3834. replacement_rate = math.Floor(prescription.DisplaceLiquiValue / float64(totalMin))
  3835. }
  3836. }
  3837. }
  3838. record := models.MonitoringRecord{
  3839. UserOrgId: adminUserInfo.Org.Id,
  3840. PatientId: patientID,
  3841. DialysisOrderId: dialysisRecord.ID,
  3842. MonitoringDate: schedulestartTime,
  3843. OperateTime: startDate.Unix(),
  3844. // MonitoringTime: recordTime,
  3845. MonitoringNurse: nurseID,
  3846. Dispose: tempdispose,
  3847. UltrafiltrationRate: ultrafiltration_rate,
  3848. UltrafiltrationVolume: 0,
  3849. Status: 1,
  3850. CreatedTime: time.Now().Unix(),
  3851. UpdatedTime: time.Now().Unix(),
  3852. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3853. ReplacementRate: replacement_rate,
  3854. }
  3855. //只针对广慈医院
  3856. 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 {
  3857. // 查询病人是否有透前评估数据
  3858. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3859. //如果有数据就插入
  3860. if errcode == nil {
  3861. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3862. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3863. record.BreathingRate = befor.BreathingRate
  3864. record.PulseFrequency = befor.PulseFrequency
  3865. record.Temperature = befor.Temperature
  3866. }
  3867. }
  3868. //孝昌
  3869. if adminUserInfo.Org.Id == 10693 {
  3870. // 查询病人是否有透前评估数据
  3871. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3872. //如果有数据就插入
  3873. if errcode == nil {
  3874. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3875. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3876. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3877. record.BreathingRate = befor.BreathingRate
  3878. }
  3879. }
  3880. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3881. if newdialysisRecord.ID > 0 {
  3882. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3883. record.Temperature = 36.5
  3884. record.ArterialPressure = -100
  3885. record.DialysateTemperature = 36.5
  3886. record.Conductivity = 14
  3887. record.BreathingRate = "20"
  3888. record.VenousPressure = 80
  3889. record.TransmembranePressure = 60
  3890. record.Dispose = catheter_operation
  3891. }
  3892. //针对新化博翔
  3893. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3894. record.BloodOxygenSaturation = "99"
  3895. record.Conductivity = 14
  3896. record.DialysateTemperature = 36.5
  3897. record.BreathingRate = "20"
  3898. }
  3899. //针对兰溪人民医院的需求
  3900. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3901. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3902. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3903. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3904. record.Temperature = befor.Temperature
  3905. record.PulseFrequency = befor.PulseFrequency
  3906. record.BreathingRate = befor.BreathingRate
  3907. }
  3908. //针对乐山友谊医院的需求
  3909. if adminUserInfo.Org.Id == 10677 {
  3910. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3911. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3912. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3913. record.Temperature = befor.Temperature
  3914. record.PulseFrequency = befor.PulseFrequency
  3915. record.BreathingRate = befor.BreathingRate
  3916. }
  3917. //新化博翔
  3918. if adminUserInfo.Org.Id == 10447 {
  3919. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3920. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3921. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3922. record.BreathingRate = befor.BreathingRate
  3923. }
  3924. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3925. record.PulseFrequency = 80
  3926. record.Temperature = 36.5
  3927. }
  3928. //诊断灵山圣康
  3929. if adminUserInfo.Org.Id == 10375 {
  3930. record.Conductivity = 13.8
  3931. record.DialysateTemperature = 37
  3932. record.DialysateFlow = 500
  3933. record.BloodFlowVolume = 200
  3934. record.BreathingRate = "18"
  3935. record.SodiumConcentration = 140
  3936. }
  3937. //江成肾病医院
  3938. if adminUserInfo.Org.Id == 10517 {
  3939. record.SodiumConcentration = 138
  3940. record.DialysateTemperature = 36.5
  3941. }
  3942. //濉溪杏康血液透析中心
  3943. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3944. record.BloodFlowVolume = prescription.BloodFlowVolume
  3945. }
  3946. //胶州少海医院
  3947. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3948. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3949. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3950. record.BreathingRate = befor.BreathingRate
  3951. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3952. record.Temperature = befor.Temperature
  3953. record.PulseFrequency = befor.PulseFrequency
  3954. }
  3955. if adminUserInfo.Org.Id != 10683 {
  3956. err = service.CreateMonitor(&record)
  3957. }
  3958. //记录日志
  3959. byterequest, _ := json.Marshal(record)
  3960. monitorRecordLog := models.XtMonitorRecordLog{
  3961. RecordDate: record.MonitoringDate,
  3962. PatientId: record.PatientId,
  3963. Module: 1,
  3964. AdminUserId: adminUserInfo.AdminUser.Id,
  3965. Ctime: time.Now().Unix(),
  3966. Mtime: 0,
  3967. Status: 1,
  3968. UserOrgId: record.UserOrgId,
  3969. ErrLog: string(byterequest),
  3970. Source: "执行上机时新增监测",
  3971. }
  3972. service.CreateMonitorRecordLog(monitorRecordLog)
  3973. finish := models.XtDialysisFinish{
  3974. IsFinish: 1,
  3975. UserOrgId: adminUserInfo.Org.Id,
  3976. Status: 1,
  3977. Ctime: time.Now().Unix(),
  3978. Mtime: 0,
  3979. Module: 7,
  3980. RecordDate: schedulestartTime,
  3981. Sourse: 1,
  3982. PatientId: patientID,
  3983. }
  3984. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3985. if dialysisFinish.ID == 0 {
  3986. service.CreateDialysisFinish(finish)
  3987. }
  3988. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3989. redis := service.RedisClient()
  3990. //清空key 值
  3991. redis.Set(key, "", time.Second)
  3992. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3993. redis.Set(keyOne, "", time.Second)
  3994. defer redis.Close()
  3995. if err != nil {
  3996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3997. return
  3998. }
  3999. }
  4000. go func() {
  4001. ssoDomain := beego.AppConfig.String("call_domain")
  4002. api := ssoDomain + "/index/uppatient"
  4003. values := make(url.Values)
  4004. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  4005. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  4006. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  4007. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  4008. http.PostForm(api, values)
  4009. }()
  4010. this.ServeSuccessJSON(map[string]interface{}{
  4011. "dialysis_order": newdialysisRecord,
  4012. "monitor": record,
  4013. })
  4014. return
  4015. }
  4016. func (c *DialysisAPIController) PostSolution() {
  4017. id, _ := c.GetInt64("patient", 0)
  4018. recordDateStr := c.GetString("record_date")
  4019. if id <= 0 {
  4020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4021. return
  4022. }
  4023. adminUserInfo := c.GetMobileAdminUserInfo()
  4024. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  4025. if patient.ID == 0 {
  4026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4027. return
  4028. }
  4029. if len(recordDateStr) == 0 {
  4030. recordDateStr = time.Now().Format("2006-01-02")
  4031. }
  4032. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4033. if parseDateErr != nil {
  4034. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4036. return
  4037. }
  4038. mode_id, _ := c.GetInt64("mode_id", 0)
  4039. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  4040. dialyzer, _ := c.GetInt64("dialyzer", 0)
  4041. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  4042. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  4043. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  4044. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  4045. replacement_way, _ := c.GetInt64("replacement_way", 0)
  4046. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  4047. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  4048. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  4049. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  4050. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  4051. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  4052. kalium, _ := c.GetFloat("kalium", 0)
  4053. sodium, _ := c.GetFloat("sodium", 0)
  4054. calcium, _ := c.GetFloat("calcium", 0)
  4055. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  4056. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  4057. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  4058. glucose, _ := c.GetFloat("glucose", 0)
  4059. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  4060. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  4061. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  4062. conductivity, _ := c.GetFloat("conductivity", 0)
  4063. remark := c.GetString("remark")
  4064. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  4065. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  4066. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  4067. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  4068. body_fluid, _ := c.GetInt64("body_fluid", 0)
  4069. special_medicine, _ := c.GetInt64("special_medicine", 0)
  4070. special_medicine_other := c.GetString("special_medicine_other")
  4071. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4072. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4073. blood_access, _ := c.GetInt64("blood_access", 0)
  4074. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4075. body_fluid_other := c.GetString("body_fluid_other")
  4076. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4077. niprocart, _ := c.GetInt64("niprocart", 0)
  4078. jms, _ := c.GetInt64("jms", 0)
  4079. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4080. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4081. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4082. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4083. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4084. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4085. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4086. injector, _ := c.GetInt64("injector", 0)
  4087. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4088. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4089. safe_package, _ := c.GetInt64("package", 0)
  4090. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4091. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4092. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4093. blood := c.GetString("blood")
  4094. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4095. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4096. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4097. displace_speed := c.GetString("displace_speed")
  4098. illness, _ := c.GetInt64("illness")
  4099. amylaceum := c.GetString("amylaceum")
  4100. single_time := c.GetString("single_time")
  4101. single_water := c.GetString("single_water")
  4102. replacement_flow := c.GetString("replacement_flow")
  4103. plasma_separator := c.GetString("plasma_separator")
  4104. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4105. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4106. oxygen_flow := c.GetString("oxygen_flow")
  4107. oxygen_time := c.GetString("oxygen_time")
  4108. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4109. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4110. puncture_needle := c.GetString("puncture_needle")
  4111. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4112. epo := c.GetString("epo")
  4113. epo_count, _ := c.GetFloat("epo_count", 0)
  4114. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4115. pre_impulse := c.GetString("pre_impulse")
  4116. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4117. admin_user_id, _ := c.GetInt64("admin_user_id")
  4118. is_water := c.GetString("is_water")
  4119. add_amount, _ := c.GetFloat("add_amount")
  4120. reduce_amount, _ := c.GetFloat("reduce_amount")
  4121. prescribing_number, _ := c.GetFloat("prescribing_number")
  4122. treatment_remark := c.GetString("treatment_remark")
  4123. prescription_sodium := c.GetString("prescription_sodium")
  4124. start_sodium := c.GetString("start_sodium")
  4125. sodium_curve := c.GetString("sodium_curve")
  4126. var is_war int64
  4127. if is_water == "是" {
  4128. is_war = 1
  4129. }
  4130. if is_water == "否" {
  4131. is_war = 2
  4132. }
  4133. if is_water == "请选择" {
  4134. is_war = 0
  4135. }
  4136. drhy_water := c.GetString("drhy_water")
  4137. dry_water_hour := c.GetString("dry_water_hour")
  4138. water_machine := c.GetString("water_machine")
  4139. dialysis_remark := c.GetString("dialysis_remark")
  4140. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4141. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4142. prescription_water, _ := c.GetFloat("prescription_water")
  4143. dialysis_strainer := c.GetString("dialysis_strainer")
  4144. chaptalization := c.GetString("chaptalization")
  4145. washing_time := c.GetString("washing_time")
  4146. warsh_count := c.GetString("warsh_count")
  4147. blood_access_part_id := c.GetString("blood_access_part_id")
  4148. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4149. dialyzate := c.GetString("dialyzate")
  4150. first_super := c.GetString("first_super")
  4151. is_sequential := c.GetString("is_sequential")
  4152. sterilization_water := c.GetString("sterilization_water")
  4153. five_glucose := c.GetString("five_glucose")
  4154. fifty_glucose := c.GetString("fifty_glucose")
  4155. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  4156. calcium_gluconate := c.GetString("calcium_gluconate")
  4157. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  4158. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  4159. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  4160. new_sty := c.GetString("new_sty")
  4161. var fisrt_sup int64
  4162. if first_super == "是" {
  4163. fisrt_sup = 1
  4164. }
  4165. if first_super == "否" {
  4166. fisrt_sup = 2
  4167. }
  4168. if first_super == "请选择" {
  4169. fisrt_sup = 0
  4170. }
  4171. var is_sequen int64
  4172. if is_sequential == "是" {
  4173. is_sequen = 1
  4174. }
  4175. if is_sequential == "否" {
  4176. is_sequen = 2
  4177. }
  4178. if is_sequential == "请选择" {
  4179. is_sequen = 0
  4180. }
  4181. conduct := c.GetString("conduct")
  4182. if mode_id > 0 {
  4183. var str string
  4184. //查找该机构用的是什么透析器
  4185. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4186. if filedConfig.ID > 0 {
  4187. str = dialyzerPerfusionApparatus
  4188. } else {
  4189. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4190. }
  4191. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4192. }
  4193. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4194. //
  4195. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4196. // if appRole.UserType == 3 {
  4197. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4198. // if getPermissionErr != nil {
  4199. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4200. // return
  4201. // } else if headNursePermission == nil {
  4202. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4203. // return
  4204. // }
  4205. // }
  4206. //}
  4207. // 查询信息规挡的设置天数
  4208. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4209. if infor.ID > 0 && infor.WeekDay > 0 {
  4210. var cha_time int64
  4211. timeNowStr := time.Now().Format("2006-01-02")
  4212. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4213. //今日的日期减去设置的日期
  4214. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4215. if cha_time >= recordDate.Unix() {
  4216. //查询审核是否允许
  4217. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4218. //申请状态不允许的情况 拒绝修改
  4219. if infor.ApplicationStatus != 1 {
  4220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4221. return
  4222. }
  4223. }
  4224. }
  4225. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4226. var dialysis_dialyszers_id int64
  4227. var dialysis_strainer_id int64
  4228. var dialysis_irrigation_id int64
  4229. if len(goodList) > 0 {
  4230. for _, item := range goodList {
  4231. if item.SpecificationName == dialysis_dialyszers {
  4232. dialysis_dialyszers_id = item.ID
  4233. }
  4234. if item.SpecificationName == dialysis_irrigation {
  4235. dialysis_irrigation_id = item.ID
  4236. }
  4237. if item.SpecificationName == dialysis_strainer {
  4238. dialysis_strainer_id = item.ID
  4239. }
  4240. }
  4241. }
  4242. prescription := models.DialysisPrescription{
  4243. UserOrgId: adminUserInfo.Org.Id,
  4244. PatientId: id,
  4245. RecordDate: recordDate.Unix(),
  4246. ModeId: mode_id,
  4247. DialysisDuration: dialysis_duration,
  4248. Dialyzer: dialyzer,
  4249. PerfusionApparatus: perfusion_apparatus,
  4250. BloodFlowVolume: blood_flow_volume,
  4251. DewaterAmount: dewater_amount,
  4252. DisplaceLiqui: displace_liqui,
  4253. ReplacementWay: replacement_way,
  4254. Anticoagulant: anticoagulant,
  4255. AnticoagulantShouji: anticoagulant_shouji,
  4256. AnticoagulantWeichi: anticoagulant_weichi,
  4257. AnticoagulantZongliang: anticoagulant_zongliang,
  4258. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4259. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4260. Kalium: kalium,
  4261. Sodium: sodium,
  4262. Calcium: calcium,
  4263. Bicarbonate: bicarbonate,
  4264. Glucose: glucose,
  4265. // DryWeight: dry_weight,
  4266. DialysateFlow: dialysate_flow,
  4267. DialysateTemperature: dialysate_temperature,
  4268. Conductivity: conductivity,
  4269. Remark: remark,
  4270. Status: 1,
  4271. CreatedTime: time.Now().Unix(),
  4272. UpdatedTime: time.Now().Unix(),
  4273. DialysisDurationMinute: dialysisDurationMinute,
  4274. DialysisDurationHour: dialysisDurationHour,
  4275. TargetUltrafiltration: targetUltrafiltration,
  4276. DialysateFormulation: dialysateFormulation,
  4277. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4278. BodyFluid: body_fluid,
  4279. SpecialMedicine: special_medicine,
  4280. SpecialMedicineOther: special_medicine_other,
  4281. DisplaceLiquiPart: displace_liqui_part,
  4282. DisplaceLiquiValue: displace_liqui_value,
  4283. BloodAccess: blood_access,
  4284. Ultrafiltration: ultrafiltration,
  4285. BodyFluidOther: body_fluid_other,
  4286. ReplacementTotal: replacement_total,
  4287. Niprocart: niprocart,
  4288. Jms: jms,
  4289. FistulaNeedleSet: fistula_needle_set,
  4290. FistulaNeedleSet16: fistula_needle_set_16,
  4291. Hemoperfusion: hemoperfusion,
  4292. DialyserSterilised: dialyser_sterilised,
  4293. Filtryzer: filtryzer,
  4294. TargetKtv: target_ktv,
  4295. Dialyzers: dialyzers,
  4296. Injector: injector,
  4297. Bloodlines: bloodlines,
  4298. TubingHemodialysis: tubing_hemodialysis,
  4299. Package: safe_package,
  4300. ALiquid: a_liquid,
  4301. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4302. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4303. Blood: blood,
  4304. DialysisDialyszers: dialysis_dialyszers,
  4305. DialysisIrrigation: dialysis_irrigation,
  4306. AntioxidantCommodityName: antioxidant_commodity_name,
  4307. DisplaceSpeed: displace_speed,
  4308. Illness: illness,
  4309. Amylaceum: amylaceum,
  4310. SingleWater: single_water,
  4311. SingleTime: single_time,
  4312. ReplacementFlow: replacement_flow,
  4313. PlasmaSeparator: plasma_separator,
  4314. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4315. OxygenUptake: oxygen_uptake,
  4316. OxygenTime: oxygen_time,
  4317. OxygenFlow: oxygen_flow,
  4318. HemodialysisPipelines: hemodialysis_pipelines,
  4319. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4320. PunctureNeedle: puncture_needle,
  4321. PunctureNeedleCount: puncture_needle_count,
  4322. Epo: epo,
  4323. EpoCount: epo_count,
  4324. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4325. PreImpulse: impulse,
  4326. AdminUserId: admin_user_id,
  4327. IsWater: is_war,
  4328. DrhyWater: drhy_water,
  4329. DryWaterHour: dry_water_hour,
  4330. WaterMachine: water_machine,
  4331. AddAmount: add_amount,
  4332. ReduceAmount: reduce_amount,
  4333. DialysisRemark: dialysis_remark,
  4334. PrescribingNumber: prescribing_number,
  4335. PrescriptionSodium: prescription_sodium,
  4336. StartSodium: start_sodium,
  4337. SodiumCurve: sodium_curve,
  4338. TreatmentRemark: treatment_remark,
  4339. DialysisFluidFlow: dialysis_fluid_flow,
  4340. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4341. PrescriptionWater: prescription_water,
  4342. DialysisStrainer: dialysis_strainer,
  4343. Chaptalization: chaptalization,
  4344. WashingTime: washing_time,
  4345. WarshCount: warsh_count,
  4346. BloodAccessPartId: blood_access_part_id,
  4347. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4348. Dialyzate: dialyzate,
  4349. DialysisDialyszersId: dialysis_dialyszers_id,
  4350. DialysisIrrigationId: dialysis_irrigation_id,
  4351. DialysisStrainerId: dialysis_strainer_id,
  4352. FirstSuper: fisrt_sup,
  4353. IsSequential: is_sequen,
  4354. Conduct: conduct,
  4355. SterilizationWater: sterilization_water,
  4356. FiveGlucose: five_glucose,
  4357. FiftyGlucose: fifty_glucose,
  4358. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4359. CalciumGluconate: calcium_gluconate,
  4360. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4361. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4362. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4363. NewSty: new_sty,
  4364. }
  4365. if prescription.ModeId != 13 {
  4366. prescription.SterilizationWater = ""
  4367. prescription.FiveGlucose = ""
  4368. prescription.FiftyGlucose = ""
  4369. prescription.MagnesiumSulfateInjection = ""
  4370. prescription.CalciumGluconate = ""
  4371. prescription.FivePotassiumChlorideInjection = ""
  4372. prescription.TenPotassiumChlorideInjection = ""
  4373. prescription.FiveSodiumBicarbonateInjection = ""
  4374. prescription.NewSty = ""
  4375. }
  4376. if adminUserInfo.Org.Id == 10721 {
  4377. if prescription.ModeId == 2 {
  4378. if prescription.ReplacementTotal == 0 {
  4379. prescription.ReplacementTotal = 15
  4380. }
  4381. }
  4382. }
  4383. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4384. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4385. if prescription.ReplacementTotal == 0 {
  4386. prescription.ReplacementTotal = 15
  4387. }
  4388. }
  4389. }
  4390. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4391. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4392. //
  4393. if appRole.UserType == 2 || appRole.UserType == 1 {
  4394. prescription_doctor = adminUserInfo.AdminUser.Id
  4395. prescription.PrescriptionDoctor = prescription_doctor
  4396. }
  4397. if dialysisPrescription.ID == 0 { //新增
  4398. prescription.Creater = adminUserInfo.AdminUser.Id
  4399. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4400. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4401. }
  4402. } else { //修改
  4403. if dialysisPrescription.Creater == 0 {
  4404. prescription.Creater = adminUserInfo.AdminUser.Id
  4405. } else {
  4406. prescription.Creater = dialysisPrescription.Creater
  4407. if adminUserInfo.Org.Id == 9882 {
  4408. if appRole.UserType == 2 || appRole.UserType == 1 {
  4409. prescription.Creater = adminUserInfo.AdminUser.Id
  4410. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4411. }
  4412. }
  4413. }
  4414. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4415. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4416. }
  4417. //if/**/
  4418. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4419. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4420. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4421. // if getPermissionErr != nil {
  4422. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4423. // return
  4424. // } else if headNursePermission == nil {
  4425. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4426. // return
  4427. // }
  4428. //}
  4429. //prescription.Creater = dialysisPrescription.Creater
  4430. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4431. prescription.Modifier = adminUserInfo.AdminUser.Id
  4432. prescription.ID = dialysisPrescription.ID
  4433. }
  4434. solution := models.DialysisSolution{
  4435. RegistrarsId: adminUserInfo.AdminUser.Id,
  4436. UserOrgId: adminUserInfo.Org.Id,
  4437. Doctor: prescription_doctor,
  4438. PatientId: id,
  4439. ModeId: mode_id,
  4440. DialysisDuration: dialysis_duration,
  4441. PerfusionApparatus: perfusion_apparatus,
  4442. BloodFlowVolume: blood_flow_volume,
  4443. Dewater: dewater_amount,
  4444. DisplaceLiqui: displace_liqui,
  4445. ReplacementWay: replacement_way,
  4446. Anticoagulant: anticoagulant,
  4447. AnticoagulantShouji: anticoagulant_shouji,
  4448. AnticoagulantWeichi: anticoagulant_weichi,
  4449. AnticoagulantZongliang: anticoagulant_zongliang,
  4450. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4451. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4452. Kalium: kalium,
  4453. Sodium: sodium,
  4454. Calcium: calcium,
  4455. Bicarbonate: bicarbonate,
  4456. Glucose: glucose,
  4457. // DryWeight: dry_weight,
  4458. DialysateFlow: dialysate_flow,
  4459. DialysateTemperature: dialysate_temperature,
  4460. Conductivity: conductivity,
  4461. Remark: remark,
  4462. Status: 1,
  4463. CreatedTime: time.Now().Unix(),
  4464. UpdatedTime: time.Now().Unix(),
  4465. DialysisDurationMinute: dialysisDurationMinute,
  4466. DialysisDurationHour: dialysisDurationHour,
  4467. TargetUltrafiltration: targetUltrafiltration,
  4468. DialysateFormulation: dialysateFormulation,
  4469. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4470. BodyFluid: body_fluid,
  4471. SpecialMedicine: special_medicine,
  4472. SpecialMedicineOther: special_medicine_other,
  4473. DisplaceLiquiPart: displace_liqui_part,
  4474. DisplaceLiquiValue: displace_liqui_value,
  4475. BloodAccess: blood_access,
  4476. Ultrafiltration: ultrafiltration,
  4477. BodyFluidOther: body_fluid_other,
  4478. ReplacementTotal: replacement_total,
  4479. TargetKtv: target_ktv,
  4480. DialysisDialyszers: dialysis_dialyszers,
  4481. DialysisIrrigation: dialysis_irrigation,
  4482. HemodialysisPipelines: hemodialysis_pipelines,
  4483. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4484. PunctureNeedle: puncture_needle,
  4485. PunctureNeedleCount: puncture_needle_count,
  4486. Epo: epo,
  4487. EpoCount: epo_count,
  4488. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4489. PreImpulse: impulse,
  4490. SolutionStatus: 1,
  4491. DialysisRemark: dialysis_remark,
  4492. PrescribingNumber: prescribing_number,
  4493. PrescriptionSodium: prescription_sodium,
  4494. StartSodium: start_sodium,
  4495. SodiumCurve: sodium_curve,
  4496. TreatmentRemark: treatment_remark,
  4497. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4498. DialysisFluidFlow: dialysis_fluid_flow,
  4499. PrescriptionWater: prescription_water,
  4500. DialysisStrainer: dialysis_strainer,
  4501. Chaptalization: chaptalization,
  4502. WashingTime: washing_time,
  4503. WarshCount: warsh_count,
  4504. BloodAccessPartId: blood_access_part_id,
  4505. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4506. Dialyzate: dialyzate,
  4507. DialysisDialyszersId: dialysis_dialyszers_id,
  4508. DialysisIrrigationId: dialysis_irrigation_id,
  4509. DialysisStrainerId: dialysis_strainer_id,
  4510. FirstSuper: fisrt_sup,
  4511. IsSequential: is_sequen,
  4512. Conduct: conduct,
  4513. SterilizationWater: sterilization_water,
  4514. FiveGlucose: five_glucose,
  4515. FiftyGlucose: fifty_glucose,
  4516. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4517. CalciumGluconate: calcium_gluconate,
  4518. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4519. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4520. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4521. NewSty: new_sty,
  4522. }
  4523. if prescription.ModeId != 13 {
  4524. prescription.SterilizationWater = ""
  4525. prescription.FiveGlucose = ""
  4526. prescription.FiftyGlucose = ""
  4527. prescription.MagnesiumSulfateInjection = ""
  4528. prescription.CalciumGluconate = ""
  4529. prescription.FivePotassiumChlorideInjection = ""
  4530. prescription.TenPotassiumChlorideInjection = ""
  4531. prescription.FiveSodiumBicarbonateInjection = ""
  4532. prescription.NewSty = ""
  4533. }
  4534. //针对河间咸的
  4535. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4536. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4537. solution.DisplaceLiquiPart = 0
  4538. solution.DisplaceLiquiValue = 0
  4539. }
  4540. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4541. prescription.DisplaceLiquiPart = 0
  4542. prescription.DisplaceLiquiValue = 0
  4543. }
  4544. }
  4545. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4546. if solution.PrescribingNumber == 0 {
  4547. solution.PrescribingNumber = 1
  4548. }
  4549. if prescription.PrescribingNumber == 0 {
  4550. prescription.PrescribingNumber = 1
  4551. }
  4552. if solution.PrescribingNumber == 0 && id == 14682 {
  4553. solution.PrescribingNumber = 2
  4554. }
  4555. if solution.PrescribingNumber == 0 && id == 18560 {
  4556. solution.PrescribingNumber = 2
  4557. }
  4558. if prescription.PrescribingNumber == 0 && id == 14682 {
  4559. prescription.PrescribingNumber = 2
  4560. }
  4561. if prescription.PrescribingNumber == 0 && id == 18560 {
  4562. prescription.PrescribingNumber = 2
  4563. }
  4564. }
  4565. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4566. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4567. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4568. if len(monitorList) > 0 {
  4569. var ultrafiltration_rate float64
  4570. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4571. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4572. var replacement_rate float64
  4573. if adminUserInfo.Org.Id == 10721 {
  4574. //乘10 除10是为了保留一位小数
  4575. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4576. }
  4577. if adminUserInfo.Org.Id == 9478 {
  4578. //乘10 除10是为了保留一位小数
  4579. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4580. }
  4581. if adminUserInfo.Org.Id == 10766 {
  4582. //乘10 除10是为了保留一位小数
  4583. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4584. }
  4585. var firstOpeateTime = monitorList[0].OperateTime
  4586. for _, item := range monitorList {
  4587. //超滤率
  4588. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4589. //置换率
  4590. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4591. //超滤量
  4592. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4593. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4594. //置换量
  4595. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4596. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4597. }
  4598. }
  4599. }
  4600. //记录日志
  4601. byterequest, _ := json.Marshal(prescription)
  4602. prescriptionLog := models.XtDialysisPrescriptionLog{
  4603. UserOrgId: prescription.UserOrgId,
  4604. Ctime: time.Now().Unix(),
  4605. Mtime: 0,
  4606. ErrLog: string(byterequest),
  4607. AdminUserId: adminUserInfo.AdminUser.Id,
  4608. RecordDate: prescription.RecordDate,
  4609. PatientId: prescription.PatientId,
  4610. Source: "手机端新增长期处方",
  4611. Status: 1,
  4612. }
  4613. service.CreatePrescriptionLog(prescriptionLog)
  4614. finish := models.XtDialysisFinish{
  4615. IsFinish: 1,
  4616. UserOrgId: adminUserInfo.Org.Id,
  4617. Status: 1,
  4618. Ctime: time.Now().Unix(),
  4619. Mtime: 0,
  4620. Module: 1,
  4621. RecordDate: recordDate.Unix(),
  4622. Sourse: 1,
  4623. PatientId: id,
  4624. }
  4625. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4626. if dialysisFinish.ID == 0 {
  4627. service.CreateDialysisFinish(finish)
  4628. }
  4629. //获取最新1条
  4630. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4631. //更新状态
  4632. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4633. //长沙南雅医院,自动生成抗凝剂的临时处方
  4634. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4635. if prescribing_number == 0 {
  4636. prescribing_number = 1
  4637. }
  4638. advice := models.DoctorAdvice{
  4639. UserOrgId: adminUserInfo.Org.Id,
  4640. PatientId: id,
  4641. GroupNo: 0,
  4642. AdviceType: 2,
  4643. RecordDate: recordDate.Unix(),
  4644. AdviceDate: recordDate.Unix(),
  4645. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4646. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4647. AdviceDesc: "",
  4648. ReminderDate: 0,
  4649. SingleDose: prescription.AnticoagulantZongliang,
  4650. SingleDoseUnit: "iu",
  4651. DrugSpec: 0,
  4652. DrugSpecUnit: "",
  4653. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4654. PrescribingNumberUnit: "支",
  4655. DeliveryWay: "静脉注射",
  4656. ExecutionFrequency: "上机前",
  4657. AdviceDoctor: 0,
  4658. Status: 1,
  4659. CreatedTime: time.Now().Unix(),
  4660. UpdatedTime: time.Now().Unix(),
  4661. IsPrescription: 1,
  4662. ExecutionState: 2,
  4663. StopState: 2,
  4664. IsSettle: 2,
  4665. }
  4666. // 查询排班信息
  4667. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4668. if schedulePatient.ID > 0 {
  4669. if schedulePatient.ScheduleType == 1 {
  4670. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4671. }
  4672. if schedulePatient.ScheduleType == 2 {
  4673. advice.StartTime = recordDate.Unix() + 9*60*60
  4674. }
  4675. }
  4676. // 抗凝剂名称
  4677. switch anticoagulant {
  4678. case 1:
  4679. advice.AdviceName = "无肝素"
  4680. break
  4681. case 2:
  4682. advice.AdviceName = "普通肝素"
  4683. break
  4684. case 3:
  4685. advice.AdviceName = "低分子肝素"
  4686. break
  4687. case 4:
  4688. advice.AdviceName = "阿加曲班"
  4689. break
  4690. case 5:
  4691. advice.AdviceName = "枸橼酸钠"
  4692. break
  4693. case 6:
  4694. advice.AdviceName = "低分子肝素钙"
  4695. break
  4696. case 7:
  4697. advice.AdviceName = "低分子肝素钠"
  4698. break
  4699. case 8:
  4700. advice.AdviceName = "依诺肝素"
  4701. break
  4702. case 9:
  4703. advice.AdviceName = "达肝素"
  4704. break
  4705. case 10:
  4706. advice.AdviceName = "体外抗凝"
  4707. break
  4708. case 11:
  4709. advice.AdviceName = "那曲肝素"
  4710. break
  4711. case 12:
  4712. advice.AdviceName = "无抗凝剂"
  4713. break
  4714. }
  4715. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4716. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4717. advice.AdviceDoctor = appRole.AdminUserId
  4718. }
  4719. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4720. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4721. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4722. advice.AdviceName = "低分子肝素钠注射液"
  4723. // 修改患者临时医嘱里的抗凝剂医嘱
  4724. advice.ID = advicePrescription.ID
  4725. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4726. } else {
  4727. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4728. advice.AdviceName = "低分子肝素钠注射液"
  4729. service.CreateDoctorAdvice(&advice)
  4730. }
  4731. }
  4732. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4733. redis := service.RedisClient()
  4734. defer redis.Close()
  4735. //清空key 值
  4736. redis.Set(key, "", time.Second)
  4737. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4738. redis.Set(keyOne, "", time.Second)
  4739. }
  4740. //获取key,清空redis
  4741. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4742. redis := service.RedisClient()
  4743. defer redis.Close()
  4744. //清空key 值
  4745. redis.Set(key, "", time.Second)
  4746. //清空长期医嘱的key
  4747. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4748. redis.Set(soulution_key, "", time.Second)
  4749. //查询最近透析准备表里是否存在 透析器 灌流器
  4750. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4751. redis.Set(keyOne, "", time.Second)
  4752. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4753. redis.Set(keyTwo, "", time.Second)
  4754. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4755. redis.Set(keyThree, "", time.Second)
  4756. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4757. redis.Set(keyFour, "", time.Second)
  4758. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4759. //
  4760. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4761. //
  4762. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4763. //if len(mation)>0{
  4764. // for _, item := range splitStr {
  4765. // for _,it := range mation{
  4766. // if(item == it.SpecificationName){
  4767. //
  4768. // //查询最近一次的透析器
  4769. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4770. //
  4771. // if errcode == gorm.ErrRecordNotFound{
  4772. // //插入数据
  4773. // prepare := models.DialysisBeforePrepare{
  4774. // UserOrgId: adminUserInfo.Org.Id,
  4775. // PatientId: id,
  4776. // RecordDate: recordDate.Unix(),
  4777. // GoodTypeId: it.GoodTypeId,
  4778. // GoodId: it.ID,
  4779. // Count: 1,
  4780. // Ctime: time.Now().Unix(),
  4781. // Creater: adminUserInfo.AdminUser.Id,
  4782. // Status:1,
  4783. //
  4784. // }
  4785. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4786. // fmt.Println("",errcode)
  4787. // }
  4788. // }
  4789. // }
  4790. //
  4791. // }
  4792. //
  4793. // for _, item := range splitIrrigation {
  4794. // for _,it := range mation{
  4795. // if(item == it.SpecificationName){
  4796. // //查询最近一次的透析器
  4797. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4798. // if errcode == gorm.ErrRecordNotFound{
  4799. // //插入数据
  4800. // prepare := models.DialysisBeforePrepare{
  4801. // UserOrgId: adminUserInfo.Org.Id,
  4802. // PatientId: id,
  4803. // RecordDate: recordDate.Unix(),
  4804. // GoodTypeId: it.GoodTypeId,
  4805. // GoodId: it.ID,
  4806. // Count: 1,
  4807. // Ctime: time.Now().Unix(),
  4808. // Creater: adminUserInfo.AdminUser.Id,
  4809. // Status:1,
  4810. //
  4811. // }
  4812. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4813. // fmt.Println(errcode)
  4814. // }
  4815. // }
  4816. // }
  4817. // }
  4818. //}
  4819. c.ServeSuccessJSON(map[string]interface{}{
  4820. "solution": &solution,
  4821. "prescription": &prescription,
  4822. })
  4823. }
  4824. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4825. patient, _ := c.GetInt64("patient", 0)
  4826. adminUserInfo := c.GetMobileAdminUserInfo()
  4827. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4828. c.ServeSuccessJSON(map[string]interface{}{
  4829. "receiveTreatmentAsses": receiveTreatmentAsses,
  4830. })
  4831. }
  4832. func (this *DialysisAPIController) PostSignInfo() {
  4833. patientID, _ := this.GetInt64("patient_id")
  4834. recordDateStr := this.GetString("date")
  4835. if patientID <= 0 {
  4836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4837. return
  4838. }
  4839. if len(recordDateStr) == 0 {
  4840. recordDateStr = time.Now().Format("2006-01-02")
  4841. }
  4842. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4843. if parseDateErr != nil {
  4844. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4846. return
  4847. }
  4848. adminInfo := this.GetMobileAdminUserInfo()
  4849. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4850. if err != nil {
  4851. this.ErrorLog("签名失败:%v", err)
  4852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4853. return
  4854. }
  4855. this.ServeSuccessJSON(map[string]interface{}{
  4856. "doctor_id": adminInfo.AdminUser.Id,
  4857. })
  4858. }
  4859. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4860. patientID, _ := this.GetInt64("patient_id")
  4861. adminInfo := this.GetMobileAdminUserInfo()
  4862. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4863. this.ServeSuccessJSON(map[string]interface{}{
  4864. "monitor": record,
  4865. })
  4866. }
  4867. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4868. thisTime := time.Now()
  4869. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4870. timeLayout := "2006-01-02 15:04:05"
  4871. loc, _ := time.LoadLocation("Local")
  4872. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4873. theAssessmentDateTime := theStartTime.Unix()
  4874. patientID, _ := this.GetInt64("patient_id")
  4875. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4876. adminInfo := this.GetMobileAdminUserInfo()
  4877. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4878. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4879. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4880. var ultrafiltration_rate float64
  4881. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4882. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4883. fmt.Println(evaluation)
  4884. fmt.Println("prescription.ID", prescription.ID)
  4885. if prescription.ID > 0 {
  4886. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4887. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4888. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4890. record.UltrafiltrationRate = ultrafiltration_rate
  4891. }
  4892. //重庆塘坝卫生院
  4893. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4894. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4895. record.UltrafiltrationRate = ultrafiltration_rate
  4896. }
  4897. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4898. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4899. record.UltrafiltrationRate = ultrafiltration_rate
  4900. }
  4901. if adminInfo.Org.Id == 10768 {
  4902. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60)
  4903. record.UltrafiltrationRate = ultrafiltration_rate
  4904. }
  4905. if adminInfo.Org.Id == 10510 {
  4906. record.UltrafiltrationRate = 0
  4907. }
  4908. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4909. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4910. record.UltrafiltrationRate = ultrafiltration_rate
  4911. }
  4912. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4913. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4914. record.UltrafiltrationRate = ultrafiltration_rate
  4915. }
  4916. // 只针对方济医院
  4917. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4918. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4919. ultrafiltration_rate = value
  4920. record.UltrafiltrationRate = ultrafiltration_rate
  4921. }
  4922. if template.TemplateId == 41 || template.TemplateId == 47 {
  4923. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4924. record.UltrafiltrationRate = ultrafiltration_rate
  4925. }
  4926. if template.TemplateId == 43 {
  4927. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4928. record.UltrafiltrationRate = ultrafiltration_rate
  4929. }
  4930. if template.TemplateId == 46 || template.TemplateId == 54 {
  4931. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4932. record.UltrafiltrationRate = ultrafiltration_rate
  4933. }
  4934. 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 {
  4935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4936. record.UltrafiltrationRate = ultrafiltration_rate
  4937. }
  4938. if adminInfo.Org.Id == 10469 {
  4939. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4940. record.UltrafiltrationRate = ultrafiltration_rate
  4941. }
  4942. if adminInfo.Org.Id == 10667 {
  4943. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4944. record.UltrafiltrationRate = ultrafiltration_rate
  4945. }
  4946. if adminInfo.Org.Id == 10471 {
  4947. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4948. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4949. }
  4950. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4951. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4952. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4953. }
  4954. if adminInfo.Org.Id == 10751 {
  4955. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4956. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4957. }
  4958. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4959. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4960. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4961. }
  4962. if adminInfo.Org.Id == 10721 {
  4963. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4964. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4965. }
  4966. if adminInfo.Org.Id == 10766 {
  4967. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4968. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4969. }
  4970. if adminInfo.Org.Id == 10757 {
  4971. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4972. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4973. }
  4974. if adminInfo.Org.Id == 10752 {
  4975. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4976. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4977. }
  4978. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4979. record.UltrafiltrationRate = 0
  4980. }
  4981. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4982. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4983. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4984. }
  4985. if adminInfo.Org.Id == 10633 {
  4986. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4987. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4988. }
  4989. if adminInfo.Org.Id == 10206 {
  4990. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4991. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4992. }
  4993. //湘潭爱心美白石
  4994. if adminInfo.Org.Id == 9850 {
  4995. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4996. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4997. }
  4998. if adminInfo.Org.Id == 9919 {
  4999. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  5000. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  5001. }
  5002. //if template.TemplateId == 47 {
  5003. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  5004. // record.UltrafiltrationRate = ultrafiltration_rate
  5005. //}
  5006. }
  5007. }
  5008. // record.UltrafiltrationRate = ultrafiltration_rate
  5009. record.UltrafiltrationVolume = 0
  5010. 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
  5011. if ultrafiltration_rate > 0 {
  5012. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5013. record.UltrafiltrationVolume = value
  5014. }
  5015. }
  5016. 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
  5017. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5018. if adminInfo.Org.Id != 10735 {
  5019. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5020. record.UltrafiltrationVolume = ultrafiltration_volume
  5021. }
  5022. //胶州少海医院
  5023. if adminInfo.Org.Id == 10735 {
  5024. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5025. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5026. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  5027. if lastMonitorRecordList.ID > 0 {
  5028. record.UltrafiltrationRate = ultrafiltration_rate_one
  5029. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  5030. record.UltrafiltrationVolume = ultrafiltration_volume
  5031. } else {
  5032. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  5033. record.UltrafiltrationVolume = ultrafiltration_volume
  5034. }
  5035. }
  5036. }
  5037. }
  5038. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  5039. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5040. record.UltrafiltrationVolume = ultrafiltration_volume
  5041. }
  5042. if adminInfo.Org.Id == 10633 {
  5043. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5044. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5045. }
  5046. //长沙南雅
  5047. 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 {
  5048. if ultrafiltration_rate > 0 {
  5049. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5050. record.UltrafiltrationVolume = ultrafiltration_volume
  5051. }
  5052. }
  5053. if adminInfo.Org.Id == 10471 {
  5054. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5055. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5056. }
  5057. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  5058. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5059. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5060. }
  5061. if adminInfo.Org.Id == 10751 {
  5062. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5063. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5064. }
  5065. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  5066. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5067. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5068. }
  5069. //长沙南雅累计血容量自动计算
  5070. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  5071. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  5072. //}
  5073. if template.TemplateId == 47 || template.TemplateId == 54 {
  5074. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5075. }
  5076. if adminInfo.Org.Id == 10510 {
  5077. record.UltrafiltrationVolume = 0
  5078. }
  5079. 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 {
  5080. if ultrafiltration_rate > 0 {
  5081. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5082. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5083. }
  5084. }
  5085. //古镇乐生
  5086. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  5087. if ultrafiltration_rate > 0 {
  5088. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5089. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5090. }
  5091. }
  5092. if adminInfo.Org.Id == 9919 {
  5093. if ultrafiltration_rate > 0 {
  5094. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5095. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  5096. }
  5097. }
  5098. if adminInfo.Org.Id == 10206 {
  5099. if ultrafiltration_rate > 0 {
  5100. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5101. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5102. }
  5103. }
  5104. if adminInfo.Org.Id == 10768 {
  5105. if ultrafiltration_rate > 0 {
  5106. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5107. record.UltrafiltrationVolume = ultrafiltration_volume
  5108. }
  5109. }
  5110. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  5111. var replacement_rate float64
  5112. var displacement_quantity float64
  5113. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5114. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  5115. record.ReplacementRate = replacement_rate
  5116. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5117. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5118. record.DisplacementQuantity = displacement_quantity
  5119. }
  5120. if adminInfo.Org.Id == 10726 {
  5121. var replacement_rate float64
  5122. var displacement_quantity float64
  5123. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5124. replacement_rate = math.Floor(prescription.DisplaceLiquiValue / float64(totalMin) * 60)
  5125. record.ReplacementRate = replacement_rate
  5126. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5127. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5128. record.DisplacementQuantity = displacement_quantity
  5129. }
  5130. if adminInfo.Org.Id == 10766 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10768 {
  5131. var replacement_rate float64
  5132. var displacement_quantity float64
  5133. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5134. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5135. record.ReplacementRate = replacement_rate
  5136. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5137. record.DisplacementQuantity = displacement_quantity
  5138. }
  5139. if adminInfo.Org.Id == 10752 {
  5140. var replacement_rate float64
  5141. var displacement_quantity float64
  5142. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5143. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5144. record.ReplacementRate = replacement_rate
  5145. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5146. record.DisplacementQuantity = displacement_quantity
  5147. }
  5148. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5149. var replacement_rate float64
  5150. var displacement_quantity float64
  5151. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5152. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5153. record.ReplacementRate = replacement_rate
  5154. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5155. record.DisplacementQuantity = displacement_quantity
  5156. }
  5157. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5158. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5159. record.UltrafiltrationVolume = ultrafiltration_volume
  5160. }
  5161. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5162. var replacement_rate float64
  5163. var displacement_quantity float64
  5164. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5165. if totalMin == 0 {
  5166. totalMin = 240
  5167. }
  5168. if prescription.DisplaceLiquiValue == 0 {
  5169. prescription.ReplacementTotal = 32
  5170. }
  5171. //乘10 除10是为了保留一位小数
  5172. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5173. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5174. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5175. record.DisplacementQuantity = displacement_quantity
  5176. }
  5177. if adminInfo.Org.Id == 9850 {
  5178. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5179. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5180. }
  5181. if adminInfo.Org.Id == 9478 {
  5182. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5183. if totalMin == 0 {
  5184. totalMin = 240
  5185. }
  5186. if prescription.DisplaceLiquiValue == 0 {
  5187. prescription.DisplaceLiquiValue = 15
  5188. }
  5189. var replacement_rate float64
  5190. //乘10 除10是为了保留一位小数
  5191. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5192. fmt.Println("hahahahahhaahahah", replacement_rate)
  5193. record.ReplacementRate = replacement_rate
  5194. }
  5195. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5196. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5197. this.ServeSuccessJSON(map[string]interface{}{
  5198. "monitor": record,
  5199. "lastMonitorRecordList": lastMonitorRecordList,
  5200. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5201. })
  5202. }
  5203. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5204. record_id, _ := this.GetInt64("id")
  5205. nurseID, _ := this.GetInt64("start_nurse")
  5206. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5207. bedID, _ := this.GetInt64("bed")
  5208. start_time := this.GetString("start_time")
  5209. schedual_type, _ := this.GetInt64("schedual_type")
  5210. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5211. change_nurse, _ := this.GetInt64("change_nurse")
  5212. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5213. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5214. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5215. patient_id, _ := this.GetInt64("patient_id")
  5216. record_date, _ := this.GetInt64("record_date")
  5217. puncture_needle := this.GetString("puncture_needle")
  5218. puncture_way := this.GetString("puncture_way")
  5219. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5220. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5221. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5222. nuclein_date_str := this.GetString("nuclein_date_str")
  5223. order_remark := this.GetString("order_remark")
  5224. schedule_remark := this.GetString("schedule_remark")
  5225. catheter_operation := this.GetString("catheter_operation")
  5226. blood_flow_volume := this.GetString("blood_flow_volume")
  5227. blood_drawing, _ := this.GetInt64("blood_drawing")
  5228. dialysis_strainer := this.GetString("dialysis_strainer")
  5229. if record_id == 0 {
  5230. this.ErrorLog("id:%v", record_id)
  5231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5232. return
  5233. }
  5234. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5235. if parseStartDateErr != nil {
  5236. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5238. return
  5239. }
  5240. adminUserInfo := this.GetMobileAdminUserInfo()
  5241. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5242. if getNurseErr != nil {
  5243. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5245. return
  5246. } else if nurse == nil {
  5247. this.ErrorLog("护士不存在")
  5248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5249. return
  5250. }
  5251. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5252. //if getNurseErr != nil {
  5253. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5254. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5255. // return
  5256. //} else if nurse == nil {
  5257. // this.ErrorLog("护士不存在")
  5258. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5259. // return
  5260. //}
  5261. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5262. if getDeviceNumberErr != nil {
  5263. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5265. return
  5266. } else if deviceNumber == nil {
  5267. this.ErrorLog("床位号不存在")
  5268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5269. return
  5270. }
  5271. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5272. //
  5273. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5274. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5275. // if getPermissionErr != nil {
  5276. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5277. // return
  5278. // } else if headNursePermission == nil {
  5279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5280. // return
  5281. // }
  5282. //}
  5283. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5284. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5285. timeLayout := "2006-01-02 15:04:05"
  5286. loc, _ := time.LoadLocation("Local")
  5287. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5288. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5289. schedulestartTime := theStartTime.Unix()
  5290. scheduleendTime := theEndTime.Unix()
  5291. var theNucleinDate int64
  5292. timeLayoutOne := "2006-01-02"
  5293. if len(nuclein_date_str) > 0 {
  5294. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5295. if err != nil {
  5296. utils.ErrorLog(err.Error())
  5297. }
  5298. theNucleinDate = theTime.Unix()
  5299. }
  5300. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5301. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5302. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5303. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5304. if err == gorm.ErrRecordNotFound { //空床位
  5305. // 修改了床位逻辑
  5306. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5307. if daySchedule.ID > 0 {
  5308. //daySchedule.BedId = bedID
  5309. //daySchedule.PartitionId = deviceNumber.ZoneID
  5310. //daySchedule.ScheduleType = schedual_type
  5311. //daySchedule.UpdatedTime = time.Now().Unix()
  5312. //err := service.UpdateSchedule(&daySchedule)
  5313. xtSchedule := models.Schedule{
  5314. PartitionId: deviceNumber.ZoneID,
  5315. BedId: bedID,
  5316. ScheduleType: schedual_type,
  5317. UpdatedTime: time.Now().Unix(),
  5318. }
  5319. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5320. if err != nil {
  5321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5322. return
  5323. }
  5324. }
  5325. } else if err == nil {
  5326. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5327. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5328. if daySchedule.ID > 0 {
  5329. //daySchedule.BedId = bedID
  5330. //daySchedule.PartitionId = deviceNumber.ZoneID
  5331. //
  5332. //daySchedule.ScheduleType = schedual_type
  5333. //daySchedule.UpdatedTime = time.Now().Unix()
  5334. //err := service.UpdateSchedule(&daySchedule)
  5335. xtSchedule := models.Schedule{
  5336. PartitionId: deviceNumber.ZoneID,
  5337. BedId: bedID,
  5338. ScheduleType: schedual_type,
  5339. UpdatedTime: time.Now().Unix(),
  5340. }
  5341. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5342. if err != nil {
  5343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5344. return
  5345. }
  5346. }
  5347. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5349. return
  5350. }
  5351. } else if err != nil {
  5352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5353. return
  5354. }
  5355. }
  5356. dialysisRecord := &models.DialysisOrder{
  5357. ID: record_id,
  5358. UserOrgId: adminUserInfo.Org.Id,
  5359. BedID: bedID,
  5360. StartNurse: nurseID,
  5361. StartTime: startDate.Unix(),
  5362. PunctureNurse: puncture_nurse,
  5363. Creator: adminUserInfo.AdminUser.Id,
  5364. Modifier: adminUserInfo.AdminUser.Id,
  5365. WashpipeNurse: washpipe_nurse,
  5366. SchedualType: schedual_type,
  5367. ChangeNurse: change_nurse,
  5368. DifficultPunctureNurse: difficult_puncture_nurse,
  5369. NewFistulaNurse: new_fistula_nurse,
  5370. QualityNurseId: quality_nurse_id,
  5371. PunctureNeedle: puncture_needle,
  5372. PunctureWay: puncture_way,
  5373. DialysisDialyszers: dialysis_dialyszers,
  5374. DialysisIrrigation: dialysis_irrigation,
  5375. BloodAccessId: blood_access_id,
  5376. NucleinDate: theNucleinDate,
  5377. OrderRemark: order_remark,
  5378. ScheduleRemark: schedule_remark,
  5379. CatheterOperation: catheter_operation,
  5380. BloodFlowVolume: blood_flow_volume,
  5381. BloodDrawing: blood_drawing,
  5382. DialysisStrainer: dialysis_strainer,
  5383. }
  5384. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5385. if prescription.ID > 0 {
  5386. var endTime int64
  5387. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5388. dialysisRecord.EndTime = endTime
  5389. }
  5390. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10164 {
  5391. //查询第一条监测
  5392. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5393. service.UpdateFirstMoitorById(firstMonitor.ID, dialysisRecord.StartTime)
  5394. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5395. redis := service.RedisClient()
  5396. //清空key 值
  5397. redis.Set(key, "", time.Second)
  5398. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5399. redis.Set(keyOne, "", time.Second)
  5400. defer redis.Close()
  5401. }
  5402. //修改床位号需要重新消毒
  5403. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5404. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5405. //查询第一条监测
  5406. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5407. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5408. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5409. redis := service.RedisClient()
  5410. //清空key 值
  5411. redis.Set(key, "", time.Second)
  5412. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5413. redis.Set(keyOne, "", time.Second)
  5414. defer redis.Close()
  5415. }
  5416. // 查询信息规挡的设置天数
  5417. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5418. if infor.ID > 0 && infor.WeekDay > 0 {
  5419. var cha_time int64
  5420. timeNowStr := time.Now().Format("2006-01-02")
  5421. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5422. //今日的日期减去设置的日期
  5423. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5424. if cha_time >= record_date {
  5425. //查询审核是否允许
  5426. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5427. //申请状态不允许的情况 拒绝修改
  5428. if infor.ApplicationStatus != 1 {
  5429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5430. return
  5431. }
  5432. }
  5433. }
  5434. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5435. //修改床位后重新生成消毒计划
  5436. if adminUserInfo.Org.Id == 10340 {
  5437. //根据床位号获取设备型号
  5438. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5439. //查询使用消毒最后一条消毒记录
  5440. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5441. fmt.Println("err", err)
  5442. if err == gorm.ErrRecordNotFound {
  5443. //查找排班
  5444. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5445. //查询改设备是否有消毒计划
  5446. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5447. //根据床位号获取设备id
  5448. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5449. //查询病人信息
  5450. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5451. var con = ""
  5452. if patients.IsInfectious == 0 {
  5453. con = ""
  5454. }
  5455. if patients.IsInfectious == 1 {
  5456. con = "无"
  5457. }
  5458. if patients.IsInfectious == 2 {
  5459. con = "有"
  5460. }
  5461. if errcode == nil {
  5462. var end_time int64
  5463. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5464. //新增消毒
  5465. information := models.DeviceInformation{
  5466. Date: dialysisRecord.DialysisDate,
  5467. Zone: dialysisRecord.ZoneId,
  5468. Class: dialysisRecord.SchedualType,
  5469. BedNumber: dialysisRecord.BedID,
  5470. PatientId: dialysisRecord.PatientId,
  5471. DialysisMode: scheduleByPatient.ModeId,
  5472. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5473. Disinfection: 1,
  5474. DialysisConcentration: 1,
  5475. DisinfectionStatus: 1,
  5476. Move: 1,
  5477. UserOrgId: dialysisRecord.UserOrgId,
  5478. DisinfectType: plan.Way,
  5479. DisinfectantType: plan.MachineDisinfectant,
  5480. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5481. Disinfectant: plan.Disinfectant,
  5482. Ctime: time.Now().Unix(),
  5483. Status: 1,
  5484. SignName: nurseID,
  5485. EquimentId: addmacher.ID,
  5486. DisinfectionResidue: 2,
  5487. Bed: addmacher.BedNumber,
  5488. StartTime: dialysisRecord.StartTime,
  5489. EndTime: dialysisRecord.EndTime,
  5490. Contagion: con,
  5491. WeightLoss: 0,
  5492. Hyperfiltratio: 0,
  5493. DialysisHour: "",
  5494. MachineRun: 1,
  5495. DisinfecStartime: dialysisRecord.EndTime,
  5496. DisinfecEndtime: end_time,
  5497. }
  5498. err := service.CreateInformationTwo(&information)
  5499. fmt.Println("报错", err)
  5500. }
  5501. }
  5502. }
  5503. order, _ := service.GetLastPatientOrder(record_id)
  5504. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5505. redis := service.RedisClient()
  5506. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5507. redis.Set(key, "", time.Second)
  5508. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5509. //清空key 值
  5510. redis.Set(keyOne, "", time.Second)
  5511. scheduleDateStartOne := startDate.Format("2006-01-02")
  5512. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5513. redis.Set(keyTwo, "", time.Second)
  5514. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5515. redis.Set(keyThree, "", time.Second)
  5516. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5517. redis.Set(keyFour, "", time.Second)
  5518. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5519. redis.Set(keyFive, "", time.Second)
  5520. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5521. redis.Set(keySix, "", time.Second)
  5522. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5523. redis.Set(keySeven, "", time.Second)
  5524. if updateErr != nil {
  5525. this.ErrorLog("修改上机失败:%v", updateErr)
  5526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5527. return
  5528. }
  5529. if updateErr == nil {
  5530. if tempDialysisRecord.Stage == 2 {
  5531. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5532. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5533. fmt.Println(value)
  5534. a, b := math.Modf(value)
  5535. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5536. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5537. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5538. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5539. redis := service.RedisClient()
  5540. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5541. redis.Set(key, "", time.Second)
  5542. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5543. redis.Set(keyOne, "", time.Second)
  5544. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5545. //清空key 值
  5546. redis.Set(keySix, "", time.Second)
  5547. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5548. redis.Set(keySeven, "", time.Second)
  5549. redis.Close()
  5550. if updateAssessmentErr != nil {
  5551. utils.ErrorLog("%v", updateAssessmentErr)
  5552. }
  5553. }
  5554. }
  5555. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5556. this.ServeSuccessJSON(map[string]interface{}{
  5557. "dialysis_order": dialysisRecords,
  5558. })
  5559. }
  5560. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5561. record_id, _ := c.GetInt64("id")
  5562. nurseID, _ := c.GetInt64("nurse")
  5563. end_time := c.GetString("end_time")
  5564. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5565. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5566. catheter := c.GetString("catheter")
  5567. cruor := c.GetString("cruor")
  5568. mission := c.GetString("mission")
  5569. condenser := c.GetString("condenser")
  5570. if record_id <= 0 || nurseID <= 0 {
  5571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5572. return
  5573. }
  5574. adminUserInfo := c.GetMobileAdminUserInfo()
  5575. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5576. if getNurseErr != nil {
  5577. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5579. return
  5580. } else if nurse == nil {
  5581. c.ErrorLog("护士不存在")
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5583. return
  5584. }
  5585. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5586. if parseEndDateErr != nil {
  5587. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5589. return
  5590. }
  5591. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5592. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5593. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5594. // if getPermissionErr != nil {
  5595. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5596. // return
  5597. // } else if headNursePermission == nil {
  5598. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5599. // return
  5600. // }
  5601. //}
  5602. // 查询信息规挡的设置天数
  5603. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5604. if infor.ID > 0 {
  5605. var cha_time int64
  5606. timeNowStr := time.Now().Format("2006-01-02")
  5607. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5608. //今日的日期减去设置的日期
  5609. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5610. if cha_time >= tempDialysisRecords.DialysisDate {
  5611. //查询审核是否允许
  5612. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5613. //申请状态不允许的情况 拒绝修改
  5614. if infor.ApplicationStatus != 1 {
  5615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5616. return
  5617. }
  5618. }
  5619. }
  5620. dialysisRecord := &models.DialysisOrder{
  5621. ID: record_id,
  5622. UserOrgId: adminUserInfo.Org.Id,
  5623. EndTime: endDate.Unix(),
  5624. FinishNurse: nurseID,
  5625. FinishModifier: adminUserInfo.AdminUser.Id,
  5626. PuncturePointHaematoma: puncture_point_haematoma,
  5627. BloodAccessInternalFistula: blood_access_internal_fistula,
  5628. Catheter: catheter,
  5629. Cruor: cruor,
  5630. Mission: mission,
  5631. Condenser: condenser,
  5632. }
  5633. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5634. redis := service.RedisClient()
  5635. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5636. //清空key 值
  5637. redis.Set(key, "", time.Second)
  5638. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5639. //清空key 值
  5640. redis.Set(keyOne, "", time.Second)
  5641. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5642. redis.Set(keySeven, "", time.Second)
  5643. redis.Close()
  5644. if updateErr != nil {
  5645. c.ErrorLog("修改下机失败:%v", updateErr)
  5646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5647. return
  5648. }
  5649. if updateErr == nil {
  5650. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5651. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5652. a, b := math.Modf(value)
  5653. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5654. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5655. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5656. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5657. redis := service.RedisClient()
  5658. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5659. redis.Set(keyTen, "", time.Second)
  5660. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5661. redis.Set(keyTwo, "", time.Second)
  5662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5663. redis.Set(key, "", time.Second)
  5664. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5665. redis.Set(keyThree, "", time.Second)
  5666. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5667. redis.Set(keySeven, "", time.Second)
  5668. defer redis.Close()
  5669. if updateAssessmentErr != nil {
  5670. utils.ErrorLog("%v", updateAssessmentErr)
  5671. }
  5672. }
  5673. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5674. c.ServeSuccessJSON(map[string]interface{}{
  5675. "dialysis_order": dialysisRecords,
  5676. })
  5677. }
  5678. func (c *DialysisAPIController) GetLongAdvice() {
  5679. patient_id, _ := c.GetInt64("id")
  5680. adminUserInfo := c.GetMobileAdminUserInfo()
  5681. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5682. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5683. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5684. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5685. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5686. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5687. c.ServeSuccessJSON(map[string]interface{}{
  5688. "status": "1",
  5689. })
  5690. return
  5691. } else { //开启推送提醒
  5692. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5693. var advice_three []*models.DoctorAdvice
  5694. recordDateStr := time.Now().Format("2006-01-02")
  5695. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5696. nowtime := recordDate.Unix()
  5697. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5698. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5699. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5700. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5701. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5702. for _, advice := range advices {
  5703. if advice.FrequencyType == 3 {
  5704. t := time.Now()
  5705. week := int(t.Weekday())
  5706. fmt.Println(t.Weekday())
  5707. fmt.Println(week)
  5708. switch week {
  5709. case 1:
  5710. if strings.Index(advice.WeekDay, "周一") == -1 {
  5711. advice_three = append(advice_three, advice)
  5712. }
  5713. break
  5714. case 2:
  5715. if strings.Index(advice.WeekDay, "周二") == -1 {
  5716. advice_three = append(advice_three, advice)
  5717. }
  5718. break
  5719. case 3:
  5720. if strings.Index(advice.WeekDay, "周三") == -1 {
  5721. advice_three = append(advice_three, advice)
  5722. }
  5723. break
  5724. case 4:
  5725. if strings.Index(advice.WeekDay, "周四") == -1 {
  5726. advice_three = append(advice_three, advice)
  5727. }
  5728. break
  5729. case 5:
  5730. if strings.Index(advice.WeekDay, "周五") == -1 {
  5731. advice_three = append(advice_three, advice)
  5732. }
  5733. break
  5734. case 6:
  5735. if strings.Index(advice.WeekDay, "周六") == -1 {
  5736. advice_three = append(advice_three, advice)
  5737. }
  5738. break
  5739. case 0:
  5740. if strings.Index(advice.WeekDay, "周日") == -1 {
  5741. advice_three = append(advice_three, advice)
  5742. }
  5743. break
  5744. }
  5745. }
  5746. }
  5747. for _, advice := range advices_two {
  5748. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5749. now := p.Unix()
  5750. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5751. dayStr2 := "-" + dayStr
  5752. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5753. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5754. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5755. for _, ad := range advices {
  5756. advice_three = append(advice_three, ad)
  5757. }
  5758. }
  5759. if err == nil {
  5760. c.ServeSuccessJSON(map[string]interface{}{
  5761. "status": "2",
  5762. "advices": advices,
  5763. "advices_two": RemoveRepeatedElement(advice_three),
  5764. "is_open_remind": config.IsOpenRemind,
  5765. "his_config_open": hisConfig.IsOpen,
  5766. "is_advice_open": is_advice_open.IsAdviceOpen,
  5767. "prescription_open": prescription_open.IsOpen,
  5768. })
  5769. }
  5770. }
  5771. }
  5772. func (c *DialysisAPIController) GetLongAdviceOne() {
  5773. patient_id, _ := c.GetInt64("id")
  5774. startTime := c.GetString("schedule_date")
  5775. timeLayout := "2006-01-02"
  5776. loc, _ := time.LoadLocation("Local")
  5777. var theStartTime int64
  5778. if len(startTime) > 0 {
  5779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5780. if err != nil {
  5781. utils.ErrorLog(err.Error())
  5782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5783. return
  5784. }
  5785. theStartTime = theTime.Unix()
  5786. }
  5787. adminUserInfo := c.GetMobileAdminUserInfo()
  5788. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5789. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5790. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5791. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5792. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5793. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5794. c.ServeSuccessJSON(map[string]interface{}{
  5795. "status": "1",
  5796. })
  5797. return
  5798. } else { //开启推送提醒
  5799. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5800. var advice_three []*models.DoctorAdvice
  5801. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5802. fmt.Println("theStartTime-----------------------", theStartTime)
  5803. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5804. for _, advice := range advices {
  5805. if advice.FrequencyType == 3 {
  5806. t := time.Now()
  5807. week := int(t.Weekday())
  5808. fmt.Println(t.Weekday())
  5809. fmt.Println(week)
  5810. switch week {
  5811. case 1:
  5812. if strings.Index(advice.WeekDay, "周一") == -1 {
  5813. advice_three = append(advice_three, advice)
  5814. }
  5815. break
  5816. case 2:
  5817. if strings.Index(advice.WeekDay, "周二") == -1 {
  5818. advice_three = append(advice_three, advice)
  5819. }
  5820. break
  5821. case 3:
  5822. if strings.Index(advice.WeekDay, "周三") == -1 {
  5823. advice_three = append(advice_three, advice)
  5824. }
  5825. break
  5826. case 4:
  5827. if strings.Index(advice.WeekDay, "周四") == -1 {
  5828. advice_three = append(advice_three, advice)
  5829. }
  5830. break
  5831. case 5:
  5832. if strings.Index(advice.WeekDay, "周五") == -1 {
  5833. advice_three = append(advice_three, advice)
  5834. }
  5835. break
  5836. case 6:
  5837. if strings.Index(advice.WeekDay, "周六") == -1 {
  5838. advice_three = append(advice_three, advice)
  5839. }
  5840. break
  5841. case 0:
  5842. if strings.Index(advice.WeekDay, "周日") == -1 {
  5843. advice_three = append(advice_three, advice)
  5844. }
  5845. break
  5846. }
  5847. }
  5848. }
  5849. for _, advice := range advices_two {
  5850. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5851. now := p.Unix()
  5852. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5853. dayStr2 := "-" + dayStr
  5854. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5855. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5856. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5857. fmt.Println("advices-==---------------", advices)
  5858. for _, ad := range advices {
  5859. advice_three = append(advice_three, ad)
  5860. }
  5861. }
  5862. if err == nil {
  5863. c.ServeSuccessJSON(map[string]interface{}{
  5864. "status": "2",
  5865. "advices": advices,
  5866. "advices_two": RemoveRepeatedElement(advice_three),
  5867. "is_open_remind": config.IsOpenRemind,
  5868. "his_config_open": hisConfig.IsOpen,
  5869. "is_advice_open": is_advice_open.IsAdviceOpen,
  5870. "prescription_open": prescription_open.IsOpen,
  5871. })
  5872. }
  5873. }
  5874. }
  5875. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5876. newArr = make([]*models.DoctorAdvice, 0)
  5877. for i := 0; i < len(arr); i++ {
  5878. repeat := false
  5879. for j := i + 1; j < len(arr); j++ {
  5880. if arr[i].ID == arr[j].ID {
  5881. repeat = true
  5882. break
  5883. }
  5884. }
  5885. if !repeat {
  5886. newArr = append(newArr, arr[i])
  5887. }
  5888. }
  5889. return
  5890. }
  5891. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5892. patient, _ := c.GetInt64("id", 0)
  5893. groupNo, _ := c.GetInt64("groupno", 0)
  5894. if patient <= 0 {
  5895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5896. return
  5897. }
  5898. adminUserInfo := c.GetMobileAdminUserInfo()
  5899. dataBody := make(map[string]interface{}, 0)
  5900. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5901. if err != nil {
  5902. utils.ErrorLog(err.Error())
  5903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5904. return
  5905. }
  5906. utils.ErrorLog("%v", dataBody)
  5907. timeLayout := "2006-01-02 15:04"
  5908. loc, _ := time.LoadLocation("Local")
  5909. timeLayout2 := "2006-01-02"
  5910. loc2, _ := time.LoadLocation("Local")
  5911. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5912. utils.ErrorLog("advice_type")
  5913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5914. return
  5915. }
  5916. adviceType := int64(2)
  5917. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5918. utils.ErrorLog("advice_date")
  5919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5920. return
  5921. }
  5922. adviceDate, _ := dataBody["advice_date"].(string)
  5923. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5924. AdviceDate := theTime.Unix()
  5925. RecordDate := theTime.Unix()
  5926. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5927. utils.ErrorLog("start_time")
  5928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5929. return
  5930. }
  5931. startTime, _ := dataBody["start_time"].(string)
  5932. if len(startTime) == 0 {
  5933. utils.ErrorLog("len(start_time) == 0")
  5934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5935. return
  5936. }
  5937. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5938. if err != nil {
  5939. utils.ErrorLog(err.Error())
  5940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5941. return
  5942. }
  5943. StartTime := theTime.Unix()
  5944. Remark := ""
  5945. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5946. remark, _ := dataBody["remark"].(string)
  5947. Remark = remark
  5948. }
  5949. var advices []*models.GroupAdvice
  5950. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5951. utils.ErrorLog("advices")
  5952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. return
  5954. }
  5955. adviceNames := dataBody["advices"].([]interface{})
  5956. for _, adviceNameMap := range adviceNames {
  5957. adviceNameM := adviceNameMap.(map[string]interface{})
  5958. var advice models.GroupAdvice
  5959. advice.Remark = Remark
  5960. advice.AdviceType = adviceType
  5961. advice.StartTime = StartTime
  5962. advice.AdviceDate = AdviceDate
  5963. advice.RecordDate = RecordDate
  5964. advice.Status = 1
  5965. advice.CreatedTime = time.Now().Unix()
  5966. advice.UpdatedTime = time.Now().Unix()
  5967. advice.StopState = 2
  5968. advice.ExecutionState = 2
  5969. advice.UserOrgId = adminUserInfo.Org.Id
  5970. advice.PatientId = patient
  5971. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5972. advice.IsSettle = 2
  5973. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5974. utils.ErrorLog("advice_name")
  5975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5976. return
  5977. }
  5978. adviceName, _ := adviceNameM["advice_name"].(string)
  5979. if len(adviceName) == 0 {
  5980. utils.ErrorLog("len(advice_name) == 0")
  5981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5982. return
  5983. }
  5984. advice.AdviceName = adviceName
  5985. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5986. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5987. advice.DrugSpec = drugSpec
  5988. }
  5989. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5990. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5991. advice.AdviceDesc = adviceDesc
  5992. }
  5993. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5994. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5995. advice.DrugSpecUnit = drugSpecUnit
  5996. }
  5997. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5998. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5999. // advice.SingleDose = singleDose
  6000. //}
  6001. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  6002. //single_dose := int64(adviceNameM["single_dose"].(float64))
  6003. advice.SingleDose = adviceNameM["single_dose"].(float64)
  6004. }
  6005. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  6006. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  6007. advice.SingleDoseUnit = singleDoseUnit
  6008. }
  6009. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  6010. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  6011. // advice.PrescribingNumber = prescribingNumber
  6012. //}
  6013. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  6014. //single_dose := int64(adviceNameM["single_dose"].(float64))
  6015. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  6016. }
  6017. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  6018. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  6019. advice.PrescribingNumberUnit = prescribingNumberUnit
  6020. }
  6021. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  6022. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  6023. advice.DeliveryWay = deliveryWay
  6024. }
  6025. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  6026. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  6027. advice.ExecutionFrequency = executionFrequency
  6028. }
  6029. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  6030. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  6031. advice.FrequencyType = frequency_type
  6032. }
  6033. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  6034. day_count := int64(adviceNameM["day_count"].(float64))
  6035. advice.DayCount = day_count
  6036. }
  6037. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  6038. week_day, _ := adviceNameM["week_day"].(string)
  6039. advice.WeekDay = week_day
  6040. }
  6041. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  6042. way := int64(adviceNameM["way"].(float64))
  6043. advice.Way = way
  6044. }
  6045. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  6046. drug_id := int64(adviceNameM["drug_id"].(float64))
  6047. advice.DrugId = drug_id
  6048. }
  6049. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  6050. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  6051. advice.DrugNameId = drug_name_id
  6052. }
  6053. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  6054. remark, _ := adviceNameM["remark"].(string)
  6055. advice.Remark = remark
  6056. }
  6057. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  6058. groupno := int64(adviceNameM["groupno"].(float64))
  6059. advice.GroupNo = groupno
  6060. }
  6061. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  6062. template_id, _ := adviceNameM["template_id"].(string)
  6063. advice.TemplateId = template_id
  6064. }
  6065. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  6066. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  6067. advice.ExecutionFrequency = executionFrequency
  6068. }
  6069. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  6070. children := adviceNameM["child"].([]interface{})
  6071. if len(children) > 0 {
  6072. for _, childrenMap := range children {
  6073. childMap := childrenMap.(map[string]interface{})
  6074. var child models.GroupAdvice
  6075. child.Remark = Remark
  6076. child.AdviceType = adviceType
  6077. child.StartTime = StartTime
  6078. child.AdviceDate = AdviceDate
  6079. child.RecordDate = RecordDate
  6080. child.Status = 1
  6081. child.CreatedTime = time.Now().Unix()
  6082. child.UpdatedTime = time.Now().Unix()
  6083. child.StopState = 2
  6084. child.ExecutionState = 2
  6085. child.UserOrgId = adminUserInfo.Org.Id
  6086. child.PatientId = patient
  6087. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  6088. child.IsSettle = 1
  6089. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  6090. utils.ErrorLog("child advice_name")
  6091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6092. return
  6093. }
  6094. childAdviceName, _ := childMap["advice_name"].(string)
  6095. if len(childAdviceName) == 0 {
  6096. utils.ErrorLog("len(child advice_name) == 0")
  6097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6098. return
  6099. }
  6100. child.AdviceName = childAdviceName
  6101. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  6102. childAdviceDesc, _ := childMap["advice_desc"].(string)
  6103. child.AdviceDesc = childAdviceDesc
  6104. }
  6105. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  6106. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  6107. child.DrugSpec = childDrugSpec
  6108. }
  6109. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  6110. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  6111. child.DrugSpecUnit = childDrugSpecUnit
  6112. }
  6113. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  6114. child.SingleDose = childMap["single_dose"].(float64)
  6115. }
  6116. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  6117. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  6118. child.SingleDoseUnit = childSingleDoseUnit
  6119. }
  6120. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  6121. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  6122. }
  6123. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  6124. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  6125. child.PrescribingNumberUnit = childPrescribingNumberUnit
  6126. }
  6127. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  6128. groupno := int64(childMap["groupno"].(float64))
  6129. advice.GroupNo = groupno
  6130. }
  6131. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  6132. remark, _ := childMap["remark"].(string)
  6133. child.Remark = remark
  6134. }
  6135. child.DeliveryWay = advice.DeliveryWay
  6136. child.ExecutionFrequency = advice.ExecutionFrequency
  6137. advice.Children = append(advice.Children, &child)
  6138. }
  6139. }
  6140. }
  6141. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  6142. if temp_advice.ID == 0 {
  6143. advices = append(advices, &advice)
  6144. }
  6145. }
  6146. if len(advices) > 0 {
  6147. finish := models.XtDialysisFinish{
  6148. IsFinish: 1,
  6149. UserOrgId: adminUserInfo.Org.Id,
  6150. Status: 1,
  6151. Ctime: time.Now().Unix(),
  6152. Mtime: 0,
  6153. Module: 4,
  6154. RecordDate: AdviceDate,
  6155. Sourse: 1,
  6156. PatientId: patient,
  6157. }
  6158. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  6159. if dialysisFinish.ID == 0 {
  6160. service.CreateDialysisFinish(finish)
  6161. }
  6162. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  6163. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  6164. for _, item := range advices {
  6165. byterequest, _ := json.Marshal(item)
  6166. adviceLog := models.XtDoctorAdviceLog{
  6167. UserOrgId: adminUserInfo.Org.Id,
  6168. PatientId: patient,
  6169. AdminUserId: adminUserInfo.AdminUser.Id,
  6170. Module: 1,
  6171. ErrLog: string(byterequest),
  6172. Status: 1,
  6173. Ctime: time.Now().Unix(),
  6174. Mtime: 0,
  6175. Source: "手机端医嘱推送",
  6176. RecordDate: item.AdviceDate,
  6177. }
  6178. service.CreateDoctorAdviceLog(adviceLog)
  6179. }
  6180. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6181. redis := service.RedisClient()
  6182. //清空key 值
  6183. redis.Set(key, "", time.Second)
  6184. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6185. redis.Set(keyOne, "", time.Second)
  6186. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6187. defer redis.Close()
  6188. redis.Set(keyThree, "", time.Second)
  6189. if err != nil {
  6190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6191. return
  6192. }
  6193. c.ServeSuccessJSON(map[string]interface{}{
  6194. "msg": "ok",
  6195. "advices": list,
  6196. })
  6197. } else {
  6198. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6199. for _, item := range advices {
  6200. byterequest, _ := json.Marshal(item)
  6201. adviceLog := models.XtDoctorAdviceLog{
  6202. UserOrgId: adminUserInfo.Org.Id,
  6203. PatientId: patient,
  6204. AdminUserId: adminUserInfo.AdminUser.Id,
  6205. Module: 1,
  6206. ErrLog: string(byterequest),
  6207. Status: 1,
  6208. Ctime: time.Now().Unix(),
  6209. Mtime: 0,
  6210. Source: "手机端医嘱推送",
  6211. RecordDate: item.AdviceDate,
  6212. }
  6213. service.CreateDoctorAdviceLog(adviceLog)
  6214. }
  6215. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6216. redis := service.RedisClient()
  6217. //清空key 值
  6218. redis.Set(key, "", time.Second)
  6219. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6220. redis.Set(keyOne, "", time.Second)
  6221. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6222. defer redis.Close()
  6223. redis.Set(keyThree, "", time.Second)
  6224. if err != nil {
  6225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6226. return
  6227. }
  6228. c.ServeSuccessJSON(map[string]interface{}{
  6229. "msg": "ok",
  6230. "advices": list,
  6231. })
  6232. }
  6233. } else {
  6234. c.ServeSuccessJSON(map[string]interface{}{
  6235. "msg": "ok",
  6236. })
  6237. }
  6238. return
  6239. }
  6240. func (c *DialysisAPIController) UploadDryWeight() {
  6241. patient_id, _ := c.GetInt64("id")
  6242. dry_weight, _ := c.GetFloat("dry_weight")
  6243. doctor_id, _ := c.GetInt64("doctor_id")
  6244. remark := c.GetString("remark")
  6245. adminUserInfo := c.GetMobileAdminUserInfo()
  6246. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6247. if err == gorm.ErrRecordNotFound {
  6248. dryWeight := &models.SgjPatientDryweight{
  6249. PatientId: patient_id,
  6250. DryWeight: dry_weight,
  6251. Remakes: remark,
  6252. Ctime: time.Now().Unix(),
  6253. Mtime: time.Now().Unix(),
  6254. Creator: doctor_id,
  6255. Status: 1,
  6256. UserOrgId: adminUserInfo.Org.Id,
  6257. AdjustedValue: "/",
  6258. UserId: adminUserInfo.AdminUser.Id,
  6259. }
  6260. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6261. redis := service.RedisClient()
  6262. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6263. redis.Set(keyOne, "", time.Second)
  6264. loc, _ := time.LoadLocation("Local")
  6265. nowTime := time.Now()
  6266. nowDay := nowTime.Format("2006-01-02")
  6267. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6268. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6269. redis.Set(key, "", time.Second)
  6270. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6271. redis.Set(keyTwo, "", time.Second)
  6272. redis.Close()
  6273. if createErr == nil {
  6274. c.ServeSuccessJSON(map[string]interface{}{
  6275. "msg": "提交成功",
  6276. "weight": dryWeight,
  6277. })
  6278. }
  6279. } else {
  6280. dryWeight := &models.SgjPatientDryweight{
  6281. PatientId: patient_id,
  6282. DryWeight: dry_weight,
  6283. Remakes: remark,
  6284. Ctime: time.Now().Unix(),
  6285. Mtime: time.Now().Unix(),
  6286. Creator: doctor_id,
  6287. Status: 1,
  6288. UserOrgId: adminUserInfo.Org.Id,
  6289. AdjustedValue: "/",
  6290. UserId: adminUserInfo.AdminUser.Id,
  6291. }
  6292. var value float64
  6293. value = dry_weight - weightAdjust.DryWeight
  6294. if value < 0 {
  6295. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6296. } else if value == 0 {
  6297. dryWeight.AdjustedValue = "/"
  6298. } else if value > 0 {
  6299. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6300. }
  6301. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6302. //康桥
  6303. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6304. timeNowStr := time.Now().Format("2006-01-02")
  6305. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6306. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6307. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6308. if beforAssesment.ID > 0 {
  6309. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6310. var dewater_amount float64
  6311. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6312. if adminUserInfo.Org.Id != 10702 {
  6313. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6314. }
  6315. if adminUserInfo.Org.Id == 10702 {
  6316. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6317. }
  6318. //获取key,清空redis
  6319. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6320. redis := service.RedisClient()
  6321. //清空key 值
  6322. redis.Set(key, "", time.Second)
  6323. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6324. //清空key 值
  6325. redis.Set(keyOne, "", time.Second)
  6326. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6327. //清空key 值
  6328. redis.Set(keyTwo, "", time.Second)
  6329. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6330. redis.Set(keySix, "", time.Second)
  6331. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6332. redis.Set(keySeven, "", time.Second)
  6333. }
  6334. }
  6335. redis := service.RedisClient()
  6336. loc, _ := time.LoadLocation("Local")
  6337. nowTime := time.Now()
  6338. nowDay := nowTime.Format("2006-01-02")
  6339. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6340. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6341. redis.Set(keyOne, "", time.Second)
  6342. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6343. redis.Set(key, "", time.Second)
  6344. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6345. redis.Set(keyTwo, "", time.Second)
  6346. redis.Close()
  6347. if createErr == nil {
  6348. c.ServeSuccessJSON(map[string]interface{}{
  6349. "msg": "提交成功",
  6350. "weight": dryWeight,
  6351. })
  6352. }
  6353. }
  6354. }
  6355. func (c *DialysisAPIController) GetSolution() {
  6356. patient_id, _ := c.GetInt64("patient_id")
  6357. mode_id, _ := c.GetInt64("mode_id")
  6358. adminUserInfo := c.GetMobileAdminUserInfo()
  6359. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6360. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6361. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6362. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6363. if err != nil {
  6364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6365. return
  6366. }
  6367. c.ServeSuccessJSON(map[string]interface{}{
  6368. "solution": solution,
  6369. "prescription": prescription,
  6370. "system_prescription": system_prescription,
  6371. "dialysisPrescription": dialysisPrescription,
  6372. })
  6373. }
  6374. func (c *DialysisAPIController) GetSchedule() {
  6375. schedual_type, _ := c.GetInt64("schedual_type")
  6376. adminUserInfo := c.GetMobileAdminUserInfo()
  6377. scheduleTime, _ := c.GetInt64("record_date")
  6378. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6379. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6380. c.ServeSuccessJSON(map[string]interface{}{
  6381. "number": deviceNumber,
  6382. "list": list,
  6383. })
  6384. }
  6385. func (c *DialysisAPIController) GetPatientId() {
  6386. id, _ := c.GetInt64("id")
  6387. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6388. patientId, _ := service.GetPatientId(id)
  6389. //获取该患者的所有传染病
  6390. list, _ := service.GetPatientInfectious(id)
  6391. c.ServeSuccessJSON(map[string]interface{}{
  6392. "patient": patientId,
  6393. "infectioulist": list,
  6394. })
  6395. }
  6396. func (this *DialysisAPIController) GetDialysisSchedule() {
  6397. schedualDate := this.GetString("date")
  6398. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6399. if parseDateErr != nil {
  6400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6401. return
  6402. }
  6403. adminInfo := this.GetMobileAdminUserInfo()
  6404. orgID := adminInfo.Org.Id
  6405. redis := service.RedisClient()
  6406. defer redis.Close()
  6407. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6408. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6409. if len(scheduals) > 0 {
  6410. //缓存数据
  6411. scheduals_json, err := json.Marshal(scheduals)
  6412. if err == nil {
  6413. redis.Set(key, scheduals_json, time.Second*30)
  6414. }
  6415. }
  6416. this.ServeSuccessJSON(map[string]interface{}{
  6417. "scheduals": scheduals,
  6418. })
  6419. }
  6420. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6421. change_type, _ := this.GetInt64("type", 0)
  6422. record_date := this.GetString("record_time")
  6423. patient_id, _ := this.GetInt64("patient_id", 0)
  6424. timeLayout := "2006-01-02"
  6425. loc, _ := time.LoadLocation("Local")
  6426. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6427. record_time := theAdviceRecordTime.Unix()
  6428. adminUserInfo := this.GetMobileAdminUserInfo()
  6429. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6430. if err == nil {
  6431. if len(advices) == 0 {
  6432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6433. return
  6434. } else {
  6435. this.ServeSuccessJSON(map[string]interface{}{
  6436. "advices": advices,
  6437. "schedule": sch,
  6438. })
  6439. return
  6440. }
  6441. } else {
  6442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6443. return
  6444. }
  6445. }
  6446. func (c *DialysisAPIController) CreateConsumables() {
  6447. record_date := c.GetString("record_time")
  6448. patient_id, _ := c.GetInt64("patient_id", 0)
  6449. active, _ := c.GetInt64("active")
  6450. adminUser := c.GetMobileAdminUserInfo()
  6451. timeLayout := "2006-01-02"
  6452. loc, _ := time.LoadLocation("Local")
  6453. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6454. record_time := theRecordTime.Unix()
  6455. // 查询信息规挡的设置天数
  6456. orgid := c.GetMobileAdminUserInfo().Org.Id
  6457. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6458. if infor.ID > 0 {
  6459. var cha_time int64
  6460. timeNowStr := time.Now().Format("2006-01-02")
  6461. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6462. //今日的日期减去设置的日期
  6463. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6464. if cha_time >= record_time {
  6465. //查询审核是否允许
  6466. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6467. //申请状态不允许的情况 拒绝修改
  6468. if infor.ApplicationStatus != 1 {
  6469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6470. return
  6471. }
  6472. }
  6473. }
  6474. dataBody := make(map[string]interface{}, 0)
  6475. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6476. if err != nil {
  6477. utils.ErrorLog(err.Error())
  6478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6479. return
  6480. }
  6481. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6482. var beforePrepares []*models.DialysisBeforePrepareGoods
  6483. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6484. var dialysisBefor []*models.DialysisBeforePrepare
  6485. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6486. goods, _ := dataBody["goods"].([]interface{})
  6487. if len(goods) > 0 {
  6488. for _, item := range goods {
  6489. items := item.(map[string]interface{})
  6490. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6491. utils.ErrorLog("good_id")
  6492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6493. return
  6494. }
  6495. good_id := int64(items["good_id"].(float64))
  6496. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6497. utils.ErrorLog("good_type_id")
  6498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6499. return
  6500. }
  6501. good_type_id := int64(items["good_type_id"].(float64))
  6502. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6503. utils.ErrorLog("count")
  6504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6505. return
  6506. }
  6507. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6508. commdity_code := items["commdity_code"].(string)
  6509. fmt.Println("commdity", commdity_code)
  6510. prepareGoods := &models.DialysisBeforePrepareGoods{
  6511. GoodTypeId: good_type_id,
  6512. GoodId: good_id,
  6513. Count: count,
  6514. StorehouseId: houseConfig.StorehouseOutInfo,
  6515. }
  6516. beforePrepares = append(beforePrepares, prepareGoods)
  6517. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6518. GoodTypeId: good_type_id,
  6519. GoodId: good_id,
  6520. Count: count,
  6521. StorehouseId: houseConfig.StorehouseOutInfo,
  6522. }
  6523. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6524. prepare := &models.DialysisBeforePrepare{
  6525. GoodTypeId: good_type_id,
  6526. GoodId: good_id,
  6527. Count: count,
  6528. PatientId: patient_id,
  6529. RecordDate: record_time,
  6530. UserOrgId: adminUser.Org.Id,
  6531. Status: 1,
  6532. Ctime: time.Now().Unix(),
  6533. Creater: adminUser.AdminUser.Id,
  6534. CommdityCode: commdity_code,
  6535. StorehouseId: houseConfig.StorehouseOutInfo,
  6536. }
  6537. dialysisBefor = append(dialysisBefor, prepare)
  6538. }
  6539. }
  6540. //查询是否有库存
  6541. for _, item := range dialysisBefor {
  6542. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6543. if err == gorm.ErrRecordNotFound {
  6544. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6545. c.ServeSuccessJSON(map[string]interface{}{
  6546. "message": "1",
  6547. "good_name": goodObj.GoodName,
  6548. "specification_name": goodObj.SpecificationName,
  6549. })
  6550. return
  6551. }
  6552. if err != nil {
  6553. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6554. c.ServeSuccessJSON(map[string]interface{}{
  6555. "message": "1",
  6556. "good_name": goodObj.GoodName,
  6557. "specification_name": goodObj.SpecificationName,
  6558. })
  6559. return
  6560. }
  6561. }
  6562. fmt.Println("active-----------------------", active)
  6563. fmt.Println("len(goods)-----------------------", len(goods))
  6564. //新增
  6565. if active == 1 && len(goods) > 0 {
  6566. for _, item := range dialysisBefor {
  6567. dialyPrepareOne := models.DialysisBeforePrepare{
  6568. GoodTypeId: item.GoodTypeId,
  6569. GoodId: item.GoodId,
  6570. PatientId: item.PatientId,
  6571. RecordDate: item.RecordDate,
  6572. UserOrgId: item.UserOrgId,
  6573. Count: item.Count,
  6574. Ctime: time.Now().Unix(),
  6575. Creater: item.Creater,
  6576. CommdityCode: item.CommdityCode,
  6577. Status: 1,
  6578. StorehouseId: houseConfig.StorehouseOutInfo,
  6579. }
  6580. //先清除再插入
  6581. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6582. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6583. //查询默认仓库
  6584. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6585. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6586. var total_count int64
  6587. for _, it := range stockList {
  6588. total_count += it.StockCount
  6589. }
  6590. //基础库插入数据
  6591. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6592. //更新库存
  6593. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6594. var flush_count int64
  6595. for _, it := range goodList {
  6596. flush_count += it.StockCount
  6597. }
  6598. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6599. }
  6600. if err == nil {
  6601. c.ServeSuccessJSON(map[string]interface{}{
  6602. "msg": "保存成功",
  6603. "message": "2",
  6604. })
  6605. return
  6606. } else {
  6607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6608. return
  6609. }
  6610. }
  6611. if len(beforePrepares) > 0 && active == 2 {
  6612. for _, item := range beforePrepares {
  6613. //1.查看该患者该耗材型号最后一次出库数量
  6614. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6615. //判断当前出库数量和最后一次出库数量的大小
  6616. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6617. if item.Count <= goodInfo.Count {
  6618. //退库
  6619. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6620. //查询今日出库数据
  6621. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6622. for _, it := range list {
  6623. prepare := models.DialysisBeforePrepare{
  6624. UserOrgId: it.OrgId,
  6625. PatientId: patient_id,
  6626. RecordDate: it.RecordTime,
  6627. GoodId: it.GoodId,
  6628. GoodTypeId: it.GoodTypeId,
  6629. Count: it.Count,
  6630. Ctime: time.Now().Unix(),
  6631. Creater: adminUser.AdminUser.Id,
  6632. Status: 1,
  6633. StorehouseId: houseConfig.StorehouseOutInfo,
  6634. }
  6635. //删除准备表数据
  6636. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6637. service.CreateDialysisBeforePrepareOne(&prepare)
  6638. }
  6639. }
  6640. var last_total int64
  6641. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6642. if item.Count >= goodInfo.Count {
  6643. //查询当前批次当前耗材最后一条出库数据
  6644. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6645. //计算当前出库和最后一次出库数据相差数据
  6646. last_total = item.Count - lastOutInfo.Count
  6647. //查询该批次剩余库存
  6648. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6649. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6650. if lastInfo.StockCount >= last_total {
  6651. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6652. //查询今日出库数据
  6653. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6654. for _, it := range list {
  6655. prepare := models.DialysisBeforePrepare{
  6656. UserOrgId: it.OrgId,
  6657. PatientId: patient_id,
  6658. RecordDate: it.RecordTime,
  6659. GoodId: it.GoodId,
  6660. GoodTypeId: it.GoodTypeId,
  6661. Count: it.Count,
  6662. Ctime: time.Now().Unix(),
  6663. Creater: adminUser.AdminUser.Id,
  6664. Status: 1,
  6665. StorehouseId: houseConfig.StorehouseOutInfo,
  6666. }
  6667. //删除准备表数据
  6668. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6669. service.CreateDialysisBeforePrepareOne(&prepare)
  6670. //查询默认仓库
  6671. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6672. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6673. var total_count int64
  6674. for _, it := range stockList {
  6675. total_count += it.StockCount
  6676. }
  6677. //基础库插入数据
  6678. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6679. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6680. var flush_count int64
  6681. for _, it := range goodList {
  6682. flush_count += it.StockCount
  6683. }
  6684. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6685. }
  6686. }
  6687. //如果库存不够,则出库到下一个批次
  6688. if lastInfo.StockCount < last_total {
  6689. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6690. //查询今日出库数据
  6691. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6692. for _, it := range list {
  6693. prepare := models.DialysisBeforePrepare{
  6694. UserOrgId: it.OrgId,
  6695. PatientId: patient_id,
  6696. RecordDate: it.RecordTime,
  6697. GoodId: it.GoodId,
  6698. GoodTypeId: it.GoodTypeId,
  6699. Count: it.Count,
  6700. Ctime: time.Now().Unix(),
  6701. Creater: adminUser.AdminUser.Id,
  6702. Status: 1,
  6703. StorehouseId: houseConfig.StorehouseOutInfo,
  6704. }
  6705. //删除准备表数据
  6706. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6707. service.CreateDialysisBeforePrepareOne(&prepare)
  6708. //查询默认仓库
  6709. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6710. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6711. var total_count int64
  6712. for _, it := range stockList {
  6713. total_count += it.StockCount
  6714. }
  6715. //基础库插入数据
  6716. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6717. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6718. var flush_count int64
  6719. for _, it := range goodList {
  6720. flush_count += it.StockCount
  6721. }
  6722. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6723. }
  6724. if err != nil {
  6725. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6726. c.ServeSuccessJSON(map[string]interface{}{
  6727. "message": "1",
  6728. "good_name": goodObj.GoodName,
  6729. "specification_name": goodObj.SpecificationName,
  6730. })
  6731. return
  6732. }
  6733. }
  6734. }
  6735. if err != nil {
  6736. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6737. c.ServeSuccessJSON(map[string]interface{}{
  6738. "message": "1",
  6739. "good_name": goodObj.GoodName,
  6740. "specification_name": goodObj.SpecificationName,
  6741. })
  6742. return
  6743. }
  6744. }
  6745. }
  6746. }
  6747. var errs error
  6748. if errs == nil {
  6749. c.ServeSuccessJSON(map[string]interface{}{
  6750. "msg": "提交成功",
  6751. "message": "2",
  6752. "good_name": "",
  6753. "specification_name": "",
  6754. })
  6755. return
  6756. } else {
  6757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6758. return
  6759. }
  6760. }
  6761. func (c *DialysisAPIController) CreateStockOutInfo() {
  6762. patient_id, _ := c.GetInt64("patient_id", 0)
  6763. record_date := c.GetString("record_time")
  6764. if patient_id <= 0 {
  6765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6766. return
  6767. }
  6768. adminInfo := c.GetMobileAdminUserInfo()
  6769. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6770. timeLayout := "2006-01-02"
  6771. loc, _ := time.LoadLocation("Local")
  6772. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6773. record_time := theRecordTime.Unix()
  6774. // 查询信息规挡的设置天数
  6775. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6776. if infor.ID > 0 && infor.WeekDay > 0 {
  6777. var cha_time int64
  6778. timeNowStr := time.Now().Format("2006-01-02")
  6779. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6780. //今日的日期减去设置的日期
  6781. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6782. if cha_time >= record_time {
  6783. //查询审核是否允许
  6784. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6785. //申请状态不允许的情况 拒绝修改
  6786. if infor.ApplicationStatus != 1 {
  6787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6788. return
  6789. }
  6790. }
  6791. }
  6792. //创建步骤表
  6793. finish := models.XtDialysisFinish{
  6794. IsFinish: 1,
  6795. UserOrgId: adminInfo.Org.Id,
  6796. Status: 1,
  6797. Ctime: time.Now().Unix(),
  6798. Mtime: 0,
  6799. Module: 11,
  6800. RecordDate: record_time,
  6801. Sourse: 1,
  6802. PatientId: patient_id,
  6803. }
  6804. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6805. if dialysisFinish.ID == 0 {
  6806. service.CreateDialysisFinish(finish)
  6807. }
  6808. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6809. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6810. //去重
  6811. consumables = RemoveRepeatedGood(consumables)
  6812. if adminInfo.Org.Id == 9919 {
  6813. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6814. //查询是否有库存
  6815. for _, item := range consumables {
  6816. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6817. if item.Count > warehouse.Count {
  6818. goodErrcode := models.XtGoodErrcode{
  6819. UserOrgId: item.UserOrgId,
  6820. Errcode: "自动出库库存不足",
  6821. GoodId: item.GoodId,
  6822. Status: 1,
  6823. Ctime: time.Now().Unix(),
  6824. Mtime: 0,
  6825. Count: 0,
  6826. StockCount: 0,
  6827. Creater: creator,
  6828. BatchNumberId: warehouse.ID,
  6829. WarehouseOutId: 0,
  6830. }
  6831. service.CreateGoodErrcode(goodErrcode)
  6832. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6833. c.ServeSuccessJSON(map[string]interface{}{
  6834. "message": "1",
  6835. "good_name": goodObj.GoodName,
  6836. "specification_name": goodObj.SpecificationName,
  6837. })
  6838. return
  6839. }
  6840. }
  6841. //查询是否有出库单
  6842. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6843. if err == gorm.ErrRecordNotFound {
  6844. //没有记录,则创建出库单
  6845. timeStr := time.Now().Format("2006-01-02")
  6846. timeArr := strings.Split(timeStr, "-")
  6847. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6848. total = total + 1
  6849. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6850. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6851. number = number + total
  6852. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6853. creater := adminInfo.AdminUser.Id
  6854. warehouseOut := models.WarehouseOut{
  6855. WarehouseOutOrderNumber: warehousing_out_order,
  6856. OperationTime: time.Now().Unix(),
  6857. OrgId: adminInfo.Org.Id,
  6858. Creater: creater,
  6859. Ctime: time.Now().Unix(),
  6860. Status: 1,
  6861. WarehouseOutTime: record_time,
  6862. Dealer: 0,
  6863. Manufacturer: 0,
  6864. Type: 1,
  6865. IsSys: 1,
  6866. StorehouseId: houseConfig.StorehouseOutInfo,
  6867. IsCheck: 1,
  6868. }
  6869. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6870. if err != nil {
  6871. goodErrcode := models.XtGoodErrcode{
  6872. UserOrgId: adminInfo.Org.Id,
  6873. Errcode: "创建出库单失败",
  6874. GoodId: 0,
  6875. Status: 1,
  6876. Ctime: time.Now().Unix(),
  6877. Mtime: 0,
  6878. Count: 0,
  6879. StockCount: 0,
  6880. Creater: creator,
  6881. BatchNumberId: 0,
  6882. WarehouseOutId: 0,
  6883. }
  6884. service.CreateGoodErrcode(goodErrcode)
  6885. utils.TraceLog("创建出库单失败 err = %v", err)
  6886. } else {
  6887. for _, item := range consumables {
  6888. //出库
  6889. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6890. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6891. if err == nil {
  6892. goodErrcode := models.XtGoodErrcode{
  6893. UserOrgId: adminInfo.Org.Id,
  6894. Errcode: "自动出库接口报错",
  6895. GoodId: 0,
  6896. Status: 1,
  6897. Ctime: time.Now().Unix(),
  6898. Mtime: 0,
  6899. Count: 0,
  6900. StockCount: 0,
  6901. Creater: creator,
  6902. BatchNumberId: 0,
  6903. WarehouseOutId: 0,
  6904. }
  6905. service.CreateGoodErrcode(goodErrcode)
  6906. utils.TraceLog("创建出库单失败 err = %v", err)
  6907. }
  6908. //查询
  6909. //出库数量相加
  6910. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6911. if errs != nil {
  6912. goodErrcode := models.XtGoodErrcode{
  6913. UserOrgId: item.UserOrgId,
  6914. Errcode: "创建剩余库存字段报错",
  6915. GoodId: item.GoodId,
  6916. Status: 1,
  6917. Ctime: time.Now().Unix(),
  6918. Mtime: 0,
  6919. Count: 0,
  6920. StockCount: 0,
  6921. Creater: creater,
  6922. BatchNumberId: 0,
  6923. WarehouseOutId: 0,
  6924. }
  6925. service.CreateGoodErrcode(goodErrcode)
  6926. }
  6927. }
  6928. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6929. if len(list) == 0 {
  6930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6931. return
  6932. }
  6933. for _, item := range list {
  6934. prepare := models.DialysisBeforePrepare{
  6935. UserOrgId: adminInfo.Org.Id,
  6936. PatientId: patient_id,
  6937. RecordDate: record_time,
  6938. GoodId: item.GoodId,
  6939. GoodTypeId: item.GoodTypeId,
  6940. Count: item.Count,
  6941. Creater: adminInfo.AdminUser.Id,
  6942. Status: 1,
  6943. Ctime: time.Now().Unix(),
  6944. StorehouseId: houseConfig.StorehouseOutInfo,
  6945. }
  6946. //清空准备表数据
  6947. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6948. if err != nil {
  6949. goodErrcode := models.XtGoodErrcode{
  6950. UserOrgId: item.OrgId,
  6951. Errcode: "自动出库清空准备表数据报错",
  6952. GoodId: item.GoodId,
  6953. Status: 1,
  6954. Ctime: time.Now().Unix(),
  6955. Mtime: 0,
  6956. Count: 0,
  6957. StockCount: 0,
  6958. Creater: creater,
  6959. BatchNumberId: 0,
  6960. WarehouseOutId: 0,
  6961. }
  6962. service.CreateGoodErrcode(goodErrcode)
  6963. }
  6964. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6965. if errs != nil {
  6966. goodErrcode := models.XtGoodErrcode{
  6967. UserOrgId: item.OrgId,
  6968. Errcode: "自动出库创建准备表数据报错",
  6969. GoodId: item.GoodId,
  6970. Status: 1,
  6971. Ctime: time.Now().Unix(),
  6972. Mtime: 0,
  6973. Count: 0,
  6974. StockCount: 0,
  6975. Creater: creater,
  6976. BatchNumberId: 0,
  6977. WarehouseOutId: 0,
  6978. }
  6979. service.CreateGoodErrcode(goodErrcode)
  6980. }
  6981. //查询默认仓库
  6982. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6983. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6984. var total_count int64
  6985. for _, it := range stockList {
  6986. total_count += it.StockCount
  6987. }
  6988. //基础库插入数据
  6989. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6990. if errcodes != nil {
  6991. goodErrcode := models.XtGoodErrcode{
  6992. UserOrgId: item.OrgId,
  6993. Errcode: "自动出库基础库插入数据",
  6994. GoodId: item.GoodId,
  6995. Status: 1,
  6996. Ctime: time.Now().Unix(),
  6997. Mtime: 0,
  6998. Count: 0,
  6999. StockCount: 0,
  7000. Creater: creater,
  7001. BatchNumberId: 0,
  7002. WarehouseOutId: 0,
  7003. }
  7004. service.CreateGoodErrcode(goodErrcode)
  7005. }
  7006. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7007. var flush_count int64
  7008. for _, it := range goodList {
  7009. flush_count += it.StockCount
  7010. }
  7011. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7012. if errsss != nil {
  7013. goodErrcode := models.XtGoodErrcode{
  7014. UserOrgId: item.OrgId,
  7015. Errcode: "自动出库剩余库存更新数据",
  7016. GoodId: item.GoodId,
  7017. Status: 1,
  7018. Ctime: time.Now().Unix(),
  7019. Mtime: 0,
  7020. Count: 0,
  7021. StockCount: 0,
  7022. Creater: creater,
  7023. BatchNumberId: 0,
  7024. WarehouseOutId: 0,
  7025. }
  7026. service.CreateGoodErrcode(goodErrcode)
  7027. }
  7028. }
  7029. }
  7030. //
  7031. } else if err == nil {
  7032. for _, item := range consumables {
  7033. //出库
  7034. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7035. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7036. if err != nil {
  7037. goodErrcode := models.XtGoodErrcode{
  7038. UserOrgId: adminInfo.Org.Id,
  7039. Errcode: "自动出库接口报错",
  7040. GoodId: 0,
  7041. Status: 1,
  7042. Ctime: time.Now().Unix(),
  7043. Mtime: 0,
  7044. Count: 0,
  7045. StockCount: 0,
  7046. Creater: creator,
  7047. BatchNumberId: 0,
  7048. WarehouseOutId: 0,
  7049. }
  7050. service.CreateGoodErrcode(goodErrcode)
  7051. }
  7052. //出库数量相加
  7053. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7054. if errss != nil {
  7055. goodErrcode := models.XtGoodErrcode{
  7056. UserOrgId: item.UserOrgId,
  7057. Errcode: "创建剩余库存字段报错",
  7058. GoodId: item.GoodId,
  7059. Status: 1,
  7060. Ctime: time.Now().Unix(),
  7061. Mtime: time.Now().Unix(),
  7062. Count: 0,
  7063. StockCount: 0,
  7064. Creater: item.Creater,
  7065. BatchNumberId: 0,
  7066. WarehouseOutId: 0,
  7067. }
  7068. service.CreateGoodErrcode(goodErrcode)
  7069. }
  7070. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7071. if len(list) == 0 {
  7072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7073. return
  7074. }
  7075. for _, item := range list {
  7076. prepare := models.DialysisBeforePrepare{
  7077. UserOrgId: adminInfo.Org.Id,
  7078. PatientId: patient_id,
  7079. RecordDate: record_time,
  7080. GoodId: item.GoodId,
  7081. GoodTypeId: item.GoodTypeId,
  7082. Count: item.Count,
  7083. Creater: adminInfo.AdminUser.Id,
  7084. Status: 1,
  7085. Ctime: time.Now().Unix(),
  7086. StorehouseId: houseConfig.StorehouseOutInfo,
  7087. }
  7088. //清空准备表数据
  7089. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7090. if errs != nil {
  7091. goodErrcode := models.XtGoodErrcode{
  7092. UserOrgId: adminInfo.Org.Id,
  7093. Errcode: "自动出库清空准备表数据报错",
  7094. GoodId: 0,
  7095. Status: 1,
  7096. Ctime: time.Now().Unix(),
  7097. Mtime: 0,
  7098. Count: 0,
  7099. StockCount: 0,
  7100. Creater: creator,
  7101. BatchNumberId: 0,
  7102. WarehouseOutId: 0,
  7103. }
  7104. service.CreateGoodErrcode(goodErrcode)
  7105. }
  7106. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7107. if errcodes != nil {
  7108. goodErrcode := models.XtGoodErrcode{
  7109. UserOrgId: adminInfo.Org.Id,
  7110. Errcode: "自动出库创建准备表数据报错",
  7111. GoodId: 0,
  7112. Status: 1,
  7113. Ctime: time.Now().Unix(),
  7114. Mtime: 0,
  7115. Count: 0,
  7116. StockCount: 0,
  7117. Creater: creator,
  7118. BatchNumberId: 0,
  7119. WarehouseOutId: 0,
  7120. }
  7121. service.CreateGoodErrcode(goodErrcode)
  7122. }
  7123. //查询默认仓库
  7124. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7125. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7126. var total_count int64
  7127. for _, it := range stockList {
  7128. total_count += it.StockCount
  7129. }
  7130. //基础库插入数据
  7131. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7132. if errcodes != nil {
  7133. goodErrcode := models.XtGoodErrcode{
  7134. UserOrgId: adminInfo.Org.Id,
  7135. Errcode: "自动出库基础库插入数据报错",
  7136. GoodId: 0,
  7137. Status: 1,
  7138. Ctime: time.Now().Unix(),
  7139. Mtime: 0,
  7140. Count: 0,
  7141. StockCount: 0,
  7142. Creater: creator,
  7143. BatchNumberId: 0,
  7144. WarehouseOutId: 0,
  7145. }
  7146. service.CreateGoodErrcode(goodErrcode)
  7147. }
  7148. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7149. var flush_count int64
  7150. for _, it := range goodList {
  7151. flush_count += it.StockCount
  7152. }
  7153. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7154. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7155. if errss != nil {
  7156. goodErrcode := models.XtGoodErrcode{
  7157. UserOrgId: item.OrgId,
  7158. Errcode: "自动出库剩余库存更新数据",
  7159. GoodId: item.GoodId,
  7160. Status: 1,
  7161. Ctime: time.Now().Unix(),
  7162. Mtime: 0,
  7163. Count: 0,
  7164. StockCount: 0,
  7165. Creater: creater,
  7166. BatchNumberId: 0,
  7167. WarehouseOutId: 0,
  7168. }
  7169. service.CreateGoodErrcode(goodErrcode)
  7170. }
  7171. }
  7172. }
  7173. }
  7174. c.ServeSuccessJSON(map[string]interface{}{
  7175. "msg": "提交成功",
  7176. "message": "2",
  7177. "good_name": "",
  7178. "specification_name": "",
  7179. })
  7180. return
  7181. }
  7182. if record.IsOpen == 1 {
  7183. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7184. //查询是否有库存
  7185. for _, item := range consumables {
  7186. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7187. if item.Count > warehouse.Count {
  7188. goodErrcode := models.XtGoodErrcode{
  7189. UserOrgId: item.UserOrgId,
  7190. Errcode: "自动出库库存不足",
  7191. GoodId: item.GoodId,
  7192. Status: 1,
  7193. Ctime: time.Now().Unix(),
  7194. Mtime: 0,
  7195. Count: 0,
  7196. StockCount: 0,
  7197. Creater: creator,
  7198. BatchNumberId: warehouse.ID,
  7199. WarehouseOutId: 0,
  7200. }
  7201. service.CreateGoodErrcode(goodErrcode)
  7202. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "message": "1",
  7205. "good_name": goodObj.GoodName,
  7206. "specification_name": goodObj.SpecificationName,
  7207. })
  7208. return
  7209. }
  7210. }
  7211. //查询是否有出库单
  7212. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7213. if err == gorm.ErrRecordNotFound {
  7214. //没有记录,则创建出库单
  7215. timeStr := time.Now().Format("2006-01-02")
  7216. timeArr := strings.Split(timeStr, "-")
  7217. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7218. total = total + 1
  7219. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7220. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7221. number = number + total
  7222. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7223. creater := adminInfo.AdminUser.Id
  7224. warehouseOut := models.WarehouseOut{
  7225. WarehouseOutOrderNumber: warehousing_out_order,
  7226. OperationTime: time.Now().Unix(),
  7227. OrgId: adminInfo.Org.Id,
  7228. Creater: creater,
  7229. Ctime: time.Now().Unix(),
  7230. Status: 1,
  7231. WarehouseOutTime: record_time,
  7232. Dealer: 0,
  7233. Manufacturer: 0,
  7234. Type: 1,
  7235. IsSys: 1,
  7236. StorehouseId: houseConfig.StorehouseOutInfo,
  7237. IsCheck: 1,
  7238. }
  7239. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7240. if err != nil {
  7241. goodErrcode := models.XtGoodErrcode{
  7242. UserOrgId: adminInfo.Org.Id,
  7243. Errcode: "创建出库单失败",
  7244. GoodId: 0,
  7245. Status: 1,
  7246. Ctime: time.Now().Unix(),
  7247. Mtime: 0,
  7248. Count: 0,
  7249. StockCount: 0,
  7250. Creater: creator,
  7251. BatchNumberId: 0,
  7252. WarehouseOutId: 0,
  7253. }
  7254. service.CreateGoodErrcode(goodErrcode)
  7255. utils.TraceLog("创建出库单失败 err = %v", err)
  7256. } else {
  7257. for _, item := range consumables {
  7258. //出库
  7259. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7260. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7261. if err == nil {
  7262. goodErrcode := models.XtGoodErrcode{
  7263. UserOrgId: adminInfo.Org.Id,
  7264. Errcode: "自动出库接口报错",
  7265. GoodId: 0,
  7266. Status: 1,
  7267. Ctime: time.Now().Unix(),
  7268. Mtime: 0,
  7269. Count: 0,
  7270. StockCount: 0,
  7271. Creater: creator,
  7272. BatchNumberId: 0,
  7273. WarehouseOutId: 0,
  7274. }
  7275. service.CreateGoodErrcode(goodErrcode)
  7276. utils.TraceLog("创建出库单失败 err = %v", err)
  7277. }
  7278. //查询
  7279. //出库数量相加
  7280. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7281. if errs != nil {
  7282. goodErrcode := models.XtGoodErrcode{
  7283. UserOrgId: item.UserOrgId,
  7284. Errcode: "创建剩余库存字段报错",
  7285. GoodId: item.GoodId,
  7286. Status: 1,
  7287. Ctime: time.Now().Unix(),
  7288. Mtime: 0,
  7289. Count: 0,
  7290. StockCount: 0,
  7291. Creater: creater,
  7292. BatchNumberId: 0,
  7293. WarehouseOutId: 0,
  7294. }
  7295. service.CreateGoodErrcode(goodErrcode)
  7296. }
  7297. }
  7298. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7299. if len(list) == 0 {
  7300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7301. return
  7302. }
  7303. for _, item := range list {
  7304. prepare := models.DialysisBeforePrepare{
  7305. UserOrgId: adminInfo.Org.Id,
  7306. PatientId: patient_id,
  7307. RecordDate: record_time,
  7308. GoodId: item.GoodId,
  7309. GoodTypeId: item.GoodTypeId,
  7310. Count: item.Count,
  7311. Creater: adminInfo.AdminUser.Id,
  7312. Status: 1,
  7313. Ctime: time.Now().Unix(),
  7314. StorehouseId: houseConfig.StorehouseOutInfo,
  7315. }
  7316. //清空准备表数据
  7317. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7318. if err != nil {
  7319. goodErrcode := models.XtGoodErrcode{
  7320. UserOrgId: item.OrgId,
  7321. Errcode: "自动出库清空准备表数据报错",
  7322. GoodId: item.GoodId,
  7323. Status: 1,
  7324. Ctime: time.Now().Unix(),
  7325. Mtime: 0,
  7326. Count: 0,
  7327. StockCount: 0,
  7328. Creater: creater,
  7329. BatchNumberId: 0,
  7330. WarehouseOutId: 0,
  7331. }
  7332. service.CreateGoodErrcode(goodErrcode)
  7333. }
  7334. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7335. if errs != nil {
  7336. goodErrcode := models.XtGoodErrcode{
  7337. UserOrgId: item.OrgId,
  7338. Errcode: "自动出库创建准备表数据报错",
  7339. GoodId: item.GoodId,
  7340. Status: 1,
  7341. Ctime: time.Now().Unix(),
  7342. Mtime: 0,
  7343. Count: 0,
  7344. StockCount: 0,
  7345. Creater: creater,
  7346. BatchNumberId: 0,
  7347. WarehouseOutId: 0,
  7348. }
  7349. service.CreateGoodErrcode(goodErrcode)
  7350. }
  7351. //查询默认仓库
  7352. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7353. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7354. var total_count int64
  7355. for _, it := range stockList {
  7356. total_count += it.StockCount
  7357. }
  7358. //基础库插入数据
  7359. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7360. if errcodes != nil {
  7361. goodErrcode := models.XtGoodErrcode{
  7362. UserOrgId: item.OrgId,
  7363. Errcode: "自动出库基础库插入数据",
  7364. GoodId: item.GoodId,
  7365. Status: 1,
  7366. Ctime: time.Now().Unix(),
  7367. Mtime: 0,
  7368. Count: 0,
  7369. StockCount: 0,
  7370. Creater: creater,
  7371. BatchNumberId: 0,
  7372. WarehouseOutId: 0,
  7373. }
  7374. service.CreateGoodErrcode(goodErrcode)
  7375. }
  7376. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7377. var flush_count int64
  7378. for _, it := range goodList {
  7379. flush_count += it.StockCount
  7380. }
  7381. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7382. if errsss != nil {
  7383. goodErrcode := models.XtGoodErrcode{
  7384. UserOrgId: item.OrgId,
  7385. Errcode: "自动出库剩余库存更新数据",
  7386. GoodId: item.GoodId,
  7387. Status: 1,
  7388. Ctime: time.Now().Unix(),
  7389. Mtime: 0,
  7390. Count: 0,
  7391. StockCount: 0,
  7392. Creater: creater,
  7393. BatchNumberId: 0,
  7394. WarehouseOutId: 0,
  7395. }
  7396. service.CreateGoodErrcode(goodErrcode)
  7397. }
  7398. }
  7399. }
  7400. //
  7401. } else if err == nil {
  7402. for _, item := range consumables {
  7403. //出库
  7404. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7405. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7406. if err != nil {
  7407. goodErrcode := models.XtGoodErrcode{
  7408. UserOrgId: adminInfo.Org.Id,
  7409. Errcode: "自动出库接口报错",
  7410. GoodId: 0,
  7411. Status: 1,
  7412. Ctime: time.Now().Unix(),
  7413. Mtime: 0,
  7414. Count: 0,
  7415. StockCount: 0,
  7416. Creater: creator,
  7417. BatchNumberId: 0,
  7418. WarehouseOutId: 0,
  7419. }
  7420. service.CreateGoodErrcode(goodErrcode)
  7421. }
  7422. //出库数量相加
  7423. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7424. if errss != nil {
  7425. goodErrcode := models.XtGoodErrcode{
  7426. UserOrgId: item.UserOrgId,
  7427. Errcode: "创建剩余库存字段报错",
  7428. GoodId: item.GoodId,
  7429. Status: 1,
  7430. Ctime: time.Now().Unix(),
  7431. Mtime: time.Now().Unix(),
  7432. Count: 0,
  7433. StockCount: 0,
  7434. Creater: item.Creater,
  7435. BatchNumberId: 0,
  7436. WarehouseOutId: 0,
  7437. }
  7438. service.CreateGoodErrcode(goodErrcode)
  7439. }
  7440. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7441. if len(list) == 0 {
  7442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7443. return
  7444. }
  7445. for _, item := range list {
  7446. prepare := models.DialysisBeforePrepare{
  7447. UserOrgId: adminInfo.Org.Id,
  7448. PatientId: patient_id,
  7449. RecordDate: record_time,
  7450. GoodId: item.GoodId,
  7451. GoodTypeId: item.GoodTypeId,
  7452. Count: item.Count,
  7453. Creater: adminInfo.AdminUser.Id,
  7454. Status: 1,
  7455. Ctime: time.Now().Unix(),
  7456. StorehouseId: houseConfig.StorehouseOutInfo,
  7457. }
  7458. //清空准备表数据
  7459. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7460. if errs != nil {
  7461. goodErrcode := models.XtGoodErrcode{
  7462. UserOrgId: adminInfo.Org.Id,
  7463. Errcode: "自动出库清空准备表数据报错",
  7464. GoodId: 0,
  7465. Status: 1,
  7466. Ctime: time.Now().Unix(),
  7467. Mtime: 0,
  7468. Count: 0,
  7469. StockCount: 0,
  7470. Creater: creator,
  7471. BatchNumberId: 0,
  7472. WarehouseOutId: 0,
  7473. }
  7474. service.CreateGoodErrcode(goodErrcode)
  7475. }
  7476. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7477. if errcodes != nil {
  7478. goodErrcode := models.XtGoodErrcode{
  7479. UserOrgId: adminInfo.Org.Id,
  7480. Errcode: "自动出库创建准备表数据报错",
  7481. GoodId: 0,
  7482. Status: 1,
  7483. Ctime: time.Now().Unix(),
  7484. Mtime: 0,
  7485. Count: 0,
  7486. StockCount: 0,
  7487. Creater: creator,
  7488. BatchNumberId: 0,
  7489. WarehouseOutId: 0,
  7490. }
  7491. service.CreateGoodErrcode(goodErrcode)
  7492. }
  7493. //查询默认仓库
  7494. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7495. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7496. var total_count int64
  7497. for _, it := range stockList {
  7498. total_count += it.StockCount
  7499. }
  7500. //基础库插入数据
  7501. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7502. if errcodes != nil {
  7503. goodErrcode := models.XtGoodErrcode{
  7504. UserOrgId: adminInfo.Org.Id,
  7505. Errcode: "自动出库基础库插入数据报错",
  7506. GoodId: 0,
  7507. Status: 1,
  7508. Ctime: time.Now().Unix(),
  7509. Mtime: 0,
  7510. Count: 0,
  7511. StockCount: 0,
  7512. Creater: creator,
  7513. BatchNumberId: 0,
  7514. WarehouseOutId: 0,
  7515. }
  7516. service.CreateGoodErrcode(goodErrcode)
  7517. }
  7518. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7519. var flush_count int64
  7520. for _, it := range goodList {
  7521. flush_count += it.StockCount
  7522. }
  7523. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7524. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7525. if errss != nil {
  7526. goodErrcode := models.XtGoodErrcode{
  7527. UserOrgId: item.OrgId,
  7528. Errcode: "自动出库剩余库存更新数据",
  7529. GoodId: item.GoodId,
  7530. Status: 1,
  7531. Ctime: time.Now().Unix(),
  7532. Mtime: 0,
  7533. Count: 0,
  7534. StockCount: 0,
  7535. Creater: creater,
  7536. BatchNumberId: 0,
  7537. WarehouseOutId: 0,
  7538. }
  7539. service.CreateGoodErrcode(goodErrcode)
  7540. }
  7541. }
  7542. }
  7543. }
  7544. c.ServeSuccessJSON(map[string]interface{}{
  7545. "msg": "提交成功",
  7546. "message": "2",
  7547. "good_name": "",
  7548. "specification_name": "",
  7549. })
  7550. return
  7551. } else {
  7552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7553. return
  7554. }
  7555. }
  7556. func (c *DialysisAPIController) EditConsumables() {
  7557. patient_id, _ := c.GetInt64("patient_id", 0)
  7558. record_date := c.GetString("record_time")
  7559. if patient_id <= 0 {
  7560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7561. return
  7562. }
  7563. adminInfo := c.GetMobileAdminUserInfo()
  7564. timeLayout := "2006-01-02"
  7565. loc, _ := time.LoadLocation("Local")
  7566. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7567. record_time := theRecordTime.Unix()
  7568. // 查询信息规挡的设置天数
  7569. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7570. if infor.ID > 0 && infor.WeekDay > 0 {
  7571. var cha_time int64
  7572. timeNowStr := time.Now().Format("2006-01-02")
  7573. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7574. //今日的日期减去设置的日期
  7575. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7576. if cha_time >= record_time {
  7577. //查询审核是否允许
  7578. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7579. //申请状态不允许的情况 拒绝修改
  7580. if infor.ApplicationStatus != 1 {
  7581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7582. return
  7583. }
  7584. }
  7585. }
  7586. dataBody := make(map[string]interface{}, 0)
  7587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7588. if err != nil {
  7589. utils.ErrorLog(err.Error())
  7590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7591. return
  7592. }
  7593. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7594. var beforePrepares []*models.DialysisBeforePrepareGoods
  7595. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7596. var cancelbefor []*models.DialysisBeforePrepareGoods
  7597. var outbefor []*models.DialysisBeforePrepareGoods
  7598. //判断是否开启自动出库
  7599. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7600. if record.IsOpen == 1 {
  7601. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7602. goods, _ := dataBody["goods"].([]interface{})
  7603. if len(goods) > 0 {
  7604. for _, item := range goods {
  7605. items := item.(map[string]interface{})
  7606. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7607. utils.ErrorLog("good_id")
  7608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7609. return
  7610. }
  7611. good_id := int64(items["good_id"].(float64))
  7612. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7613. utils.ErrorLog("good_type_id")
  7614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7615. return
  7616. }
  7617. good_type_id := int64(items["good_type_id"].(float64))
  7618. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7619. utils.ErrorLog("count")
  7620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7621. return
  7622. }
  7623. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7624. commdity_code := items["commdity_code"].(string)
  7625. fmt.Println(commdity_code)
  7626. prepareGoods := &models.DialysisBeforePrepareGoods{
  7627. GoodTypeId: good_type_id,
  7628. GoodId: good_id,
  7629. Count: count,
  7630. StorehouseId: houseConfig.StorehouseOutInfo,
  7631. }
  7632. beforePrepares = append(beforePrepares, prepareGoods)
  7633. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7634. GoodTypeId: good_type_id,
  7635. GoodId: good_id,
  7636. Count: count,
  7637. StorehouseId: houseConfig.StorehouseOutInfo,
  7638. }
  7639. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7640. }
  7641. for _, item := range beforePrepares {
  7642. //1.查看该患者该耗材型号最后一次出库数量
  7643. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7644. //判断当前出库数量和最后一次出库数量的大小
  7645. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7646. if item.Count < goodInfo.Count {
  7647. cancelbefor = append(cancelbefor, item)
  7648. }
  7649. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7650. if item.Count > goodInfo.Count {
  7651. outbefor = append(outbefor, item)
  7652. }
  7653. //处理编辑耗材新增不了的问题
  7654. if goodInfo.Count == item.Count {
  7655. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7656. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7657. }
  7658. }
  7659. if len(cancelbefor) > 0 {
  7660. //退库
  7661. for _, item := range cancelbefor {
  7662. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7663. creater := adminInfo.AdminUser.Id
  7664. //查询该患者当天已经出库的耗材信息
  7665. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7666. var delete_count int64 = 0
  7667. delete_count = warehouseOutInfos.Count - item.Count
  7668. //增加库存数量
  7669. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7670. //减少实际出库库存数量
  7671. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7672. // 删除出库完成后,要增加对应批次的库存数量
  7673. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7674. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7675. //更新剩余库存
  7676. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7677. var flush_count int64
  7678. for _, it := range goodListOne {
  7679. flush_count += it.StockCount
  7680. }
  7681. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7682. //查询剩余库存
  7683. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7684. var sum_count int64
  7685. for _, item := range goodList {
  7686. sum_count += item.StockCount
  7687. }
  7688. // 在出库记录表里记录退库详情
  7689. warehouseOutInfo := &models.WarehouseOutInfo{
  7690. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7691. WarehouseOutId: warehouseOut.ID,
  7692. Status: 1,
  7693. Ctime: time.Now().Unix(),
  7694. OrgId: adminInfo.Org.Id,
  7695. Type: 1,
  7696. IsSys: 1,
  7697. SysRecordTime: record_time,
  7698. GoodTypeId: item.GoodTypeId,
  7699. GoodId: item.GoodId,
  7700. PatientId: patient_id,
  7701. ConsumableType: 2,
  7702. StorehouseId: houseConfig.StorehouseOutInfo,
  7703. IsCheck: 1,
  7704. OverCount: sum_count,
  7705. }
  7706. warehouseOutInfo.Count = item.Count
  7707. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7708. warehouseOutInfo.Price = stockInInfo.Price
  7709. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7710. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7711. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7712. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7713. warehouseOutInfo.Number = warehouseOutInfos.Number
  7714. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7715. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7716. //查找当天是否存在出库记录
  7717. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7718. if errcod == gorm.ErrRecordNotFound {
  7719. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7720. //插入详情明细表
  7721. stockFlow := models.VmStockFlow{
  7722. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7723. WarehouseOutId: warehouseOut.ID,
  7724. GoodId: item.GoodId,
  7725. Number: warehouseOutInfos.Number,
  7726. ProductDate: stockInInfo.ProductDate,
  7727. ExpireDate: stockInInfo.ExpiryDate,
  7728. Count: item.Count,
  7729. Price: stockInInfo.Price,
  7730. Status: 1,
  7731. Ctime: record_time,
  7732. UserOrgId: adminInfo.Org.Id,
  7733. Manufacturer: stockInInfo.Manufacturer,
  7734. Dealer: stockInInfo.Dealer,
  7735. LicenseNumber: stockInInfo.LicenseNumber,
  7736. IsEdit: 2,
  7737. Creator: creater,
  7738. SystemTime: record_time,
  7739. ConsumableType: 3,
  7740. WarehousingDetailId: 0,
  7741. IsSys: 1,
  7742. UpdateCreator: creater,
  7743. PatientId: patient_id,
  7744. StorehouseId: houseConfig.StorehouseOutInfo,
  7745. }
  7746. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7747. if errflow == gorm.ErrRecordNotFound {
  7748. //创建流水表
  7749. err := service.CreateStockFlowOne(stockFlow)
  7750. fmt.Println("err", err)
  7751. } else if errflow == nil {
  7752. //插入详情明细表
  7753. stockFlow := models.VmStockFlow{
  7754. ID: exsit.ID,
  7755. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7756. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7757. WarehouseOutId: warehouseOut.ID,
  7758. GoodId: item.GoodId,
  7759. Number: warehouseOutInfos.Number,
  7760. ProductDate: stockInInfo.ProductDate,
  7761. ExpireDate: stockInInfo.ExpiryDate,
  7762. Count: exsit.Count - delete_count,
  7763. Price: stockInInfo.Price,
  7764. Status: 1,
  7765. Ctime: record_time,
  7766. UserOrgId: adminInfo.Org.Id,
  7767. Manufacturer: stockInInfo.Manufacturer,
  7768. Dealer: stockInInfo.Dealer,
  7769. LicenseNumber: stockInInfo.LicenseNumber,
  7770. IsEdit: 2,
  7771. Creator: creater,
  7772. SystemTime: record_time,
  7773. ConsumableType: 3,
  7774. WarehousingDetailId: 0,
  7775. IsSys: 1,
  7776. UpdateCreator: creater,
  7777. PatientId: patient_id,
  7778. StorehouseId: houseConfig.StorehouseOutInfo,
  7779. }
  7780. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7781. }
  7782. } else if errcod == nil {
  7783. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7784. //查询剩余库存
  7785. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7786. var sum_count int64
  7787. for _, item := range goodList {
  7788. sum_count += item.StockCount
  7789. }
  7790. //创建退库单,生成退库数据
  7791. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7792. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7793. operation_time := time.Now().Unix()
  7794. creater := adminInfo.AdminUser.Id
  7795. //创建退库单
  7796. timeStr := time.Now().Format("2006-01-02")
  7797. timeArr := strings.Split(timeStr, "-")
  7798. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7799. total = total + 1
  7800. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7801. cancelStock := models.CancelStock{
  7802. OrderNumber: orderNumber,
  7803. OperaTime: operation_time,
  7804. OrgId: adminInfo.Org.Id,
  7805. Creater: creater,
  7806. Ctime: time.Now().Unix(),
  7807. Status: 1,
  7808. ReturnTime: record_time,
  7809. Type: 1,
  7810. StorehouseId: houseConfig.StorehouseOutInfo,
  7811. IsCheck: 1,
  7812. }
  7813. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7814. if msgerrkonde == gorm.ErrRecordNotFound {
  7815. service.AddSigleCancelStock(&cancelStock)
  7816. }
  7817. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7818. //查询是否有出库
  7819. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7820. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7821. deaerler, _ := service.GetDealerById(info.Dealer)
  7822. if info.ID > 0 {
  7823. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7824. cancelStockInfo := models.CancelStockInfo{
  7825. GoodId: item.GoodId,
  7826. CancelStockId: cancel.ID,
  7827. GoodTypeId: good.GoodTypeId,
  7828. Count: delete_count,
  7829. Price: info.Price,
  7830. Total: 0,
  7831. ProductDate: info.ProductDate,
  7832. ExpiryDate: info.ExpiryDate,
  7833. Ctime: time.Now().Unix(),
  7834. Status: 1,
  7835. OrgId: adminInfo.Org.Id,
  7836. OrderNumber: cancel.OrderNumber,
  7837. Type: 0,
  7838. Dealer: deaerler.DealerName,
  7839. Manufacturer: manufacturer.ManufacturerName,
  7840. Number: info.Number,
  7841. RegisterAccount: "",
  7842. Remark: "",
  7843. WarehouseInfoId: info.WarehouseInfotId,
  7844. PatientId: info.PatientId,
  7845. RecordDate: info.SysRecordTime,
  7846. StorehouseId: houseConfig.StorehouseOutInfo,
  7847. IsCheck: 1,
  7848. }
  7849. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7850. //退库数量增加
  7851. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7852. //查询剩余库存
  7853. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7854. var over_count int64
  7855. for _, it := range goodList {
  7856. over_count += it.StockCount
  7857. }
  7858. flow := models.VmStockFlow{
  7859. WarehousingId: info.WarehouseInfotId,
  7860. GoodId: item.GoodId,
  7861. Number: info.Number,
  7862. LicenseNumber: info.LicenseNumber,
  7863. Count: delete_count,
  7864. UserOrgId: adminInfo.Org.Id,
  7865. PatientId: patient_id,
  7866. SystemTime: info.SysRecordTime,
  7867. ConsumableType: 7,
  7868. IsSys: 0,
  7869. WarehousingOrder: "",
  7870. WarehouseOutId: info.WarehouseOutId,
  7871. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7872. IsEdit: 0,
  7873. CancelStockId: cancel.ID,
  7874. CancelOrderNumber: cancel.OrderNumber,
  7875. Manufacturer: manufacturer.ID,
  7876. Dealer: 0,
  7877. Creator: adminInfo.AdminUser.Id,
  7878. UpdateCreator: 0,
  7879. Status: 1,
  7880. Ctime: record_time,
  7881. Mtime: 0,
  7882. Price: info.Price,
  7883. WarehousingDetailId: info.WarehouseInfotId,
  7884. WarehouseOutDetailId: info.ID,
  7885. CancelOutDetailId: cancelInfo.ID,
  7886. ProductDate: info.ProductDate,
  7887. ExpireDate: info.ExpiryDate,
  7888. StorehouseId: houseConfig.StorehouseOutInfo,
  7889. OverCount: over_count,
  7890. }
  7891. service.CreateStockFlowOne(flow)
  7892. }
  7893. }
  7894. //更改自动出库的表格
  7895. details := models.BloodAutomaticReduceDetail{
  7896. WarehouseOutId: warehouseOutInfo.ID,
  7897. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7898. PatientId: patient_id,
  7899. Ctime: time.Now().Unix(),
  7900. Mtime: time.Now().Unix(),
  7901. Status: 1,
  7902. RecordTime: record_time,
  7903. OrgId: adminInfo.Org.Id,
  7904. GoodId: item.GoodId,
  7905. GoodTypeId: item.GoodTypeId,
  7906. Count: item.Count,
  7907. StorehouseId: houseConfig.StorehouseOutInfo,
  7908. }
  7909. //查询当天耗材是否已经存在数据
  7910. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7911. if errcode == gorm.ErrRecordNotFound {
  7912. service.CreateAutoReduceRecord(&details)
  7913. } else if errcode == nil {
  7914. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7915. service.CreateAutoReduceRecord(&details)
  7916. }
  7917. //查询默认仓库
  7918. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7919. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7920. var total_count int64
  7921. for _, it := range stockList {
  7922. total_count += it.StockCount
  7923. }
  7924. //基础库插入数据
  7925. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7926. }
  7927. }
  7928. if len(outbefor) > 0 {
  7929. //出库
  7930. for _, item := range outbefor {
  7931. var last_total int64
  7932. //1.查看该患者该耗材型号最后一次出库数量
  7933. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7934. //计算当前出库和最后一次出库数据相差数据
  7935. last_total = item.Count - goodInfoOne.Count
  7936. //查询该耗材的总库存
  7937. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7938. // 如果库存差大于剩余库存则提示库存不足
  7939. if last_total > wareinfo.StockCount {
  7940. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7941. c.ServeSuccessJSON(map[string]interface{}{
  7942. "message": "1",
  7943. "good_name": goodObj.GoodName,
  7944. "specification_name": goodObj.SpecificationName,
  7945. })
  7946. return
  7947. } else {
  7948. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7949. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7950. if err == gorm.ErrRecordNotFound {
  7951. //没有记录,则创建出库单
  7952. timeStr := time.Now().Format("2006-01-02")
  7953. timeArr := strings.Split(timeStr, "-")
  7954. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7955. total = total + 1
  7956. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7957. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7958. number = number + total
  7959. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7960. warehouseOut := models.WarehouseOut{
  7961. WarehouseOutOrderNumber: warehousing_out_order,
  7962. OperationTime: time.Now().Unix(),
  7963. OrgId: adminInfo.Org.Id,
  7964. Creater: adminInfo.AdminUser.Id,
  7965. Ctime: time.Now().Unix(),
  7966. Status: 1,
  7967. WarehouseOutTime: record_time,
  7968. Dealer: 0,
  7969. Manufacturer: 0,
  7970. Type: 1,
  7971. IsSys: 1,
  7972. StorehouseId: houseConfig.StorehouseOutInfo,
  7973. IsCheck: 1,
  7974. }
  7975. service.AddSigleWarehouseOutOne(&warehouseOut)
  7976. }
  7977. //出库
  7978. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7979. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7980. //1.查看该患者该耗材型号最后一次出库数量
  7981. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7982. prepare := models.DialysisBeforePrepare{
  7983. UserOrgId: adminInfo.Org.Id,
  7984. PatientId: patient_id,
  7985. RecordDate: record_time,
  7986. GoodId: item.GoodId,
  7987. GoodTypeId: item.GoodTypeId,
  7988. Count: item.Count - goodInfoTwo.Count,
  7989. Ctime: time.Now().Unix(),
  7990. Mtime: 0,
  7991. Creater: adminInfo.AdminUser.Id,
  7992. Modifier: adminInfo.AdminUser.Id,
  7993. Status: 1,
  7994. CommdityCode: "",
  7995. NewCount: 0,
  7996. ProjectId: 0,
  7997. StorehouseId: houseConfig.StorehouseOutInfo,
  7998. }
  7999. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  8000. //增加出库数量
  8001. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  8002. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8003. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8004. var total_count int64
  8005. for _, it := range stockList {
  8006. total_count += it.StockCount
  8007. }
  8008. //基础库插入数据
  8009. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8010. //剩余库存
  8011. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8012. var flush_count int64
  8013. for _, it := range goodList {
  8014. flush_count += it.StockCount
  8015. }
  8016. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8017. }
  8018. }
  8019. }
  8020. //查询今日出库数据
  8021. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8022. for _, it := range list {
  8023. prepare := models.DialysisBeforePrepare{
  8024. UserOrgId: it.OrgId,
  8025. PatientId: patient_id,
  8026. RecordDate: it.RecordTime,
  8027. GoodId: it.GoodId,
  8028. GoodTypeId: it.GoodTypeId,
  8029. Count: it.Count,
  8030. Ctime: time.Now().Unix(),
  8031. Creater: adminInfo.AdminUser.Id,
  8032. Status: 1,
  8033. StorehouseId: houseConfig.StorehouseOutInfo,
  8034. ProjectId: it.ProjectId,
  8035. }
  8036. //删除准备表数据
  8037. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  8038. service.CreateDialysisBeforePrepareOne(&prepare)
  8039. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8040. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8041. var total_count int64
  8042. for _, it := range stockList {
  8043. total_count += it.StockCount
  8044. }
  8045. //基础库插入数据
  8046. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  8047. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  8048. var flush_count int64
  8049. for _, it := range goodList {
  8050. flush_count += it.StockCount
  8051. }
  8052. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  8053. }
  8054. }
  8055. }
  8056. //更新自动出库的地方
  8057. var errs error
  8058. if errs == nil {
  8059. c.ServeSuccessJSON(map[string]interface{}{
  8060. "msg": "修改成功",
  8061. "message": "2",
  8062. "good_name": "",
  8063. "specification_name": "",
  8064. })
  8065. return
  8066. } else {
  8067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8068. return
  8069. }
  8070. }
  8071. }
  8072. func (c *DialysisAPIController) GetDialysisGoods() {
  8073. schedualDate := c.GetString("schedule_date")
  8074. schedule_type, _ := c.GetInt64("schedule_type")
  8075. partition_id, _ := c.GetInt64("partition_id")
  8076. page, _ := c.GetInt("page")
  8077. patient_id, _ := c.GetInt64("patient_id")
  8078. schedualEndDate := int64(0)
  8079. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  8080. if parseDateErr != nil && len(schedualDate) != 0 {
  8081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8082. return
  8083. }
  8084. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  8085. if parseDateErr != nil && len(schedualDate) != 0 {
  8086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8087. return
  8088. }
  8089. schedualEndDate = endDate.Unix()
  8090. adminUser := c.GetMobileAdminUserInfo()
  8091. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  8092. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  8093. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8094. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8095. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  8096. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  8097. //获取当天该病人的透析处方
  8098. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8099. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8100. if err == gorm.ErrRecordNotFound {
  8101. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8102. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8103. if patient_id != 0 {
  8104. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8105. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8106. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8107. //获取患者总的出库数据
  8108. item.LastAutomaticReduceDetail = goodUser
  8109. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8110. item.Project = project
  8111. for _, it := range item.AutomaticReduceDetail {
  8112. var total int64
  8113. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8114. for _, its := range auto {
  8115. total += its.Count
  8116. }
  8117. it.Count = total
  8118. }
  8119. }
  8120. }
  8121. c.ServeSuccessJSON(map[string]interface{}{
  8122. "dialysis_goods": dialysisGoods,
  8123. "good_type": goodTypes,
  8124. "total": total,
  8125. "prescribe": prescribe,
  8126. "good_info": good_info,
  8127. "warehouseOutList": warehouseOutList,
  8128. "config": config,
  8129. "outConfig": outConfig,
  8130. "settleConfig": settleConfig,
  8131. })
  8132. return
  8133. } else if err == nil {
  8134. //获取当天排班的每个患者的库存使用情况
  8135. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8136. //获取患者总的出库数据
  8137. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8138. if patient_id != 0 {
  8139. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8140. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8141. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8142. item.Project = project
  8143. item.LastAutomaticReduceDetail = goodUser
  8144. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8145. for _, it := range item.AutomaticReduceDetail {
  8146. var total int64
  8147. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8148. for _, its := range auto {
  8149. total += its.Count
  8150. }
  8151. it.Count = total
  8152. }
  8153. }
  8154. }
  8155. if err == nil {
  8156. c.ServeSuccessJSON(map[string]interface{}{
  8157. "dialysis_goods": dialysisGoods,
  8158. "good_type": goodTypes,
  8159. "total": total,
  8160. "prescribe": prescribe,
  8161. "good_info": good_info,
  8162. "project": project,
  8163. "warehouseOutList": warehouseOutList,
  8164. "config": config,
  8165. "outConfig": outConfig,
  8166. "settleConfig": settleConfig,
  8167. })
  8168. return
  8169. } else {
  8170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8171. return
  8172. }
  8173. } else if err != nil {
  8174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8175. return
  8176. }
  8177. }
  8178. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8179. start_time := c.GetString("start_time")
  8180. end_time := c.GetString("end_time")
  8181. timeLayout := "2006-01-02"
  8182. loc, _ := time.LoadLocation("Local")
  8183. var theStartTime int64
  8184. if len(start_time) > 0 {
  8185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8186. if err != nil {
  8187. utils.ErrorLog(err.Error())
  8188. }
  8189. theStartTime = theTime.Unix()
  8190. }
  8191. var theEndtTime int64
  8192. if len(end_time) > 0 {
  8193. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8194. if err != nil {
  8195. utils.ErrorLog(err.Error())
  8196. }
  8197. theEndtTime = theTime.Unix()
  8198. }
  8199. adminUser := c.GetMobileAdminUserInfo()
  8200. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8201. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8202. if err == nil {
  8203. c.ServeSuccessJSON(map[string]interface{}{
  8204. "stock_out": outInfo,
  8205. "stockCount": stockCount,
  8206. })
  8207. return
  8208. } else {
  8209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8210. return
  8211. }
  8212. }
  8213. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8214. patient_id, _ := c.GetInt64("patient_id", 0)
  8215. record_time := c.GetString("record_time")
  8216. adminUser := c.GetMobileAdminUserInfo()
  8217. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8218. if parseDateErr != nil && len(record_time) != 0 {
  8219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8220. return
  8221. }
  8222. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8223. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8224. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8225. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8226. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8227. //获取今日患者的透析处方参数
  8228. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8229. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8230. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8231. c.ServeSuccessJSON(map[string]interface{}{
  8232. "good_type": goodTypes,
  8233. "good_user": goodUser,
  8234. "good_info": good_info,
  8235. "last_good_user": lastGoodUserDetial,
  8236. "project": project,
  8237. "prescription": prescribe,
  8238. "outInfo": outInfo,
  8239. "configs": configs,
  8240. })
  8241. return
  8242. }
  8243. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8244. patient_id, _ := c.GetInt64("patient_id", 0)
  8245. record_date := c.GetString("record_time")
  8246. timeLayout := "2006-01-02"
  8247. loc, _ := time.LoadLocation("Local")
  8248. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8249. record_time := theRecordTime.Unix()
  8250. adminInfo := c.GetMobileAdminUserInfo()
  8251. dataBody := make(map[string]interface{}, 0)
  8252. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8253. if err != nil {
  8254. utils.ErrorLog(err.Error())
  8255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8256. return
  8257. }
  8258. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8259. var beforePrepares []*models.DialysisBeforePrepareGoods
  8260. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8261. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8262. goods, _ := dataBody["goods"].([]interface{})
  8263. if len(goods) > 0 {
  8264. for _, item := range goods {
  8265. items := item.(map[string]interface{})
  8266. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8267. utils.ErrorLog("good_id")
  8268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8269. return
  8270. }
  8271. good_id := int64(items["good_id"].(float64))
  8272. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8273. utils.ErrorLog("good_type_id")
  8274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8275. return
  8276. }
  8277. good_type_id := int64(items["good_type_id"].(float64))
  8278. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8279. utils.ErrorLog("count")
  8280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8281. return
  8282. }
  8283. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8284. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8285. utils.ErrorLog("project_id")
  8286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8287. return
  8288. }
  8289. project_id := int64(items["project_id"].(float64))
  8290. new_count := int64(items["new_count"].(float64))
  8291. old_count := int64(items["old_count"].(float64))
  8292. prepare := &models.DialysisBeforePrepareGoods{
  8293. GoodId: good_id,
  8294. GoodTypeId: good_type_id,
  8295. Count: count,
  8296. ProjectId: project_id,
  8297. StorehouseId: houseConfig.StorehouseOutInfo,
  8298. NewCount: new_count,
  8299. OldCount: old_count,
  8300. }
  8301. beforePrepares = append(beforePrepares, prepare)
  8302. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8303. GoodId: good_id,
  8304. GoodTypeId: good_type_id,
  8305. Count: count,
  8306. ProjectId: project_id,
  8307. StorehouseId: houseConfig.StorehouseOutInfo,
  8308. NewCount: new_count,
  8309. OldCount: old_count,
  8310. }
  8311. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8312. }
  8313. }
  8314. }
  8315. //查询是否有库存
  8316. for _, item := range beforePrepares {
  8317. if item.NewCount > 0 {
  8318. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8319. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8320. if item.Count > warehouse.Count {
  8321. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8322. c.ServeSuccessJSON(map[string]interface{}{
  8323. "message": "1",
  8324. "good_name": goodObj.GoodName,
  8325. "specification_name": goodObj.SpecificationName,
  8326. })
  8327. return
  8328. }
  8329. }
  8330. }
  8331. // 查询信息规挡的设置天数
  8332. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8333. if infor.ID > 0 && infor.WeekDay > 0 {
  8334. var cha_time int64
  8335. timeNowStr := time.Now().Format("2006-01-02")
  8336. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8337. //今日的日期减去设置的日期
  8338. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8339. if cha_time >= record_time {
  8340. //查询审核是否允许
  8341. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8342. //申请状态不允许的情况 拒绝修改
  8343. if infor.ApplicationStatus != 1 {
  8344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8345. return
  8346. }
  8347. }
  8348. }
  8349. //出库逻辑
  8350. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8351. if err != nil {
  8352. utils.ErrorLog(err.Error())
  8353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8354. return
  8355. }
  8356. finish := models.XtDialysisFinish{
  8357. IsFinish: 1,
  8358. UserOrgId: adminInfo.Org.Id,
  8359. Status: 1,
  8360. Ctime: time.Now().Unix(),
  8361. Mtime: 0,
  8362. Module: 11,
  8363. RecordDate: record_time,
  8364. Sourse: 1,
  8365. PatientId: patient_id,
  8366. }
  8367. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8368. if dialysisFinish.ID == 0 {
  8369. service.CreateDialysisFinish(finish)
  8370. }
  8371. //查询当天出库的数据
  8372. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8373. for _, item := range list {
  8374. prepare := models.DialysisBeforePrepare{
  8375. UserOrgId: item.OrgId,
  8376. PatientId: item.PatientId,
  8377. RecordDate: item.RecordTime,
  8378. GoodId: item.GoodId,
  8379. GoodTypeId: item.GoodTypeId,
  8380. Count: item.Count,
  8381. Creater: adminInfo.AdminUser.Id,
  8382. Status: 1,
  8383. Ctime: time.Now().Unix(),
  8384. ProjectId: item.ProjectId,
  8385. StorehouseId: houseConfig.StorehouseOutInfo,
  8386. }
  8387. //清空准备表的数据
  8388. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8389. //插入准备表数据
  8390. service.CreateDialysisBeforePrepareOne(&prepare)
  8391. //查询默认仓库
  8392. //查询默认仓库
  8393. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8394. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8395. var total_count int64
  8396. for _, it := range stockList {
  8397. total_count += it.StockCount
  8398. }
  8399. //基础库插入数据
  8400. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8401. ////更新剩余库存
  8402. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8403. var flush_count int64
  8404. for _, it := range goodList {
  8405. flush_count += it.StockCount
  8406. }
  8407. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8408. if errs != nil {
  8409. goodErrcode := models.XtGoodErrcode{
  8410. UserOrgId: item.OrgId,
  8411. Errcode: "手动出库更新剩余出库失败",
  8412. GoodId: item.GoodId,
  8413. Status: 1,
  8414. Ctime: time.Now().Unix(),
  8415. Mtime: 0,
  8416. Count: 0,
  8417. StockCount: 0,
  8418. Creater: adminInfo.AdminUser.Id,
  8419. BatchNumberId: 0,
  8420. WarehouseOutId: 0,
  8421. }
  8422. service.CreateGoodErrcode(goodErrcode)
  8423. }
  8424. }
  8425. //更新自动出库的地方
  8426. var errs error
  8427. if errs == nil {
  8428. c.ServeSuccessJSON(map[string]interface{}{
  8429. "msg": "修改成功",
  8430. "message": "2",
  8431. "good_name": "",
  8432. "specification_name": "",
  8433. })
  8434. return
  8435. } else {
  8436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8437. return
  8438. }
  8439. }
  8440. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8441. newArr = make([]*models.DialysisBeforePrepare, 0)
  8442. for i := 0; i < len(arr); i++ {
  8443. repeat := false
  8444. for j := i + 1; j < len(arr); j++ {
  8445. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8446. repeat = true
  8447. break
  8448. }
  8449. }
  8450. if !repeat {
  8451. newArr = append(newArr, arr[i])
  8452. }
  8453. }
  8454. return
  8455. }
  8456. func (c *DialysisAPIController) GetAllDrug() {
  8457. patient_id, _ := c.GetInt64("patient_id", 0)
  8458. adminInfo := c.GetMobileAdminUserInfo()
  8459. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8460. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8461. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8462. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8463. c.ServeSuccessJSON(map[string]interface{}{
  8464. "base_drug_config": drugStockConfig,
  8465. "private_drug_config": privateDrugConfig,
  8466. "base_drug_list": drugList,
  8467. "private_drug_list": privateDrugList,
  8468. })
  8469. }
  8470. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8471. newArr = make([]*models.DialysisBeforePrepare, 0)
  8472. for i := 0; i < len(arr); i++ {
  8473. repeat := false
  8474. for j := i + 1; j < len(arr); j++ {
  8475. if arr[i].GoodId == arr[j].GoodId {
  8476. repeat = true
  8477. break
  8478. }
  8479. }
  8480. if !repeat {
  8481. newArr = append(newArr, arr[i])
  8482. }
  8483. }
  8484. return
  8485. }
  8486. func (c *DialysisAPIController) GetDepartment() {
  8487. adminInfo := c.GetMobileAdminUserInfo()
  8488. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8489. if err == nil {
  8490. c.ServeSuccessJSON(map[string]interface{}{
  8491. "departments": departments,
  8492. })
  8493. } else {
  8494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8495. return
  8496. }
  8497. }
  8498. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8499. types, _ := c.GetInt("type", 0)
  8500. start_time := c.GetString("start_time")
  8501. end_time := c.GetString("end_time")
  8502. orgId := c.GetMobileAdminUserInfo().Org.Id
  8503. timeLayout := "2006-01-02"
  8504. loc, _ := time.LoadLocation("Local")
  8505. var startTime int64
  8506. if len(start_time) > 0 {
  8507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8508. if err != nil {
  8509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8510. return
  8511. }
  8512. startTime = theTime.Unix()
  8513. }
  8514. var endTime int64
  8515. if len(end_time) > 0 {
  8516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8517. if err != nil {
  8518. utils.ErrorLog(err.Error())
  8519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8520. return
  8521. }
  8522. endTime = theTime.Unix()
  8523. }
  8524. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8525. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8526. if err != nil {
  8527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8528. } else {
  8529. c.ServeSuccessJSON(map[string]interface{}{
  8530. "list": list,
  8531. "type": types,
  8532. "stockTotal": stockTotal,
  8533. })
  8534. }
  8535. }
  8536. func (c *DialysisAPIController) GetPrescriptionList() {
  8537. start_time := c.GetString("start_time")
  8538. end_time := c.GetString("end_time")
  8539. schedule_type, _ := c.GetInt64("schedule_type")
  8540. partion_id, _ := c.GetInt64("partion_id")
  8541. orgId := c.GetMobileAdminUserInfo().Org.Id
  8542. timeLayout := "2006-01-02"
  8543. loc, _ := time.LoadLocation("Local")
  8544. var startTime int64
  8545. if len(start_time) > 0 {
  8546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8547. if err != nil {
  8548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8549. return
  8550. }
  8551. startTime = theTime.Unix()
  8552. }
  8553. var endTime int64
  8554. if len(end_time) > 0 {
  8555. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8556. if err != nil {
  8557. utils.ErrorLog(err.Error())
  8558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8559. return
  8560. }
  8561. endTime = theTime.Unix()
  8562. }
  8563. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8564. fmt.Println("schedulelist22222222", schedulelist)
  8565. c.ServeSuccessJSON(map[string]interface{}{
  8566. "list": schedulelist,
  8567. })
  8568. return
  8569. }
  8570. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8571. ids := c.GetString("ids")
  8572. //patient_id, _ := c.GetInt64("patient_id")
  8573. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8574. idArray := strings.Split(ids, ",")
  8575. err := service.BatchDeleteMonitor(idArray)
  8576. fmt.Print("err", err)
  8577. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8578. //redis := service.RedisClient()
  8579. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8580. //redis.Set(key, "", time.Second)
  8581. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8582. //redis.Set(keyOne, "", time.Second)
  8583. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8584. //redis.Close()
  8585. c.ServeSuccessJSON(map[string]interface{}{
  8586. "msg": "批量删除成功",
  8587. })
  8588. return
  8589. }
  8590. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8591. id, _ := c.GetInt64("id")
  8592. timeLayout := "2006-01-02"
  8593. loc, _ := time.LoadLocation("Local")
  8594. //start_time := time.Now().Format("2006-01-02")
  8595. start_time := c.GetString("start_time")
  8596. end_time := c.GetString("end_time")
  8597. var startdateunix int64
  8598. if len(start_time) > 0 {
  8599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8600. if err != nil {
  8601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8602. return
  8603. }
  8604. startdateunix = theTime.Unix()
  8605. }
  8606. var enddateunix int64
  8607. if len(end_time) > 0 {
  8608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8609. if err != nil {
  8610. utils.ErrorLog(err.Error())
  8611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8612. return
  8613. }
  8614. enddateunix = theTime.Unix()
  8615. }
  8616. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8617. //nowTime := time.Now()
  8618. //endTime := nowTime.AddDate(-30, 0, 0)
  8619. //endTimes := endTime.Format("2006-01-02")
  8620. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8621. org_id := c.GetMobileAdminUserInfo().Org.Id
  8622. //if org_id == 10579 {
  8623. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8624. // c.ServeSuccessJSON(map[string]interface{}{
  8625. // "list": list,
  8626. // })
  8627. // return
  8628. //} else {
  8629. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8630. // c.ServeSuccessJSON(map[string]interface{}{
  8631. // "list": list,
  8632. // })
  8633. // return
  8634. //}
  8635. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8636. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8637. c.ServeSuccessJSON(map[string]interface{}{
  8638. "list": list,
  8639. })
  8640. return
  8641. } else {
  8642. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8643. c.ServeSuccessJSON(map[string]interface{}{
  8644. "list": list,
  8645. })
  8646. }
  8647. return
  8648. }
  8649. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8650. dataBody := make(map[string]interface{}, 0)
  8651. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8652. ids := c.GetString("ids")
  8653. idArray := strings.Split(ids, ",")
  8654. origin, _ := c.GetInt64("origin")
  8655. if origin == 1 {
  8656. err = service.BatchDeleteAdvice(idArray)
  8657. fmt.Print("err", err)
  8658. c.ServeSuccessJSON(map[string]interface{}{
  8659. "msg": "批量删除成功",
  8660. })
  8661. return
  8662. }
  8663. if origin == 2 {
  8664. service.BatchDeleteHisAdvice(idArray)
  8665. }
  8666. }
  8667. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8668. good_id, _ := c.GetInt64("good_id")
  8669. count, _ := c.GetInt64("count")
  8670. record_time, _ := c.GetInt64("record_time")
  8671. patient_id, _ := c.GetInt64("patient_id")
  8672. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8673. c.ServeSuccessJSON(map[string]interface{}{
  8674. "detail": detail,
  8675. })
  8676. return
  8677. }
  8678. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8679. good_id, _ := c.GetInt64("good_id")
  8680. record_time, _ := c.GetInt64("record_time")
  8681. patient_id, _ := c.GetInt64("patient_id")
  8682. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8683. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8684. fmt.Print("err", err)
  8685. c.ServeSuccessJSON(map[string]interface{}{
  8686. "msg": "批量删除成功",
  8687. })
  8688. return
  8689. }
  8690. func (c *DialysisAPIController) BatchAdviceCheck() {
  8691. ids := c.GetString("ids")
  8692. idArray := strings.Split(ids, ",")
  8693. creator, _ := c.GetInt64("creator")
  8694. origin, _ := c.GetInt64("origin")
  8695. if origin == 1 {
  8696. err := service.BatchAdviceCheck(idArray, creator)
  8697. fmt.Println(err)
  8698. list, _ := service.GetAdviceExecutionById(idArray)
  8699. c.ServeSuccessJSON(map[string]interface{}{
  8700. "list": list,
  8701. })
  8702. return
  8703. }
  8704. if origin == 2 {
  8705. service.BatchHisAdviceCheck(idArray, creator)
  8706. list, _ := service.GetHisAdviceExecutionById(idArray)
  8707. c.ServeSuccessJSON(map[string]interface{}{
  8708. "list": list,
  8709. })
  8710. return
  8711. }
  8712. }
  8713. func (c *DialysisAPIController) BatchAdviceExecution() {
  8714. ids := c.GetString("ids")
  8715. idArray := strings.Split(ids, ",")
  8716. executionTime := c.GetString("execution_time")
  8717. creator, _ := c.GetInt64("creator")
  8718. timeLayout := "2006-01-02 15:04:05"
  8719. loc, _ := time.LoadLocation("Local")
  8720. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8721. orgin, _ := c.GetInt64("origin")
  8722. if orgin == 1 {
  8723. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8724. list, _ := service.GetAdviceExecutionById(idArray)
  8725. fmt.Println(err)
  8726. c.ServeSuccessJSON(map[string]interface{}{
  8727. "list": list,
  8728. })
  8729. return
  8730. }
  8731. if orgin == 2 {
  8732. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8733. list, _ := service.GetHisAdviceExecutionById(idArray)
  8734. fmt.Println(err)
  8735. c.ServeSuccessJSON(map[string]interface{}{
  8736. "list": list,
  8737. })
  8738. return
  8739. }
  8740. }
  8741. func (c *DialysisAPIController) UpdateStockGoods() {
  8742. good_id, _ := c.GetInt64("good_id")
  8743. record_time, _ := c.GetInt64("record_time")
  8744. patient_id, _ := c.GetInt64("patient_id")
  8745. count, _ := c.GetInt64("count")
  8746. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8747. fmt.Print("err", err)
  8748. c.ServeSuccessJSON(map[string]interface{}{
  8749. "msg": "更新成功",
  8750. })
  8751. return
  8752. }
  8753. // 当前数据比上一次出库数据少
  8754. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8755. //查询该患者当天已经出库的耗材信息
  8756. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8757. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8758. for i := len(goods_yc) - 1; i >= 0; i-- {
  8759. goods_yc_temp := goods_yc[i]
  8760. for j := len(goods) - 1; j >= 0; j-- {
  8761. goods_temp := goods[j]
  8762. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8763. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8764. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8765. if goods_yc_temp.Count == goods_temp.Count {
  8766. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8767. goods = append(goods[:j], goods[j+1:]...)
  8768. break
  8769. }
  8770. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8771. if goods_yc_temp.Count > goods_temp.Count {
  8772. temp_count := goods_yc_temp.Count - goods_temp.Count
  8773. goods_yc[i].Count = temp_count
  8774. goods = append(goods[:j], goods[j+1:]...)
  8775. break
  8776. }
  8777. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8778. if goods_yc_temp.Count < goods_temp.Count {
  8779. temp_count := goods_temp.Count - goods_yc_temp.Count
  8780. goods[j].Count = temp_count
  8781. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8782. break
  8783. }
  8784. }
  8785. }
  8786. }
  8787. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8788. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8789. //退库
  8790. if len(goods_yc) > 0 {
  8791. for _, good_yc := range goods_yc {
  8792. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8793. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8794. }
  8795. }
  8796. return nil
  8797. }
  8798. // 耗材出库删除
  8799. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8800. // 先根据相关信息查询当天该耗材的出库信息
  8801. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8802. if err != nil {
  8803. return err
  8804. }
  8805. var delete_count int64 = 0
  8806. delete_count = warehouseOutInfos.Count - count
  8807. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8808. // 在出库记录表里记录退库详情
  8809. warehouseOutInfo := &models.WarehouseOutInfo{
  8810. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8811. WarehouseOutId: warehouseOut.ID,
  8812. Status: 1,
  8813. Ctime: time.Now().Unix(),
  8814. OrgId: orgID,
  8815. Type: 1,
  8816. IsSys: 1,
  8817. SysRecordTime: record_time,
  8818. GoodTypeId: good_yc.GoodTypeId,
  8819. GoodId: good_yc.GoodId,
  8820. PatientId: good_yc.PatientId,
  8821. ConsumableType: 2,
  8822. StorehouseId: houseConfig.StorehouseOutInfo,
  8823. IsCheck: 1,
  8824. }
  8825. warehouseOutInfo.Count = count
  8826. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8827. warehouseOutInfo.Price = stockInInfo.Price
  8828. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8829. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8830. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8831. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8832. warehouseOutInfo.Number = warehouseOutInfos.Number
  8833. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8834. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8835. //查找当天是否存在出库记录
  8836. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8837. if errcod == gorm.ErrRecordNotFound {
  8838. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8839. //插入详情明细表
  8840. stockFlow := models.VmStockFlow{
  8841. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8842. WarehouseOutId: warehouseOut.ID,
  8843. GoodId: good_yc.GoodId,
  8844. Number: warehouseOutInfos.Number,
  8845. ProductDate: stockInInfo.ProductDate,
  8846. ExpireDate: stockInInfo.ExpiryDate,
  8847. Count: count,
  8848. Price: stockInInfo.Price,
  8849. Status: 1,
  8850. Ctime: time.Now().Unix(),
  8851. UserOrgId: good_yc.OrgId,
  8852. Manufacturer: stockInInfo.Manufacturer,
  8853. Dealer: stockInInfo.Dealer,
  8854. LicenseNumber: stockInInfo.LicenseNumber,
  8855. IsEdit: 2,
  8856. Creator: creater,
  8857. SystemTime: record_time,
  8858. ConsumableType: 3,
  8859. WarehousingDetailId: 0,
  8860. IsSys: 1,
  8861. UpdateCreator: creater,
  8862. PatientId: patient_id,
  8863. StorehouseId: houseConfig.StorehouseOutInfo,
  8864. }
  8865. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8866. if errflow == gorm.ErrRecordNotFound {
  8867. //创建流水表
  8868. err := service.CreateStockFlowOne(stockFlow)
  8869. fmt.Println("err", err)
  8870. } else if errflow == nil {
  8871. //插入详情明细表
  8872. stockFlow := models.VmStockFlow{
  8873. ID: exsit.ID,
  8874. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8875. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8876. WarehouseOutId: warehouseOut.ID,
  8877. GoodId: good_yc.GoodId,
  8878. Number: warehouseOutInfos.Number,
  8879. ProductDate: stockInInfo.ProductDate,
  8880. ExpireDate: stockInInfo.ExpiryDate,
  8881. Count: exsit.Count - delete_count,
  8882. Price: stockInInfo.Price,
  8883. Status: 1,
  8884. Ctime: time.Now().Unix(),
  8885. UserOrgId: good_yc.OrgId,
  8886. Manufacturer: stockInInfo.Manufacturer,
  8887. Dealer: stockInInfo.Dealer,
  8888. LicenseNumber: stockInInfo.LicenseNumber,
  8889. IsEdit: 2,
  8890. Creator: creater,
  8891. SystemTime: record_time,
  8892. ConsumableType: 3,
  8893. WarehousingDetailId: 0,
  8894. IsSys: 1,
  8895. UpdateCreator: creater,
  8896. PatientId: patient_id,
  8897. StorehouseId: houseConfig.StorehouseOutInfo,
  8898. }
  8899. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8900. }
  8901. if errOne != nil {
  8902. return errOne
  8903. }
  8904. } else if errcod == nil {
  8905. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8906. //插入详情明细表
  8907. stockFlow := models.VmStockFlow{
  8908. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8909. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8910. WarehouseOutId: warehouseOut.ID,
  8911. GoodId: good_yc.GoodId,
  8912. Number: warehouseOutInfos.Number,
  8913. ProductDate: stockInInfo.ProductDate,
  8914. ExpireDate: stockInInfo.ExpiryDate,
  8915. Count: count,
  8916. Price: stockInInfo.Price,
  8917. Status: 1,
  8918. Ctime: time.Now().Unix(),
  8919. UserOrgId: good_yc.OrgId,
  8920. Manufacturer: stockInInfo.Manufacturer,
  8921. Dealer: stockInInfo.Dealer,
  8922. LicenseNumber: stockInInfo.LicenseNumber,
  8923. IsEdit: 2,
  8924. Creator: creater,
  8925. SystemTime: record_time,
  8926. ConsumableType: 3,
  8927. WarehousingDetailId: 0,
  8928. IsSys: 1,
  8929. UpdateCreator: creater,
  8930. PatientId: patient_id,
  8931. ReturnCount: delete_count,
  8932. StorehouseId: houseConfig.StorehouseOutInfo,
  8933. }
  8934. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8935. if errflows == gorm.ErrRecordNotFound {
  8936. //创建流水表
  8937. service.CreateStockFlowOne(stockFlow)
  8938. } else if errflows == nil {
  8939. stockFlow := models.VmStockFlow{
  8940. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8941. ID: exsit.ID,
  8942. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8943. WarehouseOutId: warehouseOut.ID,
  8944. GoodId: good_yc.GoodId,
  8945. Number: warehouseOutInfos.Number,
  8946. ProductDate: stockInInfo.ProductDate,
  8947. ExpireDate: stockInInfo.ExpiryDate,
  8948. Count: exsit.Count - delete_count,
  8949. Price: stockInInfo.Price,
  8950. Status: 1,
  8951. Ctime: time.Now().Unix(),
  8952. UserOrgId: good_yc.OrgId,
  8953. Manufacturer: stockInInfo.Manufacturer,
  8954. Dealer: stockInInfo.Dealer,
  8955. LicenseNumber: stockInInfo.LicenseNumber,
  8956. IsEdit: 2,
  8957. Creator: creater,
  8958. SystemTime: record_time,
  8959. ConsumableType: 3,
  8960. WarehousingDetailId: 0,
  8961. IsSys: 1,
  8962. UpdateCreator: creater,
  8963. PatientId: patient_id,
  8964. ReturnCount: delete_count,
  8965. StorehouseId: houseConfig.StorehouseOutInfo,
  8966. }
  8967. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8968. }
  8969. }
  8970. //更改自动出库的表格
  8971. details := models.BloodAutomaticReduceDetail{
  8972. WarehouseOutId: warehouseOutInfo.ID,
  8973. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8974. PatientId: patient_id,
  8975. Ctime: time.Now().Unix(),
  8976. Mtime: time.Now().Unix(),
  8977. Status: 1,
  8978. RecordTime: record_time,
  8979. OrgId: orgID,
  8980. GoodId: good_yc.GoodId,
  8981. GoodTypeId: good_yc.GoodTypeId,
  8982. Count: count,
  8983. StorehouseId: houseConfig.StorehouseOutInfo,
  8984. }
  8985. //查询当天耗材是否已经存在数据
  8986. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8987. if errcode == gorm.ErrRecordNotFound {
  8988. errTwo := service.CreateAutoReduceRecord(&details)
  8989. if errTwo != nil {
  8990. return errTwo
  8991. }
  8992. } else if errcode == nil {
  8993. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8994. service.CreateAutoReduceRecord(&details)
  8995. }
  8996. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8997. //增加出库库存数量
  8998. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8999. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9000. fmt.Println("errOne", errOne)
  9001. // 删除出库完成后,要增加对应批次的库存数量
  9002. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9003. if errThree != nil {
  9004. return errThree
  9005. }
  9006. if good_yc.Count == 0 {
  9007. return nil
  9008. } else {
  9009. return errors.New("退库和出库数据不匹配")
  9010. }
  9011. }
  9012. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  9013. //查询该患者当天已经出库的耗材信息
  9014. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  9015. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  9016. for i := len(goods_yc) - 1; i >= 0; i-- {
  9017. goods_yc_temp := goods_yc[i]
  9018. for j := len(goods) - 1; j >= 0; j-- {
  9019. goods_temp := goods[j]
  9020. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  9021. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  9022. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  9023. if goods_yc_temp.Count == goods_temp.Count {
  9024. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  9025. goods = append(goods[:j], goods[j+1:]...)
  9026. break
  9027. }
  9028. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  9029. if goods_yc_temp.Count > goods_temp.Count {
  9030. temp_count := goods_yc_temp.Count - goods_temp.Count
  9031. goods_yc[i].Count = temp_count
  9032. goods = append(goods[:j], goods[j+1:]...)
  9033. break
  9034. }
  9035. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  9036. if goods_yc_temp.Count < goods_temp.Count {
  9037. temp_count := goods_temp.Count - goods_yc_temp.Count
  9038. goods[j].Count = temp_count
  9039. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  9040. break
  9041. }
  9042. }
  9043. }
  9044. }
  9045. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  9046. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  9047. fmt.Println("剩余需要出库的", len(goods))
  9048. if len(goods) > 0 {
  9049. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  9050. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9051. if err == gorm.ErrRecordNotFound {
  9052. //没有记录,则创建出库单
  9053. timeStr := time.Now().Format("2006-01-02")
  9054. timeArr := strings.Split(timeStr, "-")
  9055. total, _ := service.FindAllWarehouseOut(orgID)
  9056. total = total + 1
  9057. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9058. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9059. number = number + total
  9060. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9061. warehouseOut := models.WarehouseOut{
  9062. WarehouseOutOrderNumber: warehousing_out_order,
  9063. OperationTime: time.Now().Unix(),
  9064. OrgId: orgID,
  9065. Creater: creater,
  9066. Ctime: time.Now().Unix(),
  9067. Status: 1,
  9068. WarehouseOutTime: record_time,
  9069. Dealer: 0,
  9070. Manufacturer: 0,
  9071. Type: 1,
  9072. IsSys: 1,
  9073. StorehouseId: houseConfig.StorehouseOutInfo,
  9074. IsCheck: 1,
  9075. }
  9076. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  9077. if err != nil {
  9078. utils.TraceLog("创建出库单失败 err = %v", err)
  9079. return err
  9080. } else {
  9081. out = warehouseOut
  9082. }
  9083. }
  9084. for _, item := range goods {
  9085. var newCount int64 = 0
  9086. for _, it := range goodOne {
  9087. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  9088. newCount = it.Count
  9089. }
  9090. }
  9091. prepare := models.DialysisBeforePrepare{
  9092. GoodTypeId: item.GoodTypeId,
  9093. GoodId: item.GoodId,
  9094. Count: item.Count,
  9095. StorehouseId: houseConfig.StorehouseOutInfo,
  9096. }
  9097. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  9098. //增加出库数量
  9099. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  9100. }
  9101. }
  9102. if len(goods_yc) > 0 {
  9103. for _, good_yc := range goods_yc {
  9104. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  9105. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  9106. }
  9107. }
  9108. return nil
  9109. }
  9110. // 耗材出库删除
  9111. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  9112. // 先根据相关信息查询当天该耗材的出库信息
  9113. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  9114. if err != nil {
  9115. return err
  9116. }
  9117. var delete_count int64 = 0
  9118. for _, ware := range warehouseOutInfos {
  9119. // 判断当前出库的数据和删除出库数量
  9120. if good_yc.Count <= ware.Count {
  9121. delete_count = good_yc.Count
  9122. } else {
  9123. delete_count = ware.Count
  9124. }
  9125. warehouseOutInfo := &models.WarehouseOutInfo{
  9126. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9127. WarehouseOutId: warehouseOut.ID,
  9128. Status: 1,
  9129. Ctime: time.Now().Unix(),
  9130. Remark: "",
  9131. OrgId: orgID,
  9132. Type: 1,
  9133. Manufacturer: 0,
  9134. Dealer: 0,
  9135. IsSys: 0,
  9136. SysRecordTime: record_time,
  9137. GoodTypeId: good_yc.GoodTypeId,
  9138. GoodId: good_yc.GoodId,
  9139. StorehouseId: warehouseOut.StorehouseId,
  9140. IsCheck: 1,
  9141. }
  9142. warehouseOutInfo.Count = delete_count
  9143. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9144. warehouseOutInfo.Price = stockInInfo.Price
  9145. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9146. if errOne != nil {
  9147. return errOne
  9148. }
  9149. // 删除出库完成后,要改变流水库存(有疑问)
  9150. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9151. fmt.Println("errOne", errOne)
  9152. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  9153. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9154. //扣减出库数量
  9155. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  9156. if errThree != nil {
  9157. return errThree
  9158. }
  9159. }
  9160. if good_yc.Count == 0 {
  9161. return nil
  9162. } else {
  9163. return errors.New("退库和出库数据不匹配")
  9164. }
  9165. }
  9166. func (this *DialysisAPIController) GetMobileScheduleList() {
  9167. limit, _ := this.GetInt64("limit")
  9168. page, _ := this.GetInt64("page")
  9169. type_options_visible, _ := this.GetInt64("type_options_visible")
  9170. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9171. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9172. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9173. }
  9174. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9175. newArr = make([]*models.HisPrescriptionProject, 0)
  9176. for i := 0; i < len(arr); i++ {
  9177. repeat := false
  9178. for j := i + 1; j < len(arr); j++ {
  9179. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9180. repeat = true
  9181. break
  9182. }
  9183. }
  9184. if !repeat {
  9185. newArr = append(newArr, arr[i])
  9186. }
  9187. }
  9188. return
  9189. }
  9190. func (this *DialysisAPIController) GetRoleList() {
  9191. admin_user_id, _ := this.GetInt64("admin_user_id")
  9192. orgid := this.GetMobileAdminUserInfo().Org.Id
  9193. list, err := service.GetRoleList(orgid, admin_user_id)
  9194. fmt.Println(err)
  9195. this.ServeSuccessJSON(map[string]interface{}{
  9196. "list": list,
  9197. })
  9198. return
  9199. }
  9200. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9201. // 先根据相关信息查询当天该耗材的出库信息
  9202. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9203. if err != nil {
  9204. return err
  9205. }
  9206. var delete_count int64 = 0
  9207. delete_count = warehouseOutInfos.Count - count
  9208. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9209. // 删除出库完成后,要增加对应批次的库存数量
  9210. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9211. if errThree != nil {
  9212. return errThree
  9213. }
  9214. //增加退库数量
  9215. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9216. //扣减出库数量
  9217. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9218. //查询剩余库存
  9219. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9220. var sum_count int64
  9221. for _, item := range goodList {
  9222. sum_count += item.StockCount
  9223. }
  9224. // 在出库记录表里记录退库详情
  9225. warehouseOutInfo := &models.WarehouseOutInfo{
  9226. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9227. WarehouseOutId: warehouseOut.ID,
  9228. Status: 1,
  9229. Ctime: time.Now().Unix(),
  9230. OrgId: orgID,
  9231. Type: 1,
  9232. IsSys: 1,
  9233. SysRecordTime: record_time,
  9234. GoodTypeId: good_yc.GoodTypeId,
  9235. GoodId: good_yc.GoodId,
  9236. PatientId: good_yc.PatientId,
  9237. ConsumableType: 2,
  9238. StorehouseId: houseConfig.StorehouseOutInfo,
  9239. IsCheck: 1,
  9240. OverCount: sum_count,
  9241. }
  9242. warehouseOutInfo.Count = count
  9243. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9244. warehouseOutInfo.Price = stockInInfo.Price
  9245. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9246. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9247. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9248. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9249. warehouseOutInfo.Number = warehouseOutInfos.Number
  9250. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9251. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9252. //查找当天是否存在出库记录
  9253. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9254. if errcod == gorm.ErrRecordNotFound {
  9255. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9256. //插入详情明细表
  9257. if errOne != nil {
  9258. return errOne
  9259. }
  9260. //插入详情明细表
  9261. stockFlow := models.VmStockFlow{
  9262. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9263. WarehouseOutId: warehouseOut.ID,
  9264. GoodId: good_yc.GoodId,
  9265. Number: warehouseOutInfos.Number,
  9266. ProductDate: stockInInfo.ProductDate,
  9267. ExpireDate: stockInInfo.ExpiryDate,
  9268. Count: count,
  9269. Price: stockInInfo.Price,
  9270. Status: 1,
  9271. Ctime: record_time,
  9272. UserOrgId: good_yc.OrgId,
  9273. Manufacturer: stockInInfo.Manufacturer,
  9274. Dealer: stockInInfo.Dealer,
  9275. LicenseNumber: stockInInfo.LicenseNumber,
  9276. IsEdit: 2,
  9277. Creator: creater,
  9278. SystemTime: record_time,
  9279. ConsumableType: 3,
  9280. WarehousingDetailId: 0,
  9281. IsSys: 1,
  9282. UpdateCreator: creater,
  9283. PatientId: patient_id,
  9284. StorehouseId: houseConfig.StorehouseOutInfo,
  9285. OverCount: sum_count,
  9286. ProjectId: good_yc.ProjectId,
  9287. }
  9288. err := service.CreateStockFlowOne(stockFlow)
  9289. fmt.Println("err", err)
  9290. } else if errcod == nil {
  9291. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9292. }
  9293. //创建退库单
  9294. operation_time := time.Now().Unix()
  9295. //创建退库单
  9296. timeStr := time.Now().Format("2006-01-02")
  9297. timeArr := strings.Split(timeStr, "-")
  9298. total, _ := service.FindAllCancelStockTotal(orgID)
  9299. total = total + 1
  9300. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9301. cancelStock := models.CancelStock{
  9302. OrderNumber: orderNumber,
  9303. OperaTime: operation_time,
  9304. OrgId: orgID,
  9305. Creater: warehouseOut.Creater,
  9306. Ctime: time.Now().Unix(),
  9307. Status: 1,
  9308. ReturnTime: record_time,
  9309. Type: 1,
  9310. StorehouseId: stockInInfo.StorehouseId,
  9311. IsCheck: 1,
  9312. }
  9313. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9314. if msgerrkonde == gorm.ErrRecordNotFound {
  9315. service.AddSigleCancelStock(&cancelStock)
  9316. }
  9317. cancel, _ := service.GetLastCancelStockById(orgID)
  9318. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9319. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9320. cancelStockInfo := models.CancelStockInfo{
  9321. GoodId: stockInInfo.GoodId,
  9322. CancelStockId: cancel.ID,
  9323. GoodTypeId: stockInInfo.GoodTypeId,
  9324. Count: delete_count,
  9325. Price: stockInInfo.PackingPrice,
  9326. Total: 0,
  9327. ProductDate: stockInInfo.ProductDate,
  9328. ExpiryDate: stockInInfo.ExpiryDate,
  9329. Ctime: record_time,
  9330. Status: 1,
  9331. OrgId: orgID,
  9332. OrderNumber: cancel.OrderNumber,
  9333. Type: 0,
  9334. Dealer: deaerler.DealerName,
  9335. Manufacturer: manufacturer.ManufacturerName,
  9336. Number: stockInInfo.Number,
  9337. RegisterAccount: "",
  9338. Remark: "",
  9339. WarehouseInfoId: stockInInfo.ID,
  9340. PatientId: patient_id,
  9341. RecordDate: record_time,
  9342. StorehouseId: stockInInfo.StorehouseId,
  9343. IsCheck: 1,
  9344. }
  9345. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9346. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9347. flow := models.VmStockFlow{
  9348. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9349. GoodId: good_yc.GoodId,
  9350. Number: warehouseOutInfos.Number,
  9351. LicenseNumber: stockInInfo.LicenseNumber,
  9352. Count: delete_count,
  9353. UserOrgId: orgID,
  9354. PatientId: patient_id,
  9355. SystemTime: record_time,
  9356. ConsumableType: 7,
  9357. IsSys: 0,
  9358. WarehousingOrder: "",
  9359. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9360. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9361. IsEdit: 0,
  9362. CancelStockId: cancel.ID,
  9363. CancelOrderNumber: cancel.OrderNumber,
  9364. Manufacturer: manufacturer.ID,
  9365. Dealer: 0,
  9366. Creator: warehouseOut.Creater,
  9367. UpdateCreator: 0,
  9368. Status: 1,
  9369. Ctime: record_time,
  9370. Mtime: 0,
  9371. Price: stockInInfo.Price,
  9372. WarehousingDetailId: stockInInfo.ID,
  9373. WarehouseOutDetailId: warehouseOutInfos.ID,
  9374. CancelOutDetailId: cancelInfo.ID,
  9375. ProductDate: stockInInfo.ProductDate,
  9376. ExpireDate: stockInInfo.ExpiryDate,
  9377. StorehouseId: houseConfig.StorehouseOutInfo,
  9378. OverCount: sum_count,
  9379. }
  9380. service.CreateStockFlowOne(flow)
  9381. //更改自动出库的表格
  9382. details := models.BloodAutomaticReduceDetail{
  9383. WarehouseOutId: warehouseOutInfo.ID,
  9384. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9385. PatientId: patient_id,
  9386. Ctime: time.Now().Unix(),
  9387. Mtime: time.Now().Unix(),
  9388. Status: 1,
  9389. RecordTime: record_time,
  9390. OrgId: orgID,
  9391. GoodId: good_yc.GoodId,
  9392. GoodTypeId: good_yc.GoodTypeId,
  9393. Count: count,
  9394. StorehouseId: houseConfig.StorehouseOutInfo,
  9395. }
  9396. //查询当天耗材是否已经存在数据
  9397. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9398. if errcode == gorm.ErrRecordNotFound {
  9399. errTwo := service.CreateAutoReduceRecord(&details)
  9400. if errTwo != nil {
  9401. return errTwo
  9402. }
  9403. } else if errcode == nil {
  9404. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9405. service.CreateAutoReduceRecord(&details)
  9406. }
  9407. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9408. //增加出库库存数量
  9409. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9410. if good_yc.Count == 0 {
  9411. return nil
  9412. } else {
  9413. return errors.New("退库和出库数据不匹配")
  9414. }
  9415. }
  9416. func (this *DialysisAPIController) SavePatientSign() {
  9417. adminUserInfo := this.GetMobileAdminUserInfo()
  9418. patient_id, _ := this.GetInt64("patient_id")
  9419. dialysis_date, _ := this.GetInt64("dialysis_date")
  9420. orgid := adminUserInfo.Org.Id
  9421. var esdata models.DialysisOrder
  9422. var err error
  9423. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9425. return
  9426. }
  9427. esdata.Hash = esdata.Hash
  9428. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9429. order := models.DialysisOrder{
  9430. Hash: esdata.Hash,
  9431. Url: esdata.Url,
  9432. }
  9433. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9434. redis := service.RedisClient()
  9435. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9436. redis.Set(key, "", time.Second)
  9437. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9438. //清空key 值
  9439. redis.Set(keyOne, "", time.Second)
  9440. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9441. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9442. //redis.Set(keyTwo, "", time.Second)
  9443. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9444. redis.Set(keyThree, "", time.Second)
  9445. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9446. redis.Set(keyFour, "", time.Second)
  9447. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9448. redis.Set(keyFive, "", time.Second)
  9449. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9450. redis.Set(keySix, "", time.Second)
  9451. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9452. redis.Set(keySeven, "", time.Second)
  9453. if err != nil {
  9454. fmt.Println(err)
  9455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9456. return
  9457. }
  9458. this.ServeSuccessJSON(map[string]interface{}{
  9459. "electronic_signature": esdata,
  9460. })
  9461. }
  9462. func (this *DialysisAPIController) GetPatientSign() {
  9463. patient_id, _ := this.GetInt64("patient_id")
  9464. dialysis_date, _ := this.GetInt64("dialysis_date")
  9465. adminUserInfo := this.GetMobileAdminUserInfo()
  9466. orgId := adminUserInfo.Org.Id
  9467. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9468. if err != nil {
  9469. fmt.Println(err)
  9470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9471. return
  9472. }
  9473. this.ServeSuccessJSON(map[string]interface{}{
  9474. "dialysisOrder": dialysisOrder,
  9475. })
  9476. }
  9477. func (this *DialysisAPIController) GetScheduleByPatient() {
  9478. patient_id, _ := this.GetInt64("patient_id")
  9479. schedule_date, _ := this.GetInt64("schedule_date")
  9480. orgid := this.GetMobileAdminUserInfo().Org.Id
  9481. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9482. this.ServeSuccessJSON(map[string]interface{}{
  9483. "schedule": schedule,
  9484. })
  9485. }
  9486. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9487. org_id := this.GetMobileAdminUserInfo().Org.Id
  9488. patient_id, _ := this.GetInt64("patient_id")
  9489. schedule_date, _ := this.GetInt64("schedule_date")
  9490. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9491. this.ServeSuccessJSON(map[string]interface{}{
  9492. "order": order,
  9493. })
  9494. }
  9495. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9496. org_id := this.GetMobileAdminUserInfo().Org.Id
  9497. schedule_date := this.GetString("schedule_date")
  9498. schedule_type, _ := this.GetInt64("schedule_type")
  9499. timeLayout := "2006-01-02"
  9500. loc, _ := time.LoadLocation("Local")
  9501. var startdateunix int64
  9502. if len(schedule_date) > 0 {
  9503. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9504. if err != nil {
  9505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9506. return
  9507. }
  9508. startdateunix = theTime.Unix()
  9509. }
  9510. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9511. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9512. devices, _ := service.GetAllDevicetByListSix(org_id)
  9513. for key, item := range scheduals {
  9514. // 床位信息
  9515. for _, device := range devices {
  9516. if item.BedId == device.ID {
  9517. scheduals[key].DeviceNumber = device
  9518. break
  9519. }
  9520. }
  9521. }
  9522. this.ServeSuccessJSON(map[string]interface{}{
  9523. "list": list,
  9524. "scheduals": scheduals,
  9525. })
  9526. }
  9527. func (this *DialysisAPIController) SavePatientPicture() {
  9528. patient_id, _ := this.GetInt64("patient_id")
  9529. dialysis_date, _ := this.GetInt64("schedule_date")
  9530. avatar := this.GetString("avatar")
  9531. fmt.Println("patient_id", patient_id)
  9532. orgId := this.GetMobileAdminUserInfo().Org.Id
  9533. order := models.DialysisOrder{
  9534. Url: avatar,
  9535. }
  9536. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9537. redis := service.RedisClient()
  9538. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9539. redis.Set(key, "", time.Second)
  9540. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9541. //清空key 值
  9542. redis.Set(keyOne, "", time.Second)
  9543. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9544. redis.Set(keyThree, "", time.Second)
  9545. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9546. redis.Set(keyFour, "", time.Second)
  9547. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9548. redis.Set(keyFive, "", time.Second)
  9549. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9550. redis.Set(keySix, "", time.Second)
  9551. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9552. redis.Set(keySeven, "", time.Second)
  9553. if err != nil {
  9554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9555. return
  9556. }
  9557. this.ServeSuccessJSON(map[string]interface{}{
  9558. "order": order,
  9559. })
  9560. }
  9561. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9562. ids := this.GetString("ids")
  9563. idSplit := strings.Split(ids, ",")
  9564. orgId := this.GetMobileAdminUserInfo().Org.Id
  9565. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9566. execution_time := this.GetString("exce_time")
  9567. timeLayout2 := "2006-01-02 15:04:05"
  9568. loc, _ := time.LoadLocation("Local")
  9569. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9570. if errs != nil {
  9571. utils.ErrorLog(errs.Error())
  9572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9573. return
  9574. }
  9575. //his客户
  9576. if config.IsOpen == 1 {
  9577. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9578. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9579. for _, item := range list {
  9580. for _, it := range adviceList {
  9581. if item.DrugId == it.DrugId {
  9582. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9583. }
  9584. }
  9585. }
  9586. for _, item := range list {
  9587. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9588. var sum_out_count int64
  9589. for _, itemThree := range item.ChildDoctorAdvice {
  9590. var prescribing_number int64
  9591. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9592. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9593. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9594. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9595. }
  9596. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9597. prescribing_number = parseIntPrescribingNumber
  9598. }
  9599. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9600. prescribing_number = parseIntPrescribingNumber
  9601. }
  9602. sum_out_count += prescribing_number
  9603. }
  9604. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9605. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9606. //库存不足
  9607. if sum_out_count > drugStockOut.FlushCount {
  9608. this.ServeSuccessJSON(map[string]interface{}{
  9609. "msg": "2",
  9610. "drug": medical,
  9611. "ids": ids,
  9612. })
  9613. return
  9614. }
  9615. }
  9616. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9617. //执行医嘱
  9618. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9619. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9620. for _, item := range advices {
  9621. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9622. redis := service.RedisClient()
  9623. //清空key 值
  9624. redis.Set(key, "", time.Second)
  9625. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9626. redis.Set(keyTwo, "", time.Second)
  9627. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9628. redis.Set(keyThree, "", time.Second)
  9629. recordDate := theTime.Format("2006-01-02")
  9630. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9631. redis.Set(keyFour, "", time.Second)
  9632. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9633. redis.Set(keyFive, "", time.Second)
  9634. defer redis.Close()
  9635. }
  9636. if errs == nil {
  9637. //药品管理信息
  9638. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9639. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9640. if drugStockConfig.IsOpen == 1 {
  9641. for _, item := range advices {
  9642. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9643. config, _ := service.GetDrugOpenConfigOne(orgId)
  9644. if config.IsOpen != 1 {
  9645. //查询该药品是否有库存
  9646. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9647. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9648. if medical.IsUse == 2 {
  9649. if config.IsOpen != 1 {
  9650. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9651. service.HisDrugsDelivery(orgId, creater, &advice)
  9652. if orgId == 3877 || orgId == 10265 {
  9653. //查询该药品是否有出库记录
  9654. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9655. if len(flowMap) == 0 {
  9656. errs := service.UpdateHisAdviceById(advice.ID)
  9657. if errs != nil {
  9658. drugError := models.XtDrugError{
  9659. UserOrgId: orgId,
  9660. DrugId: item.DrugId,
  9661. RecordDate: item.AdviceDate,
  9662. PatientId: item.PatientId,
  9663. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9664. Status: 1,
  9665. Ctime: time.Now().Unix(),
  9666. Mtime: 0,
  9667. SumCount: 0,
  9668. Prescribingnumber: advice.PrescribingNumber,
  9669. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9670. }
  9671. service.CreateDrugError(drugError)
  9672. }
  9673. this.ServeSuccessJSON(map[string]interface{}{
  9674. "msg": "2",
  9675. "drug": medical,
  9676. "ids": ids,
  9677. })
  9678. return
  9679. }
  9680. }
  9681. }
  9682. if pharmacyConfig.IsOpen != 1 {
  9683. service.HisDrugsDelivery(orgId, creater, &advice)
  9684. if orgId == 3877 || orgId == 10265 {
  9685. //查询该药品是否有出库记录
  9686. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9687. if len(flowMap) == 0 {
  9688. errs := service.UpdateHisAdviceById(advice.ID)
  9689. if errs != nil {
  9690. drugError := models.XtDrugError{
  9691. UserOrgId: orgId,
  9692. DrugId: item.DrugId,
  9693. RecordDate: item.AdviceDate,
  9694. PatientId: item.PatientId,
  9695. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9696. Status: 1,
  9697. Ctime: time.Now().Unix(),
  9698. Mtime: 0,
  9699. SumCount: 0,
  9700. Prescribingnumber: advice.PrescribingNumber,
  9701. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9702. }
  9703. service.CreateDrugError(drugError)
  9704. }
  9705. this.ServeSuccessJSON(map[string]interface{}{
  9706. "msg": "2",
  9707. "drug": medical,
  9708. "ids": ids,
  9709. })
  9710. return
  9711. }
  9712. }
  9713. }
  9714. //更新字典里面的库存
  9715. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9716. var sum_count int64
  9717. for _, its := range stockInfo {
  9718. if its.MaxUnit == medical.MaxUnit {
  9719. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9720. }
  9721. sum_count += its.StockMaxNumber + its.StockMinNumber
  9722. }
  9723. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9724. //剩余库存
  9725. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9726. }
  9727. }
  9728. }
  9729. }
  9730. }
  9731. this.ServeSuccessJSON(map[string]interface{}{
  9732. "msg": "1",
  9733. "ids": ids,
  9734. })
  9735. return
  9736. } else {
  9737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9738. }
  9739. }
  9740. //血透客户
  9741. if config.IsOpen == 2 || config.IsOpen == 0 {
  9742. //药品管理信息
  9743. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9744. if drugStockConfig.IsOpen == 1 {
  9745. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9746. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9747. for _, item := range list {
  9748. for _, it := range adviceList {
  9749. if item.DrugId == it.DrugId {
  9750. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9751. }
  9752. }
  9753. }
  9754. for _, item := range list {
  9755. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9756. var sum_out_count int64
  9757. for _, itemThree := range item.ChildDoctorAdvice {
  9758. var prescribing_number int64
  9759. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9760. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9761. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9762. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9763. }
  9764. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9765. prescribing_number = parseIntPrescribingNumber
  9766. }
  9767. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9768. prescribing_number = parseIntPrescribingNumber
  9769. }
  9770. sum_out_count += prescribing_number
  9771. }
  9772. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9773. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9774. //库存不足
  9775. if sum_out_count > drugStockOut.FlushCount {
  9776. this.ServeSuccessJSON(map[string]interface{}{
  9777. "msg": "2",
  9778. "drug": medical,
  9779. "ids": ids,
  9780. })
  9781. return
  9782. }
  9783. }
  9784. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9785. //执行医嘱
  9786. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9787. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9788. for _, item := range advices {
  9789. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9790. redis := service.RedisClient()
  9791. //清空key 值
  9792. redis.Set(key, "", time.Second)
  9793. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9794. redis.Set(keyTwo, "", time.Second)
  9795. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9796. redis.Set(keyThree, "", time.Second)
  9797. recordDate := theTime.Format("2006-01-02")
  9798. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9799. redis.Set(keyFour, "", time.Second)
  9800. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9801. redis.Set(keyFive, "", time.Second)
  9802. defer redis.Close()
  9803. }
  9804. if errs == nil {
  9805. for _, item := range advices {
  9806. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9807. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9808. //查询是否出库按钮开启
  9809. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9810. if adviceSetting.IsAdviceOpen == 1 {
  9811. //查询是否出库按钮开启
  9812. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9813. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9814. if prescriptionConfig.IsOpen == 1 {
  9815. if medical.IsUse == 2 {
  9816. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9817. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9818. }
  9819. if pharmacyConfig.IsOpen != 1 {
  9820. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9821. }
  9822. //更新字典里面的库存
  9823. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9824. var sum_count int64
  9825. for _, its := range stockInfo {
  9826. if its.MaxUnit == medical.MaxUnit {
  9827. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9828. }
  9829. sum_count += its.StockMaxNumber + its.StockMinNumber
  9830. }
  9831. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9832. //剩余库存
  9833. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9834. }
  9835. }
  9836. } else {
  9837. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9838. if medical.IsUse == 2 {
  9839. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9840. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9841. }
  9842. if pharmacyConfig.IsOpen != 1 {
  9843. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9844. }
  9845. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9846. var sum_count int64
  9847. for _, its := range stockInfo {
  9848. if its.MaxUnit == medical.MaxUnit {
  9849. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9850. }
  9851. sum_count += its.StockMaxNumber + its.StockMinNumber
  9852. }
  9853. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9854. //剩余库存
  9855. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9856. }
  9857. }
  9858. }
  9859. }
  9860. this.ServeSuccessJSON(map[string]interface{}{
  9861. "msg": "1",
  9862. "ids": ids,
  9863. })
  9864. return
  9865. } else {
  9866. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9867. //执行医嘱
  9868. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9869. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9870. for _, item := range advices {
  9871. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9872. redis := service.RedisClient()
  9873. //清空key 值
  9874. redis.Set(key, "", time.Second)
  9875. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9876. redis.Set(keyTwo, "", time.Second)
  9877. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9878. redis.Set(keyThree, "", time.Second)
  9879. recordDate := theTime.Format("2006-01-02")
  9880. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9881. redis.Set(keyFour, "", time.Second)
  9882. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9883. redis.Set(keyFive, "", time.Second)
  9884. defer redis.Close()
  9885. }
  9886. this.ServeSuccessJSON(map[string]interface{}{
  9887. "msg": "1",
  9888. "ids": ids,
  9889. })
  9890. return
  9891. }
  9892. }
  9893. }
  9894. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9895. ids := this.GetString("ids")
  9896. idSplit := strings.Split(ids, ",")
  9897. orgId := this.GetMobileAdminUserInfo().Org.Id
  9898. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9899. if config.IsOpen == 1 {
  9900. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9901. this.ServeSuccessJSON(map[string]interface{}{
  9902. "msg": "1",
  9903. "ids": ids,
  9904. })
  9905. return
  9906. }
  9907. if config.IsOpen == 0 || config.IsOpen == 2 {
  9908. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9909. this.ServeSuccessJSON(map[string]interface{}{
  9910. "msg": "1",
  9911. "ids": ids,
  9912. })
  9913. return
  9914. }
  9915. }
  9916. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9917. ids := this.GetString("ids")
  9918. idSplit := strings.Split(ids, ",")
  9919. orgId := this.GetMobileAdminUserInfo().Org.Id
  9920. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9921. //his
  9922. if config.IsOpen == 1 {
  9923. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9924. theTime := time.Now()
  9925. advices := models.HisDoctorAdviceThirty{
  9926. CheckTime: theTime.Unix(),
  9927. Checker: checker,
  9928. UpdatedTime: time.Now().Unix(),
  9929. }
  9930. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9931. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9932. for _, item := range list {
  9933. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9934. redis := service.RedisClient()
  9935. //清空key 值
  9936. redis.Set(key, "", time.Second)
  9937. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9938. redis.Set(keyTwo, "", time.Second)
  9939. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9940. redis.Set(keyThree, "", time.Second)
  9941. recordDate := theTime.Format("2006-01-02")
  9942. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9943. redis.Set(keyFour, "", time.Second)
  9944. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9945. redis.Set(keyFive, "", time.Second)
  9946. defer redis.Close()
  9947. }
  9948. this.ServeSuccessJSON(map[string]interface{}{
  9949. "msg": "1",
  9950. "ids": ids,
  9951. })
  9952. return
  9953. }
  9954. //血透
  9955. if config.IsOpen == 0 || config.IsOpen == 2 {
  9956. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9957. theTime := time.Now()
  9958. advices := models.DoctorAdvice{
  9959. CheckTime: theTime.Unix(),
  9960. Checker: checker,
  9961. UpdatedTime: time.Now().Unix(),
  9962. }
  9963. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9964. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9965. for _, item := range list {
  9966. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9967. redis := service.RedisClient()
  9968. //清空key 值
  9969. redis.Set(key, "", time.Second)
  9970. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9971. redis.Set(keyTwo, "", time.Second)
  9972. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9973. redis.Set(keyThree, "", time.Second)
  9974. recordDate := theTime.Format("2006-01-02")
  9975. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9976. redis.Set(keyFour, "", time.Second)
  9977. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9978. redis.Set(keyFive, "", time.Second)
  9979. defer redis.Close()
  9980. }
  9981. this.ServeSuccessJSON(map[string]interface{}{
  9982. "msg": "1",
  9983. "ids": ids,
  9984. })
  9985. return
  9986. }
  9987. }
  9988. func (this *DialysisAPIController) CheckSchedule() {
  9989. patientID, _ := this.GetInt64("patient_id")
  9990. recordDateStr := this.GetString("record_date")
  9991. nurseID, _ := this.GetInt64("start_nurse")
  9992. schedual_type, _ := this.GetInt64("schedual_type")
  9993. bedID, _ := this.GetInt64("bed")
  9994. start_time := this.GetString("start_time")
  9995. fmt.Println("patientID", patientID)
  9996. fmt.Println("recordDateStr", recordDateStr)
  9997. fmt.Println("nurseID", nurseID)
  9998. fmt.Println("schedual_type------", schedual_type)
  9999. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  10000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10001. return
  10002. }
  10003. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  10004. if parseStartDateErr != nil {
  10005. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  10006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10007. return
  10008. }
  10009. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10010. if parseErr != nil {
  10011. this.ErrorLog("时间解析失败:%v", parseErr)
  10012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10013. return
  10014. }
  10015. adminUserInfo := this.GetMobileAdminUserInfo()
  10016. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  10017. if getPatientErr != nil {
  10018. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  10019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10020. return
  10021. } else if patient == nil {
  10022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  10023. return
  10024. }
  10025. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  10026. if getNurseErr != nil {
  10027. this.ErrorLog("获取护士失败:%v", getNurseErr)
  10028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10029. return
  10030. } else if nurse == nil {
  10031. this.ErrorLog("护士不存在")
  10032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10033. return
  10034. }
  10035. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  10036. if getDeviceNumberErr != nil {
  10037. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  10038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10039. return
  10040. } else if deviceNumber == nil {
  10041. this.ErrorLog("床位号不存在")
  10042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10043. return
  10044. }
  10045. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  10046. if getRecordErr != nil {
  10047. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  10048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10049. return
  10050. } else if dialysisRecord != nil {
  10051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  10052. return
  10053. }
  10054. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  10055. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  10056. timeLayout := "2006-01-02 15:04:05"
  10057. loc, _ := time.LoadLocation("Local")
  10058. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  10059. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  10060. schedulestartTime := theStartTime.Unix()
  10061. scheduleendTime := theEndTime.Unix()
  10062. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  10063. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  10064. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10065. //查询该床位是否有人用了
  10066. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10067. if err == nil {
  10068. if schedule.ID == 0 {
  10069. this.ServeSuccessJSON(map[string]interface{}{
  10070. "status": 0,
  10071. "msg": "请求失败",
  10072. })
  10073. } else {
  10074. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  10075. if order.ID > 0 { //该机位被其他人占用了
  10076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  10077. return
  10078. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  10079. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  10080. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  10081. this.ServeSuccessJSON(map[string]interface{}{
  10082. "status": 1,
  10083. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  10084. })
  10085. return
  10086. } else {
  10087. this.ServeSuccessJSON(map[string]interface{}{
  10088. "status": 0,
  10089. "msg": "",
  10090. })
  10091. }
  10092. }
  10093. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  10094. this.ServeSuccessJSON(map[string]interface{}{
  10095. "status": 2,
  10096. "msg": "当前机位已有患者在使用,请重新选择!",
  10097. })
  10098. }
  10099. }
  10100. } else {
  10101. this.ServeSuccessJSON(map[string]interface{}{
  10102. "status": 0,
  10103. "msg": "",
  10104. })
  10105. }
  10106. }
  10107. func (this *DialysisAPIController) GetNewDoctorListToday() {
  10108. orgId := this.GetMobileAdminUserInfo().Org.Id
  10109. schedule_type, _ := this.GetInt64("schedule_type")
  10110. partion_type, _ := this.GetInt64("partion_type")
  10111. start_time := this.GetString("start_time")
  10112. timeLayout := "2006-01-02"
  10113. loc, _ := time.LoadLocation("Local")
  10114. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10115. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  10116. _, config := service.FindXTHisRecordByOrgId(orgId)
  10117. appId := this.GetMobileAdminUserInfo().App.Id
  10118. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  10119. if err == nil {
  10120. this.ServeSuccessJSON(map[string]interface{}{
  10121. "list": list,
  10122. "config": config,
  10123. "doctorList": doctorList,
  10124. })
  10125. return
  10126. } else {
  10127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10128. return
  10129. }
  10130. }
  10131. func (this *DialysisAPIController) SaveMobileInformation() {
  10132. patient_id, _ := this.GetInt64("patient_id")
  10133. record_date, _ := this.GetInt64("record_date")
  10134. startTime := this.GetString("start_time")
  10135. module, _ := this.GetInt64("module")
  10136. remark := this.GetString("remark")
  10137. timeLayout := "2006-01-02 15:04"
  10138. loc, _ := time.LoadLocation("Local")
  10139. if len(startTime) == 0 {
  10140. utils.ErrorLog("len(start_time) == 0")
  10141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10142. return
  10143. }
  10144. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  10145. if err != nil {
  10146. utils.ErrorLog(err.Error())
  10147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10148. return
  10149. }
  10150. StartTime := theTime.Unix()
  10151. fmt.Println("startime-------------", StartTime)
  10152. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  10153. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  10154. information := models.XtDialysisInformation{
  10155. Module: module,
  10156. PatientId: patient_id,
  10157. RecordDate: record_date,
  10158. ApplicationDate: StartTime,
  10159. Creater: creater,
  10160. ApplicationStatus: 2,
  10161. Checker: 0,
  10162. CheckTime: 0,
  10163. Remark: remark,
  10164. UserOrgId: user_org_id,
  10165. Ctime: time.Now().Unix(),
  10166. Status: 1,
  10167. Mtime: 0,
  10168. }
  10169. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10170. if infor.ID == 0 {
  10171. service.SaveDialysisInformation(information)
  10172. }
  10173. if infor.ID > 0 {
  10174. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10175. }
  10176. this.ServeSuccessJSON(map[string]interface{}{
  10177. "information": information,
  10178. })
  10179. return
  10180. }
  10181. func (this *DialysisAPIController) GetMobileInformation() {
  10182. limit, _ := this.GetInt64("limit")
  10183. page, _ := this.GetInt64("page")
  10184. orgid := this.GetMobileAdminUserInfo().Org.Id
  10185. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10186. appid := this.GetMobileAdminUserInfo().App.Id
  10187. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10188. patients, _ := service.GetAllpatientThirty(orgid)
  10189. this.ServeSuccessJSON(map[string]interface{}{
  10190. "information": information,
  10191. "total": total,
  10192. "doclist": doclist,
  10193. "patients": patients,
  10194. })
  10195. return
  10196. }
  10197. func (this *DialysisAPIController) GetMobileInformationOne() {
  10198. limit, _ := this.GetInt64("limit")
  10199. page, _ := this.GetInt64("page")
  10200. orgid := this.GetMobileAdminUserInfo().Org.Id
  10201. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10202. appid := this.GetMobileAdminUserInfo().App.Id
  10203. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10204. patients, _ := service.GetAllpatientThirty(orgid)
  10205. this.ServeSuccessJSON(map[string]interface{}{
  10206. "information": information,
  10207. "total": total,
  10208. "doclist": doclist,
  10209. "patients": patients,
  10210. })
  10211. return
  10212. }
  10213. func (this *DialysisAPIController) CheckMobileInformation() {
  10214. id, _ := this.GetInt64("id")
  10215. application_status, _ := this.GetInt64("application_status")
  10216. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10217. checktime := time.Now().Unix()
  10218. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10219. if err == nil {
  10220. this.ServeSuccessJSON(map[string]interface{}{
  10221. "msg": "ok",
  10222. })
  10223. return
  10224. }
  10225. }
  10226. func (c *DialysisAPIController) GetControlMonitorList() {
  10227. partition, _ := c.GetInt64("partition")
  10228. monitorDate := c.GetString("date")
  10229. patient_id, _ := c.GetInt64("patient_id")
  10230. pat_type, _ := c.GetInt64("pat_type")
  10231. timeLayout := "2006-01-02"
  10232. loc, _ := time.LoadLocation("Local")
  10233. var theStartTime int64
  10234. if len(monitorDate) > 0 {
  10235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10236. if err != nil {
  10237. theStartTime = 0
  10238. }
  10239. theStartTime = theTime.Unix()
  10240. }
  10241. adminInfo := c.GetMobileAdminUserInfo()
  10242. orgID := adminInfo.Org.Id
  10243. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10244. if err != nil {
  10245. c.ErrorLog("获取排班信息失败:%v", err)
  10246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10247. } else {
  10248. if len(monitor) > 0 {
  10249. //获取所有床位
  10250. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10251. //获取所有分区
  10252. zoneList, _ := service.GetAllZoneByList(orgID)
  10253. //获取透析处方
  10254. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10255. //获取透前评估
  10256. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10257. //获取上机
  10258. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10259. //获取透后
  10260. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10261. //获取透后监测
  10262. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10263. //获取所有的患者
  10264. patients, _ := service.GetAllPatientListByListOne(orgID)
  10265. //获取所有透析模式
  10266. treatments, _ := service.GetAllTreatModeByList(orgID)
  10267. //获取所有医嘱
  10268. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10269. //获取双人核对
  10270. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10271. //治疗小结
  10272. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10273. //待消毒
  10274. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10275. for key, item := range monitor {
  10276. // 获取床位信息
  10277. for _, it := range numberList {
  10278. if item.BedId == it.ID {
  10279. monitor[key].DeviceNumber = it
  10280. break
  10281. }
  10282. }
  10283. //获取分区信息
  10284. for _, it := range zoneList {
  10285. if item.PartitionId == it.ID {
  10286. monitor[key].DeviceZone = it
  10287. }
  10288. }
  10289. for _, prescription := range prescriptions {
  10290. if item.PatientId == prescription.PatientId {
  10291. monitor[key].Prescription = prescription
  10292. break
  10293. }
  10294. }
  10295. for _, it := range checkList {
  10296. if item.PatientId == it.PatientId {
  10297. monitor[key].DoubleCheck = it
  10298. break
  10299. }
  10300. }
  10301. for _, it := range summaryList {
  10302. if item.PatientId == it.PatientId {
  10303. monitor[key].TreatmentSummaryForList = it
  10304. break
  10305. }
  10306. }
  10307. // 透前评估
  10308. for _, assessmentBefore := range assessmentBefores {
  10309. if item.PatientId == assessmentBefore.PatientId {
  10310. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10311. break
  10312. }
  10313. }
  10314. // 透析上下机
  10315. for _, dialysisOrder := range dialysisOrders {
  10316. if item.PatientId == dialysisOrder.PatientId {
  10317. monitor[key].DialysisOrder = dialysisOrder
  10318. break
  10319. }
  10320. }
  10321. // 治疗小节
  10322. for _, afterDislysis := range AssessmentAfterDislysis {
  10323. if item.PatientId == afterDislysis.PatientId {
  10324. monitor[key].AssessmentAfterDislysis = afterDislysis
  10325. break
  10326. }
  10327. }
  10328. for _, it := range monitorlist {
  10329. if item.PatientId == it.PatientId {
  10330. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10331. }
  10332. }
  10333. for _, it := range adviceList {
  10334. if item.PatientId == it.PatientId {
  10335. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10336. }
  10337. }
  10338. for _, patient := range patients {
  10339. if item.PatientId == patient.ID {
  10340. monitor[key].MonitorPatients = patient
  10341. break
  10342. }
  10343. }
  10344. for _, treatment := range treatments {
  10345. if item.ModeId == treatment.ID {
  10346. monitor[key].TreatmentMode = treatment
  10347. break
  10348. }
  10349. }
  10350. for _, infor := range informationList {
  10351. if item.PatientId == infor.PatientId {
  10352. monitor[key].NewDeviceInformation = infor
  10353. break
  10354. }
  10355. }
  10356. }
  10357. }
  10358. }
  10359. patients, err := service.GetAllpatientFourty(orgID)
  10360. var mds []*models.NewMonitorDialysisScheduleList
  10361. if pat_type == 0 {
  10362. for _, item := range monitor {
  10363. mds = append(mds, item)
  10364. }
  10365. }
  10366. //待医嘱核对
  10367. if pat_type == 1 {
  10368. for _, item := range monitor {
  10369. if len(item.AdviceList) > 0 {
  10370. mds = append(mds, item)
  10371. }
  10372. }
  10373. }
  10374. //待开小结
  10375. if pat_type == 2 {
  10376. for _, item := range monitor {
  10377. if item.TreatmentSummaryForList == nil {
  10378. mds = append(mds, item)
  10379. }
  10380. }
  10381. }
  10382. //待下机
  10383. if pat_type == 3 {
  10384. for _, item := range monitor {
  10385. if item.DialysisOrder != nil {
  10386. if item.DialysisOrder.ID > 0 {
  10387. mds = append(mds, item)
  10388. }
  10389. }
  10390. }
  10391. }
  10392. //待消毒
  10393. if pat_type == 4 {
  10394. for _, item := range monitor {
  10395. if item.NewDeviceInformation == nil {
  10396. mds = append(mds, item)
  10397. }
  10398. }
  10399. }
  10400. //待双人核对
  10401. if pat_type == 5 {
  10402. for _, item := range monitor {
  10403. if item.DoubleCheck == nil {
  10404. mds = append(mds, item)
  10405. }
  10406. }
  10407. }
  10408. //医嘱未执行
  10409. if pat_type == 6 {
  10410. for _, item := range monitor {
  10411. if len(item.AdviceList) > 0 {
  10412. mds = append(mds, item)
  10413. }
  10414. }
  10415. }
  10416. //患者未签名
  10417. if pat_type == 7 {
  10418. for _, item := range monitor {
  10419. if item.DialysisOrder != nil {
  10420. if item.DialysisOrder.ID > 0 {
  10421. mds = append(mds, item)
  10422. }
  10423. }
  10424. }
  10425. }
  10426. //目标超滤于实际超滤不同
  10427. if pat_type == 8 {
  10428. for _, item := range monitor {
  10429. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10430. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10431. mds = append(mds, item)
  10432. }
  10433. }
  10434. }
  10435. }
  10436. //血压少于5次
  10437. if pat_type == 9 {
  10438. for _, item := range monitor {
  10439. if len(item.MonitoringRecord) < 5 {
  10440. mds = append(mds, item)
  10441. }
  10442. }
  10443. }
  10444. if pat_type == 13 {
  10445. for _, item := range monitor {
  10446. if len(item.MonitoringRecord) < 3 {
  10447. mds = append(mds, item)
  10448. }
  10449. }
  10450. }
  10451. if pat_type == 10 {
  10452. for _, item := range monitor {
  10453. if len(item.MonitoringRecord) == 0 {
  10454. mds = append(mds, item)
  10455. }
  10456. }
  10457. }
  10458. if pat_type == 11 {
  10459. for _, item := range monitor {
  10460. if len(item.MonitoringRecord) > 0 {
  10461. mds = append(mds, item)
  10462. }
  10463. }
  10464. }
  10465. if pat_type == 12 {
  10466. for _, item := range monitor {
  10467. if len(item.MonitoringRecord) > 0 {
  10468. mds = append(mds, item)
  10469. }
  10470. }
  10471. }
  10472. if err == nil {
  10473. c.ServeSuccessJSON(map[string]interface{}{
  10474. "monitor": mds,
  10475. "patients": patients,
  10476. })
  10477. } else {
  10478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10479. }
  10480. }
  10481. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10482. admin_user_id, _ := c.GetInt64("admin_user_id")
  10483. timeStr := time.Now().Format("2006-01-02")
  10484. timeLayout := "2006-01-02 15:04:05"
  10485. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10486. timenow := timeStringToTime.Unix()
  10487. orgId := c.GetMobileAdminUserInfo().Org.Id
  10488. //查询当前护士的患者
  10489. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10490. var patientIds []int64
  10491. for _, item := range orderList {
  10492. patientIds = append(patientIds, item.PatientId)
  10493. }
  10494. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10495. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10496. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10497. //药品管理信息
  10498. _, drugStockConfig := service.FindHisConfig(orgId)
  10499. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10500. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10501. c.ServeSuccessJSON(map[string]interface{}{
  10502. "adviceList": adviceList,
  10503. "hisAdviceList": hisAdviceList,
  10504. "projectList": projectList,
  10505. "drugStockConfig": drugStockConfig,
  10506. "patientList": patientList,
  10507. "projectConfig": projectConfig,
  10508. })
  10509. }
  10510. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10511. patient_id, _ := c.GetInt64("patient_id")
  10512. org_id := c.GetMobileAdminUserInfo().Org.Id
  10513. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10514. c.ServeSuccessJSON(map[string]interface{}{
  10515. "recrods": recrods,
  10516. })
  10517. }
  10518. func (c *DialysisAPIController) ExMobileChangeSch() {
  10519. id_one, _ := c.GetInt64("id_one")
  10520. id_two, _ := c.GetInt64("id_two")
  10521. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10522. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10523. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10524. //if order2.ID > 0 {
  10525. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10526. // return
  10527. //}
  10528. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10529. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10530. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10531. if count > 0 {
  10532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10533. return
  10534. }
  10535. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10536. if count1 > 0 {
  10537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10538. return
  10539. }
  10540. }
  10541. err := service.UpdateScheduleThree(sch, sch_two)
  10542. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10543. if order.ID > 0 {
  10544. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10545. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10546. redis := service.RedisClient()
  10547. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10548. redis.Set(key, "", time.Second)
  10549. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10550. //清空key 值
  10551. redis.Set(keyOne, "", time.Second)
  10552. }
  10553. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10554. if orderOne.ID > 0 {
  10555. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10556. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10557. redis := service.RedisClient()
  10558. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10559. redis.Set(key, "", time.Second)
  10560. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10561. //清空key 值
  10562. redis.Set(keyOne, "", time.Second)
  10563. }
  10564. if err == nil {
  10565. //去除当天患者排班中重复数据,保留最后一条数据
  10566. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10567. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10568. c.ServeSuccessJSON(map[string]interface{}{
  10569. "msg": "交换成功",
  10570. })
  10571. } else {
  10572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10573. return
  10574. }
  10575. }
  10576. func (c *DialysisAPIController) MobileCoverSch() {
  10577. id_one, _ := c.GetInt64("id_one")
  10578. id_two, _ := c.GetInt64("id_two")
  10579. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10580. //针对凤凰医院
  10581. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10582. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10583. if len(advice) > 0 {
  10584. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10585. }
  10586. }
  10587. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10588. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10589. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10590. if len(hisAdvice) > 0 {
  10591. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10592. }
  10593. if len(project) > 0 {
  10594. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10595. }
  10596. }
  10597. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10598. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10599. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10600. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10601. if count > 0 {
  10602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10603. return
  10604. }
  10605. }
  10606. var new_sch models.Schedule
  10607. new_sch = sch
  10608. new_sch.BedId = sch_two.BedId
  10609. new_sch.ScheduleDate = sch_two.ScheduleDate
  10610. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10611. new_sch.PartitionId = sch_two.PartitionId
  10612. new_sch.ScheduleType = sch_two.ScheduleType
  10613. new_sch.ID = 0
  10614. //删除原来的排班
  10615. err := service.SaveSchTwo(sch, sch_two)
  10616. //生成新的排班
  10617. if err == nil {
  10618. err2 := service.SaveSch(&new_sch)
  10619. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10620. if order.ID > 0 {
  10621. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10622. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10623. redis := service.RedisClient()
  10624. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10625. redis.Set(key, "", time.Second)
  10626. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10627. //清空key 值
  10628. redis.Set(keyOne, "", time.Second)
  10629. }
  10630. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10631. if orderOne.ID > 0 {
  10632. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10633. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10634. redis := service.RedisClient()
  10635. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10636. redis.Set(key, "", time.Second)
  10637. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10638. //清空key 值
  10639. redis.Set(keyOne, "", time.Second)
  10640. }
  10641. if err2 == nil {
  10642. //去除当天患者排班中重复数据,保留最后一条数据
  10643. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10644. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10645. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10646. c.ServeSuccessJSON(map[string]interface{}{
  10647. "msg": "覆盖成功",
  10648. "new_sch": new_sch,
  10649. })
  10650. } else {
  10651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10652. return
  10653. }
  10654. } else {
  10655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10656. return
  10657. }
  10658. }
  10659. func (c *DialysisAPIController) BatchCheckAdvice() {
  10660. patient_id, _ := c.GetInt64("patient_id")
  10661. advice_date, _ := c.GetInt64("advice_date")
  10662. org_id := c.GetMobileAdminUserInfo().Org.Id
  10663. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10664. //查询是his系统还是血透系统
  10665. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10666. //his客户
  10667. if configs.IsOpen == 1 {
  10668. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10669. for _, item := range adviceList {
  10670. service.BatchCheckHisAdvice(item.ID, creater)
  10671. }
  10672. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10673. for _, item := range projectList {
  10674. service.BatchCheckProject(item.ID, creater)
  10675. }
  10676. c.ServeSuccessJSON(map[string]interface{}{
  10677. "adviceList": adviceList,
  10678. "projectList": projectList,
  10679. })
  10680. }
  10681. if configs.IsOpen != 1 {
  10682. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10683. for _, item := range adviceList {
  10684. service.BatchAdviceList(item.ID, creater)
  10685. }
  10686. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10687. for _, item := range projectList {
  10688. service.BatchCheckProject(item.ID, creater)
  10689. }
  10690. c.ServeSuccessJSON(map[string]interface{}{
  10691. "adviceList": adviceList,
  10692. "projectList": projectList,
  10693. })
  10694. }
  10695. return
  10696. }
  10697. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10698. org_id := c.GetMobileAdminUserInfo().Org.Id
  10699. drugList, _ := service.GetAllDrugList(org_id)
  10700. c.ServeSuccessJSON(map[string]interface{}{
  10701. "drugList": drugList,
  10702. })
  10703. }
  10704. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10705. org_id := c.GetMobileAdminUserInfo().Org.Id
  10706. dataBody := make(map[string]interface{}, 0)
  10707. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10708. if err != nil {
  10709. utils.ErrorLog(err.Error())
  10710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10711. return
  10712. }
  10713. timeLayout := "2006-01-02"
  10714. loc, _ := time.LoadLocation("Local")
  10715. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10716. utils.ErrorLog("advice_type")
  10717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10718. return
  10719. }
  10720. adviceType := int64(dataBody["advice_type"].(float64))
  10721. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10722. utils.ErrorLog("start_time")
  10723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10724. return
  10725. }
  10726. startTime2, _ := dataBody["start_time"].(string)
  10727. time_arr := strings.Split(startTime2, " ")
  10728. if len(time_arr) > 0 {
  10729. startTime2 = time_arr[0]
  10730. }
  10731. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10732. utils.ErrorLog("advice_date")
  10733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10734. return
  10735. }
  10736. advice_date, _ := dataBody["advice_date"].(string)
  10737. var advicedateunix int64
  10738. if len(advice_date) > 0 {
  10739. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10740. if err != nil {
  10741. fmt.Println(err)
  10742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10743. return
  10744. }
  10745. advicedateunix = theTime.Unix()
  10746. }
  10747. adviceDate := startTime2
  10748. if len(adviceDate) == 0 {
  10749. utils.ErrorLog("len(adviceDate) == 0")
  10750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10751. return
  10752. }
  10753. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10754. if err != nil {
  10755. utils.ErrorLog(err.Error())
  10756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10757. return
  10758. }
  10759. AdviceDate := advicedateunix
  10760. RecordDate := advicedateunix
  10761. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10762. utils.ErrorLog("start_time")
  10763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10764. return
  10765. }
  10766. startTime, _ := dataBody["start_time"].(string)
  10767. if len(startTime) == 0 {
  10768. utils.ErrorLog("len(start_time) == 0")
  10769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10770. return
  10771. }
  10772. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10773. if err != nil {
  10774. utils.ErrorLog(err.Error())
  10775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10776. return
  10777. }
  10778. StartTime := theTime.Unix()
  10779. advice_name, _ := dataBody["advice_name"].(string)
  10780. advice_desc, _ := dataBody["advice_desc"].(string)
  10781. delivery_way, _ := dataBody["delivery_way"].(string)
  10782. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10783. frequency_type := int64(dataBody["frequency_type"].(float64))
  10784. frequency_week, _ := dataBody["frequency_week"].(string)
  10785. prescribing_number := dataBody["prescribing_number"].(float64)
  10786. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10787. remark := dataBody["remark"].(string)
  10788. single_dose := dataBody["single_dose"].(float64)
  10789. single_dose_unit := dataBody["single_dose_unit"].(string)
  10790. patient_id := int64(dataBody["patient_id"].(float64))
  10791. day_count := int64(dataBody["day_count"].(float64))
  10792. groupNo := int64(dataBody["group_no"].(float64))
  10793. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10794. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10795. if groupNo <= 0 {
  10796. group := service.GetMaxAdviceGroupID(org_id)
  10797. groupNo = group + 1
  10798. }
  10799. var template_id = ""
  10800. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10801. template_id = "M" + adviceLastId
  10802. advice := models.DoctorAdvice{
  10803. UserOrgId: org_id,
  10804. PatientId: patient_id,
  10805. AdviceType: adviceType,
  10806. AdviceDate: AdviceDate,
  10807. StartTime: StartTime,
  10808. AdviceName: advice_name,
  10809. AdviceDesc: advice_desc,
  10810. ReminderDate: 0,
  10811. SingleDose: single_dose,
  10812. SingleDoseUnit: single_dose_unit,
  10813. DrugSpec: 0,
  10814. DrugSpecUnit: "",
  10815. PrescribingNumber: prescribing_number,
  10816. PrescribingNumberUnit: prescribing_number_unit,
  10817. DeliveryWay: delivery_way,
  10818. ExecutionFrequency: execution_frequency,
  10819. AdviceDoctor: advice_doctor,
  10820. Status: 1,
  10821. CreatedTime: time.Now().Unix(),
  10822. UpdatedTime: 0,
  10823. AdviceAffirm: "",
  10824. Remark: remark,
  10825. StopTime: 0,
  10826. StopReason: "",
  10827. StopDoctor: 0,
  10828. StopState: 2,
  10829. ParentId: 0,
  10830. ExecutionTime: 0,
  10831. ExecutionStaff: 0,
  10832. ExecutionState: 0,
  10833. Checker: 0,
  10834. RecordDate: RecordDate,
  10835. DialysisOrderId: 0,
  10836. CheckTime: 0,
  10837. CheckState: 0,
  10838. AdviceId: 0,
  10839. RemindType: 0,
  10840. FrequencyType: frequency_type,
  10841. DayCount: day_count,
  10842. WeekDay: frequency_week,
  10843. ChildDoctorAdvice: nil,
  10844. TemplateId: template_id,
  10845. Modifier: 0,
  10846. IsCheck: 0,
  10847. Way: 0,
  10848. DrugId: 0,
  10849. DrugNameId: 0,
  10850. IsMedicine: 0,
  10851. PushStartTime: 0,
  10852. IsSettle: 0,
  10853. IsPrescription: 0,
  10854. GroupNo: groupNo,
  10855. }
  10856. service.CreateMobileAdivce(advice)
  10857. c.ServeSuccessJSON(map[string]interface{}{
  10858. "msg": "保存成功!",
  10859. })
  10860. }
  10861. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10862. patient_id, _ := c.GetInt64("patient_id")
  10863. org_id := c.GetMobileAdminUserInfo().Org.Id
  10864. app_id := c.GetMobileAdminUserInfo().App.Id
  10865. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10866. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10867. c.ServeSuccessJSON(map[string]interface{}{
  10868. "adviceList": adviceList,
  10869. "adminRoles": adminRoles,
  10870. })
  10871. }
  10872. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10873. org_id := c.GetMobileAdminUserInfo().Org.Id
  10874. dataBody := make(map[string]interface{}, 0)
  10875. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10876. if err != nil {
  10877. utils.ErrorLog(err.Error())
  10878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10879. return
  10880. }
  10881. timeLayout := "2006-01-02"
  10882. loc, _ := time.LoadLocation("Local")
  10883. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10884. utils.ErrorLog("start_time")
  10885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10886. return
  10887. }
  10888. startTime2, _ := dataBody["start_time"].(string)
  10889. time_arr := strings.Split(startTime2, " ")
  10890. if len(time_arr) > 0 {
  10891. startTime2 = time_arr[0]
  10892. }
  10893. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10894. utils.ErrorLog("advice_date")
  10895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10896. return
  10897. }
  10898. advice_date, _ := dataBody["advice_date"].(string)
  10899. var advicedateunix int64
  10900. if len(advice_date) > 0 {
  10901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10902. if err != nil {
  10903. fmt.Println(err)
  10904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10905. return
  10906. }
  10907. advicedateunix = theTime.Unix()
  10908. }
  10909. adviceDate := startTime2
  10910. if len(adviceDate) == 0 {
  10911. utils.ErrorLog("len(adviceDate) == 0")
  10912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10913. return
  10914. }
  10915. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10916. if err != nil {
  10917. utils.ErrorLog(err.Error())
  10918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10919. return
  10920. }
  10921. AdviceDate := advicedateunix
  10922. RecordDate := advicedateunix
  10923. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10924. utils.ErrorLog("start_time")
  10925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10926. return
  10927. }
  10928. startTime, _ := dataBody["start_time"].(string)
  10929. if len(startTime) == 0 {
  10930. utils.ErrorLog("len(start_time) == 0")
  10931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10932. return
  10933. }
  10934. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10935. if err != nil {
  10936. utils.ErrorLog(err.Error())
  10937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10938. return
  10939. }
  10940. StartTime := theTime.Unix()
  10941. advice_name, _ := dataBody["advice_name"].(string)
  10942. advice_desc, _ := dataBody["advice_desc"].(string)
  10943. delivery_way, _ := dataBody["delivery_way"].(string)
  10944. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10945. prescribing_number := dataBody["prescribing_number"].(float64)
  10946. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10947. remark := dataBody["remark"].(string)
  10948. single_dose := dataBody["single_dose"].(float64)
  10949. single_dose_unit := dataBody["single_dose_unit"].(string)
  10950. patient_id := int64(dataBody["patient_id"].(float64))
  10951. groupNo := int64(dataBody["group_no"].(float64))
  10952. parent_id := int64(dataBody["parent_id"].(float64))
  10953. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10954. advice := models.XtDoctorAdviceOne{
  10955. UserOrgId: org_id,
  10956. PatientId: patient_id,
  10957. AdviceType: 1,
  10958. AdviceDate: AdviceDate,
  10959. StartTime: StartTime,
  10960. AdviceName: advice_name,
  10961. AdviceDesc: advice_desc,
  10962. ReminderDate: 0,
  10963. SingleDose: single_dose,
  10964. SingleDoseUnit: single_dose_unit,
  10965. PrescribingNumber: prescribing_number,
  10966. PrescribingNumberUnit: prescribing_number_unit,
  10967. DeliveryWay: delivery_way,
  10968. ExecutionFrequency: execution_frequency,
  10969. AdviceDoctor: advice_doctor,
  10970. Status: 1,
  10971. CreatedTime: time.Now().Unix(),
  10972. UpdatedTime: time.Now().Unix(),
  10973. AdviceAffirm: "",
  10974. Remark: remark,
  10975. StopTime: 0,
  10976. StopReason: "",
  10977. StopDoctor: 0,
  10978. StopState: 2,
  10979. ParentId: parent_id,
  10980. ExecutionTime: 0,
  10981. ExecutionStaff: 0,
  10982. ExecutionState: 0,
  10983. Checker: 0,
  10984. RecordDate: RecordDate,
  10985. DialysisOrderId: 0,
  10986. CheckTime: 0,
  10987. CheckState: 0,
  10988. DrugSpec: 0,
  10989. DrugSpecUnit: "",
  10990. Groupno: groupNo,
  10991. RemindType: 0,
  10992. FrequencyType: 0,
  10993. DayCount: 0,
  10994. WeekDay: "",
  10995. TemplateId: "",
  10996. Modifier: 0,
  10997. }
  10998. service.CreateMobileAdivceOne(advice)
  10999. c.ServeSuccessJSON(map[string]interface{}{
  11000. "msg": "保存成功!",
  11001. })
  11002. }
  11003. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  11004. id, _ := c.GetInt64("id")
  11005. service.DeleteSelfAdviceSubAdvice(id)
  11006. c.ServeSuccessJSON(map[string]interface{}{
  11007. "msg": "保存成功!",
  11008. })
  11009. }
  11010. func (c *DialysisAPIController) GetEditAdviceAction() {
  11011. id, _ := c.GetInt64("id")
  11012. org_id := c.GetMobileAdminUserInfo().Org.Id
  11013. advice, _ := service.GetEditAdviceActionList(id, org_id)
  11014. drugList, _ := service.GetAllDrugList(org_id)
  11015. c.ServeSuccessJSON(map[string]interface{}{
  11016. "advice": advice,
  11017. "drugList": drugList,
  11018. })
  11019. }
  11020. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  11021. dataBody := make(map[string]interface{}, 0)
  11022. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11023. if err != nil {
  11024. utils.ErrorLog(err.Error())
  11025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11026. return
  11027. }
  11028. timeLayout := "2006-01-02"
  11029. loc, _ := time.LoadLocation("Local")
  11030. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11031. utils.ErrorLog("start_time")
  11032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11033. return
  11034. }
  11035. startTime2, _ := dataBody["start_time"].(string)
  11036. time_arr := strings.Split(startTime2, " ")
  11037. if len(time_arr) > 0 {
  11038. startTime2 = time_arr[0]
  11039. }
  11040. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11041. utils.ErrorLog("advice_date")
  11042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11043. return
  11044. }
  11045. advice_date, _ := dataBody["advice_date"].(string)
  11046. var advicedateunix int64
  11047. if len(advice_date) > 0 {
  11048. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11049. if err != nil {
  11050. fmt.Println(err)
  11051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11052. return
  11053. }
  11054. advicedateunix = theTime.Unix()
  11055. }
  11056. adviceDate := startTime2
  11057. if len(adviceDate) == 0 {
  11058. utils.ErrorLog("len(adviceDate) == 0")
  11059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11060. return
  11061. }
  11062. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11063. if err != nil {
  11064. utils.ErrorLog(err.Error())
  11065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11066. return
  11067. }
  11068. AdviceDate := advicedateunix
  11069. RecordDate := advicedateunix
  11070. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11071. utils.ErrorLog("start_time")
  11072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11073. return
  11074. }
  11075. startTime, _ := dataBody["start_time"].(string)
  11076. if len(startTime) == 0 {
  11077. utils.ErrorLog("len(start_time) == 0")
  11078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11079. return
  11080. }
  11081. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11082. if err != nil {
  11083. utils.ErrorLog(err.Error())
  11084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11085. return
  11086. }
  11087. StartTime := theTime.Unix()
  11088. advice_name, _ := dataBody["advice_name"].(string)
  11089. advice_desc, _ := dataBody["advice_desc"].(string)
  11090. delivery_way, _ := dataBody["delivery_way"].(string)
  11091. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11092. prescribing_number := dataBody["prescribing_number"].(float64)
  11093. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11094. remark := dataBody["remark"].(string)
  11095. single_dose := dataBody["single_dose"].(float64)
  11096. single_dose_unit := dataBody["single_dose_unit"].(string)
  11097. id := int64(dataBody["id"].(float64))
  11098. frequency_type := int64(dataBody["frequency_type"].(float64))
  11099. frequency_week, _ := dataBody["frequency_week"].(string)
  11100. day_count := int64(dataBody["day_count"].(float64))
  11101. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11102. advice := models.XtDoctorAdviceOne{
  11103. AdviceDate: AdviceDate,
  11104. StartTime: StartTime,
  11105. AdviceName: advice_name,
  11106. AdviceDesc: advice_desc,
  11107. SingleDose: single_dose,
  11108. SingleDoseUnit: single_dose_unit,
  11109. PrescribingNumber: prescribing_number,
  11110. PrescribingNumberUnit: prescribing_number_unit,
  11111. DeliveryWay: delivery_way,
  11112. ExecutionFrequency: execution_frequency,
  11113. AdviceDoctor: advice_doctor,
  11114. Remark: remark,
  11115. RecordDate: RecordDate,
  11116. FrequencyType: frequency_type,
  11117. DayCount: day_count,
  11118. WeekDay: frequency_week,
  11119. }
  11120. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  11121. c.ServeSuccessJSON(map[string]interface{}{
  11122. "advice": advice,
  11123. })
  11124. }
  11125. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  11126. dataBody := make(map[string]interface{}, 0)
  11127. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11128. if err != nil {
  11129. utils.ErrorLog(err.Error())
  11130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11131. return
  11132. }
  11133. timeLayout := "2006-01-02"
  11134. loc, _ := time.LoadLocation("Local")
  11135. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11136. utils.ErrorLog("start_time")
  11137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11138. return
  11139. }
  11140. startTime2, _ := dataBody["start_time"].(string)
  11141. time_arr := strings.Split(startTime2, " ")
  11142. if len(time_arr) > 0 {
  11143. startTime2 = time_arr[0]
  11144. }
  11145. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11146. utils.ErrorLog("advice_date")
  11147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11148. return
  11149. }
  11150. advice_date, _ := dataBody["advice_date"].(string)
  11151. var advicedateunix int64
  11152. if len(advice_date) > 0 {
  11153. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11154. if err != nil {
  11155. fmt.Println(err)
  11156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11157. return
  11158. }
  11159. advicedateunix = theTime.Unix()
  11160. }
  11161. adviceDate := startTime2
  11162. if len(adviceDate) == 0 {
  11163. utils.ErrorLog("len(adviceDate) == 0")
  11164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11165. return
  11166. }
  11167. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11168. if err != nil {
  11169. utils.ErrorLog(err.Error())
  11170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11171. return
  11172. }
  11173. AdviceDate := advicedateunix
  11174. RecordDate := advicedateunix
  11175. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11176. utils.ErrorLog("start_time")
  11177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11178. return
  11179. }
  11180. startTime, _ := dataBody["start_time"].(string)
  11181. if len(startTime) == 0 {
  11182. utils.ErrorLog("len(start_time) == 0")
  11183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11184. return
  11185. }
  11186. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11187. if err != nil {
  11188. utils.ErrorLog(err.Error())
  11189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11190. return
  11191. }
  11192. StartTime := theTime.Unix()
  11193. advice_name, _ := dataBody["advice_name"].(string)
  11194. advice_desc, _ := dataBody["advice_desc"].(string)
  11195. delivery_way, _ := dataBody["delivery_way"].(string)
  11196. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11197. prescribing_number := dataBody["prescribing_number"].(float64)
  11198. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11199. remark := dataBody["remark"].(string)
  11200. single_dose := dataBody["single_dose"].(float64)
  11201. single_dose_unit := dataBody["single_dose_unit"].(string)
  11202. id := int64(dataBody["id"].(float64))
  11203. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11204. advice := models.XtDoctorAdviceOne{
  11205. AdviceDate: AdviceDate,
  11206. StartTime: StartTime,
  11207. AdviceName: advice_name,
  11208. AdviceDesc: advice_desc,
  11209. SingleDose: single_dose,
  11210. SingleDoseUnit: single_dose_unit,
  11211. PrescribingNumber: prescribing_number,
  11212. PrescribingNumberUnit: prescribing_number_unit,
  11213. DeliveryWay: delivery_way,
  11214. ExecutionFrequency: execution_frequency,
  11215. AdviceDoctor: advice_doctor,
  11216. Remark: remark,
  11217. RecordDate: RecordDate,
  11218. }
  11219. service.UpdateMobileDoctorAdviceById(id, advice)
  11220. c.ServeSuccessJSON(map[string]interface{}{
  11221. "advice": advice,
  11222. })
  11223. }
  11224. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11225. dataBody := make(map[string]interface{}, 0)
  11226. timeLayout := "2006-01-02"
  11227. loc, _ := time.LoadLocation("Local")
  11228. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11229. if err != nil {
  11230. utils.ErrorLog(err.Error())
  11231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11232. return
  11233. }
  11234. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11235. utils.ErrorLog("start_time")
  11236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11237. return
  11238. }
  11239. startTime2, _ := dataBody["start_time"].(string)
  11240. time_arr := strings.Split(startTime2, " ")
  11241. if len(time_arr) > 0 {
  11242. startTime2 = time_arr[0]
  11243. }
  11244. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11245. utils.ErrorLog("advice_date")
  11246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11247. return
  11248. }
  11249. advice_date, _ := dataBody["advice_date"].(string)
  11250. var advicedateunix int64
  11251. if len(advice_date) > 0 {
  11252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11253. if err != nil {
  11254. fmt.Println(err)
  11255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11256. return
  11257. }
  11258. advicedateunix = theTime.Unix()
  11259. }
  11260. adviceDate := startTime2
  11261. if len(adviceDate) == 0 {
  11262. utils.ErrorLog("len(adviceDate) == 0")
  11263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11264. return
  11265. }
  11266. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11267. if err != nil {
  11268. utils.ErrorLog(err.Error())
  11269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11270. return
  11271. }
  11272. RecordDate := advicedateunix
  11273. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11274. utils.ErrorLog("start_time")
  11275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11276. return
  11277. }
  11278. startTime, _ := dataBody["start_time"].(string)
  11279. if len(startTime) == 0 {
  11280. utils.ErrorLog("len(start_time) == 0")
  11281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11282. return
  11283. }
  11284. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11285. if err != nil {
  11286. utils.ErrorLog(err.Error())
  11287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11288. return
  11289. }
  11290. StartTime := theTime.Unix()
  11291. patient_id := int64(dataBody["patient_id"].(float64))
  11292. group_no := int64(dataBody["group_no"].(float64))
  11293. org_id := c.GetMobileAdminUserInfo().Org.Id
  11294. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11295. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11296. utils.ErrorLog("advices")
  11297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11298. return
  11299. }
  11300. adviceNames := dataBody["advices"].([]interface{})
  11301. var advices []*models.GroupAdvice
  11302. for _, adviceNameMap := range adviceNames {
  11303. var advice models.GroupAdvice
  11304. adviceNameM := adviceNameMap.(map[string]interface{})
  11305. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11306. utils.ErrorLog("advice_name")
  11307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11308. return
  11309. }
  11310. adviceName, _ := adviceNameM["advice_name"].(string)
  11311. if len(adviceName) == 0 {
  11312. utils.ErrorLog("len(advice_name) == 0")
  11313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11314. return
  11315. }
  11316. advice.AdviceName = adviceName
  11317. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11318. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11319. advice.DrugSpec = drugSpec
  11320. }
  11321. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11322. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11323. advice.AdviceDesc = adviceDesc
  11324. }
  11325. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11326. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11327. advice.DrugSpecUnit = drugSpecUnit
  11328. }
  11329. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11330. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11331. advice.SingleDose = singleDose
  11332. }
  11333. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11334. singleDose := adviceNameM["single_dose"].(float64)
  11335. advice.SingleDose = singleDose
  11336. }
  11337. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11338. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11339. advice.SingleDoseUnit = singleDoseUnit
  11340. }
  11341. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11342. tmp := adviceNameM["single_dose_unit"].(float64)
  11343. singleDoseUnit := service.TypeConversion(tmp)
  11344. advice.SingleDoseUnit = singleDoseUnit
  11345. }
  11346. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11347. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11348. advice.PrescribingNumber = prescribingNumber
  11349. }
  11350. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11351. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11352. advice.PrescribingNumber = prescribingNumber
  11353. }
  11354. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11355. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11356. advice.PrescribingNumberUnit = prescribingNumberUnit
  11357. }
  11358. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11359. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11360. advice.DeliveryWay = deliveryWay
  11361. }
  11362. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11363. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11364. advice.ExecutionFrequency = executionFrequency
  11365. }
  11366. remark, _ := adviceNameM["remark"].(string)
  11367. advice.Remark = remark
  11368. advice.AdviceType = 1
  11369. advice.StartTime = StartTime
  11370. advice.RecordDate = RecordDate
  11371. advice.PatientId = patient_id
  11372. advice.UserOrgId = org_id
  11373. advice.AdviceDoctor = advice_doctor
  11374. advice.StopState = 2
  11375. advices = append(advices, &advice)
  11376. }
  11377. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11378. c.ServeSuccessJSON(map[string]interface{}{
  11379. "advice": newAdvices,
  11380. })
  11381. }
  11382. func (c *DialysisAPIController) StopLongAdvice() {
  11383. stop_time := c.GetString("execution_time")
  11384. id, _ := c.GetInt64("id")
  11385. if len(stop_time) <= 0 {
  11386. utils.ErrorLog("stop_time")
  11387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11388. return
  11389. }
  11390. timeLayout2 := "2006-01-02 15:04:05"
  11391. loc, _ := time.LoadLocation("Local")
  11392. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11393. if errs != nil {
  11394. utils.ErrorLog(errs.Error())
  11395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11396. return
  11397. }
  11398. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11399. c.ServeSuccessJSON(map[string]interface{}{
  11400. "advice": advice,
  11401. })
  11402. }
  11403. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11404. dataBody := make(map[string]interface{}, 0)
  11405. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11406. if err != nil {
  11407. utils.ErrorLog(err.Error())
  11408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11409. return
  11410. }
  11411. orgId := c.GetMobileAdminUserInfo().Org.Id
  11412. patient_id := int64(dataBody["patient_id"].(float64))
  11413. record_date := int64(dataBody["record_date"].(float64))
  11414. checker := int64(dataBody["checker"].(float64))
  11415. check_time := dataBody["check_time"].(string)
  11416. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11417. if parseStartDateErr != nil {
  11418. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11420. return
  11421. }
  11422. var advice_id []int64
  11423. var his_advice_id []int64
  11424. var project_id []int64
  11425. var team_list []int64
  11426. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11427. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11428. if len(newAdviceList) > 0 {
  11429. for _, item := range newAdviceList {
  11430. items := item.(map[string]interface{})
  11431. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11432. utils.ErrorLog("id")
  11433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11434. return
  11435. }
  11436. id := int64(items["id"].(float64))
  11437. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11438. utils.ErrorLog("origin")
  11439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11440. return
  11441. }
  11442. origin := int64(items["origin"].(float64))
  11443. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11444. utils.ErrorLog("team_id")
  11445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11446. return
  11447. }
  11448. team_id := int64(items["team_id"].(float64))
  11449. if team_id == 0 {
  11450. //临时医嘱
  11451. if origin == 1 {
  11452. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11453. advice_id = append(advice_id, id)
  11454. }
  11455. //his医嘱
  11456. if origin == 2 {
  11457. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11458. his_advice_id = append(his_advice_id, id)
  11459. }
  11460. //his医嘱
  11461. if origin == 3 {
  11462. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11463. project_id = append(project_id, id)
  11464. }
  11465. }
  11466. if team_id > 0 {
  11467. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11468. team_list = append(team_list, team_id)
  11469. }
  11470. }
  11471. }
  11472. }
  11473. advice, _ := service.GetBatchAdviceList(advice_id)
  11474. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11475. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11476. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11477. c.ServeSuccessJSON(map[string]interface{}{
  11478. "advice": advice,
  11479. "hisadvice": hisadvice,
  11480. "hisproject": hisproject,
  11481. "teamlist": teamlist,
  11482. })
  11483. return
  11484. }
  11485. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11486. dataBody := make(map[string]interface{}, 0)
  11487. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11488. if err != nil {
  11489. utils.ErrorLog(err.Error())
  11490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11491. return
  11492. }
  11493. orgId := c.GetMobileAdminUserInfo().Org.Id
  11494. patient_id := int64(dataBody["patient_id"].(float64))
  11495. record_date := int64(dataBody["record_date"].(float64))
  11496. execution_staff := int64(dataBody["execution_staff"].(float64))
  11497. execution_time := dataBody["execution_time"].(string)
  11498. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11499. if parseStartDateErr != nil {
  11500. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11502. return
  11503. }
  11504. var advice_id []int64
  11505. var his_advice_id []int64
  11506. var project_id []int64
  11507. var team_list []int64
  11508. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11509. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11510. if len(newAdviceList) > 0 {
  11511. for _, item := range newAdviceList {
  11512. items := item.(map[string]interface{})
  11513. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11514. utils.ErrorLog("id")
  11515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11516. return
  11517. }
  11518. id := int64(items["id"].(float64))
  11519. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11520. utils.ErrorLog("origin")
  11521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11522. return
  11523. }
  11524. origin := int64(items["origin"].(float64))
  11525. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11526. utils.ErrorLog("team_id")
  11527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11528. return
  11529. }
  11530. team_id := int64(items["team_id"].(float64))
  11531. if team_id == 0 {
  11532. //临时医嘱
  11533. if origin == 1 {
  11534. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11535. advice_id = append(advice_id, id)
  11536. }
  11537. //his医嘱
  11538. if origin == 2 {
  11539. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11540. his_advice_id = append(his_advice_id, id)
  11541. }
  11542. //his医嘱
  11543. if origin == 3 {
  11544. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11545. project_id = append(project_id, id)
  11546. }
  11547. }
  11548. if team_id > 0 {
  11549. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11550. team_list = append(team_list, team_id)
  11551. }
  11552. }
  11553. }
  11554. }
  11555. advice, _ := service.GetBatchAdviceList(advice_id)
  11556. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11557. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11558. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11559. c.ServeSuccessJSON(map[string]interface{}{
  11560. "advice": advice,
  11561. "hisadvice": hisadvice,
  11562. "hisproject": hisproject,
  11563. "teamlist": teamlist,
  11564. })
  11565. return
  11566. }